Esempio n. 1
0
 /**
  * 开始一个profiler任务
  *
  * @param name 任务名称
  * @param threshold 超过此数值的将被记录
  * @return
  */
 public static TimeProfiler start(String name, int threshold) {
   // if (local.get() != null) {
   // throw new IllegalStateException(
   // "Can't start TimeProfiler: it's already running");
   // }
   TimeProfiler profiler = new TimeProfiler(name, threshold);
   local.set(profiler);
   profiler.begin = System.currentTimeMillis();
   return profiler;
 }
Esempio n. 2
0
 /**
  * 增加一个跟踪信息,比如一个sql 注意:目前,顶级任务无法trace
  *
  * @param string
  */
 public static void addTrace(String string) {
   if (string == null) {
     return;
   }
   TimeProfiler profiler = local.get();
   if (profiler == null) {
     return;
   }
   profiler.taskJoin(profiler.new TraceTask(string));
 }
Esempio n. 3
0
 /**
  * 开始一个子任务,如果没有启动profile,则此方法将启动profile运行
  *
  * @param string 子任务名称
  */
 public static void beginTask(String string) {
   TimeProfiler profiler = local.get();
   boolean iFireIt = false;
   if (profiler == null) {
     profiler = start(string);
     iFireIt = true;
   }
   ProfilerTask task = profiler.new ProfilerTask(string);
   task.fire = iFireIt;
   profiler.addTask(task);
   task.start();
 }
Esempio n. 4
0
 /** 结束当前子任务 */
 public static void endTask() {
   TimeProfiler profiler = local.get();
   if (profiler == null) {
     throw new IllegalStateException("Can't end ProfilerTask: TimeProfiler is not running");
   }
   if (profiler.currentTask == null) {
     throw new IllegalStateException("Can't end ProfilerTask: currentTask is null");
   }
   ProfilerTask current = profiler.currentTask;
   current.end();
   boolean iFireIt = current.fire;
   profiler.currentTask = profiler.currentTask.getParentTask();
   if (iFireIt) {
     profiler.release();
   }
 }