001package io.ebean.config;
002
003/**
004 * Configuration for transaction profiling.
005 */
006public class ProfilingConfig {
007
008  /**
009   * When true transaction profiling is enabled.
010   */
011  private boolean enabled;
012
013  /**
014   * Set true for verbose mode.
015   */
016  private boolean verbose;
017
018  /**
019   * The minimum transaction execution time to be included in profiling.
020   */
021  private long minimumMicros;
022
023  /**
024   * A specific set of profileIds to include in profiling.
025   */
026  private int[] includeProfileIds = {};
027
028  /**
029   * The number of profiles to write per file.
030   */
031  private long profilesPerFile = 1000;
032
033  private String directory = "profiling";
034
035  /**
036   * Return true if transaction profiling is enabled.
037   */
038  public boolean isEnabled() {
039    return enabled;
040  }
041
042  /**
043   * Set to true to enable transaction profiling.
044   */
045  public void setEnabled(boolean enabled) {
046    this.enabled = enabled;
047  }
048
049  /**
050   * Return true if verbose mode is used.
051   */
052  public boolean isVerbose() {
053    return verbose;
054  }
055
056  /**
057   * Set to true to use verbose mode.
058   */
059  public void setVerbose(boolean verbose) {
060    this.verbose = verbose;
061  }
062
063  /**
064   * Return the minimum transaction execution to be included in profiling.
065   */
066  public long getMinimumMicros() {
067    return minimumMicros;
068  }
069
070  /**
071   * Set the minimum transaction execution to be included in profiling.
072   */
073  public void setMinimumMicros(long minimumMicros) {
074    this.minimumMicros = minimumMicros;
075  }
076
077  /**
078   * Return the specific set of profileIds to include in profiling.
079   * When not set all transactions with profileIds are included.
080   */
081  public int[] getIncludeProfileIds() {
082    return includeProfileIds;
083  }
084
085  /**
086   * Set a specific set of profileIds to include in profiling.
087   * When not set all transactions with profileIds are included.
088   */
089  public void setIncludeProfileIds(int[] includeProfileIds) {
090    this.includeProfileIds = includeProfileIds;
091  }
092
093  /**
094   * Return the number of profiles to write to a single file.
095   */
096  public long getProfilesPerFile() {
097    return profilesPerFile;
098  }
099
100  /**
101   * Set the number of profiles to write to a single file.
102   */
103  public void setProfilesPerFile(long profilesPerFile) {
104    this.profilesPerFile = profilesPerFile;
105  }
106
107  /**
108   * Return the directory profiling files are put into.
109   */
110  public String getDirectory() {
111    return directory;
112  }
113
114  /**
115   * Set the directory profiling files are put into.
116   */
117  public void setDirectory(String directory) {
118    this.directory = directory;
119  }
120
121  /**
122   * Load setting from properties.
123   */
124  public void loadSettings(PropertiesWrapper p, String name) {
125
126    enabled = p.getBoolean("profiling", enabled);
127    verbose = p.getBoolean("profiling.verbose", verbose);
128
129    directory = p.get("profiling.directory", directory);
130    profilesPerFile = p.getLong("profiling.profilesPerFile", profilesPerFile);
131    minimumMicros = p.getLong("profiling.minimumMicros", minimumMicros);
132
133    String includeIds = p.get("profiling.includeProfileIds");
134    if (includeIds != null) {
135      includeProfileIds = parseIds(includeIds);
136    }
137  }
138
139  private int[] parseIds(String includeIds) {
140
141    String[] ids = includeIds.split(",");
142    int[] vals = new int[ids.length];
143    for (int i = 0; i < ids.length; i++) {
144      vals[i] = Integer.parseInt(ids[i]);
145    }
146    return vals;
147  }
148}