| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| StaticProbeManager | 
 | 
 | 1.0;1 | 
| 1 |  /* ========================================== | |
| 2 |   * JperfProbe : Java Performance Probes | |
| 3 |   * ========================================== | |
| 4 |   * | |
| 5 |   * Project Info:  http://jperfprobe.sourceforge.net/ | |
| 6 |   * Project Lead:  Tor-Erik Larsen (http://sourceforge.net/users/uptime62) | |
| 7 |   * | |
| 8 |   * (C) Copyright 2005, by Tor-Erik Larsen and Contributors. | |
| 9 |   * | |
| 10 |   * This library is free software; you can redistribute it and/or modify it | |
| 11 |   * under the terms of the GNU Lesser General Public License as published by | |
| 12 |   * the Free Software Foundation; either version 2.1 of the License, or | |
| 13 |   * (at your option) any later version. | |
| 14 |   * | |
| 15 |   * This library is distributed in the hope that it will be useful, but | |
| 16 |   * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | |
| 17 |   * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public | |
| 18 |   * License for more details. | |
| 19 |   * | |
| 20 |   * You should have received a copy of the GNU Lesser General Public License | |
| 21 |   * along with this library; if not, write to the Free Software Foundation, Inc., | |
| 22 |   * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. | |
| 23 |   */ | |
| 24 |  package net.sf.jperfprobe; | |
| 25 | ||
| 26 |  import org.slf4j.Logger; | |
| 27 |  import org.slf4j.LoggerFactory; | |
| 28 | ||
| 29 |  import java.util.Collection; | |
| 30 | ||
| 31 |  /** | |
| 32 |   * The ProbeManager is the probe factory. It makes it possible start start and stop a probe. | |
| 33 |   * The probe can be started in different ways:<br><br> | |
| 34 |   * <p/> | |
| 35 |   * 1. Start and stop from same scope, same thread, via probe name<br> | |
| 36 |   * 2. Start probes multithreaded from same scope, via probe name<br> | |
| 37 |   * 3. Start in one scope and stop in another scope singlethreaded via probe name<br> | |
| 38 |   * 4. Start in one scope and stop in another scope multithreaded via probe instance<br> | |
| 39 |   */ | |
| 40 | ||
| 41 | public final class StaticProbeManager { | |
| 42 | 0 |      final Logger log = LoggerFactory.getLogger(StaticProbeManager.class); | 
| 43 | ||
| 44 | 1 | private static ProbeManager probeManager = new ProbeManagerImpl(); | 
| 45 | ||
| 46 | 0 |      private StaticProbeManager() { | 
| 47 | 0 |      } | 
| 48 | ||
| 49 |      /** | |
| 50 |       * Put a probe into the manager, if the probe exist it will be overwritten. This makes it possible | |
| 51 |       * to create a Probe outside the ProbeManager and insert it later. | |
| 52 |       * | |
| 53 |       * @param probeName | |
| 54 |       * @param probe | |
| 55 |       */ | |
| 56 | public static void put(String probeName, Probe probe) { | |
| 57 | 1 | probeManager.put(probeName, probe); | 
| 58 | 1 | } | 
| 59 | ||
| 60 | ||
| 61 |      /** | |
| 62 |       * Get a result for a given probe | |
| 63 |       * | |
| 64 |       * @param probeName | |
| 65 |       * @return Result | |
| 66 |       */ | |
| 67 | public static Result getResult(String probeName) { | |
| 68 | 7 |          return probeManager.getResult(probeName); | 
| 69 | } | |
| 70 | ||
| 71 |      /** | |
| 72 |       * Get all the results | |
| 73 |       * | |
| 74 |       * @return | |
| 75 |       */ | |
| 76 | public static Collection<Result> getResults() { | |
| 77 | 0 |          return probeManager.getResults(); | 
| 78 | } | |
| 79 | ||
| 80 |      /** | |
| 81 |       * Get instance of a named probe, if it is non existent, a default probe will be created. | |
| 82 |       * And time will be set to null. | |
| 83 |       * | |
| 84 |       * @param probeName identifying name of probe | |
| 85 |       * @return probe, null if it cant look it up | |
| 86 |       */ | |
| 87 | public static Probe getProbeInstance(String probeName) { | |
| 88 | 14 |          return probeManager.getProbeInstance(probeName); | 
| 89 | } | |
| 90 | ||
| 91 |      /** | |
| 92 |       * Start probe, identified by probeName, if the probe does not exist, it will be created. | |
| 93 |       * | |
| 94 |       * @param probeName name of existing or new probe. | |
| 95 |       */ | |
| 96 | public static Probe start(String probeName) { | |
| 97 | 3307 |          return probeManager.start(probeName); | 
| 98 | } | |
| 99 | ||
| 100 | public static Probe startSingle(String probeName) { | |
| 101 | 1001 |          return probeManager.startSingle(probeName); | 
| 102 | } | |
| 103 | ||
| 104 |      /** | |
| 105 |       * Stop timing. If its non existent, no time or sample will be registered. | |
| 106 |       * | |
| 107 |       * @param probeName name of probe to stop | |
| 108 |       */ | |
| 109 | public static void stop(String probeName) { | |
| 110 | 3306 | probeManager.stop(probeName); | 
| 111 | 3306 | } | 
| 112 | ||
| 113 |      /** | |
| 114 |       * Add a sample from a probe. The probe does not need to be managed by ProbeManager | |
| 115 |       * | |
| 116 |       * @param p | |
| 117 |       */ | |
| 118 | public static void addSampleFromProbe(Probe p) { | |
| 119 | 1002 | probeManager.addSampleFromProbe(p); | 
| 120 | 1002 | } | 
| 121 | ||
| 122 |      /** | |
| 123 |       * Clear all probes, all results and probes will be removed. | |
| 124 |       */ | |
| 125 | public static void clear() { | |
| 126 | 17 | probeManager.clear(); | 
| 127 | 17 | } | 
| 128 | ||
| 129 |      /** | |
| 130 |       * Disable all probes. | |
| 131 |       */ | |
| 132 | public static void disableAll() { | |
| 133 | 2 | probeManager.disable(); | 
| 134 | 2 | } | 
| 135 | ||
| 136 |      /** | |
| 137 |       * Enable all probes. | |
| 138 |       */ | |
| 139 | public static void enableAll() { | |
| 140 | 1 | probeManager.enable(); | 
| 141 | 1 | } | 
| 142 | ||
| 143 |      /** | |
| 144 |       * Set the presentation unit for presentation. | |
| 145 |       * | |
| 146 |       * @param p presentation to set | |
| 147 |       */ | |
| 148 | public static void setPresentation(ProbeManagerImpl.Presentation p) { | |
| 149 | 16 | probeManager.setPresentation(p); | 
| 150 | 16 | } | 
| 151 | ||
| 152 | public static int getFirstSamplesToSkip() { | |
| 153 | 0 |          return probeManager.getFirstSamplesToSkip(); | 
| 154 | } | |
| 155 | ||
| 156 |      /** | |
| 157 |       * Set how many samples to skip in the calculation of statistics. If set to ie. 5, the first 5 samples will | |
| 158 |       * not be taken into account when calculating max/min/n#samples and average. | |
| 159 |       * | |
| 160 |       * @param _firstSamplesToSkip | |
| 161 |       */ | |
| 162 | public static void setFirstSamplesToSkip(int _firstSamplesToSkip) { | |
| 163 | 0 |          probeManager.setFirstSamplesToSkip(_firstSamplesToSkip); | 
| 164 | 0 |      } | 
| 165 | ||
| 166 |      /** | |
| 167 |       * Get the current presentation for the manager | |
| 168 |       * | |
| 169 |       * @return presentation | |
| 170 |       */ | |
| 171 | public static ProbeManagerImpl.Presentation getPresentation() { | |
| 172 | 0 |          return probeManager.getPresentation(); | 
| 173 | } | |
| 174 | ||
| 175 |      /** | |
| 176 |       * Set the Time implementation. | |
| 177 |       * | |
| 178 |       * @param tim | |
| 179 |       */ | |
| 180 | public static void setTime(Time tim) { | |
| 181 | 3 | probeManager.setTime(tim); | 
| 182 | 3 | } | 
| 183 | ||
| 184 |      /** | |
| 185 |       * Get result as a string | |
| 186 |       * | |
| 187 |       * @param probe | |
| 188 |       * @return result | |
| 189 |       */ | |
| 190 | public static String toString(String probe) { | |
| 191 | 4 |          return probeManager.toString(probe); | 
| 192 | } | |
| 193 | ||
| 194 |      /** | |
| 195 |       * Get all samples from a probe, as a string newline delimited | |
| 196 |       * | |
| 197 |       * @param probe | |
| 198 |       * @return samples | |
| 199 |       */ | |
| 200 | public static long[] getSamples(String probe) { | |
| 201 | 0 |          return probeManager.getSamples(probe); | 
| 202 | } | |
| 203 | ||
| 204 |      /** | |
| 205 |       * Get all probe names in the ProbeManager | |
| 206 |       * | |
| 207 |       * @return probename | |
| 208 |       */ | |
| 209 | public static String[] getNames() { | |
| 210 | 1 |          return probeManager.getNames(); | 
| 211 | } | |
| 212 | } |