Esempio n. 1
0
 private String prettyPrint() {
   StringBuffer sb = new StringBuffer(shortSummary());
   for (ProfilerTask task : this.tasks) {
     sb.append(NewLine).append(task.prettyPrint(this.begin));
   }
   return sb.toString();
 }
Esempio n. 2
0
 public void addChildTask(ProfilerTask task) {
   if (children == null) {
     children = new ArrayList<ProfilerTask>();
   }
   children.add(task);
   task.parent = this;
   task.deep = this.deep + 1;
 }
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
 @Override
 public StringBuffer prettyPrint(long profileStart) {
   StringBuffer sb = new StringBuffer();
   sb.append("Trace:").append(this.name);
   if (this.children != null) {
     for (ProfilerTask child : this.children) {
       sb.append(NewLine);
       for (int i = 0; i < this.deep; i++) {
         sb.append("--");
       }
       sb.append(child.prettyPrint(profileStart));
     }
   }
   return sb;
 }
Esempio n. 5
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();
   }
 }
Esempio n. 6
0
 public StringBuffer prettyPrint(long profileStart) {
   StringBuffer sb = new StringBuffer();
   sb.append("Task:").append(this.name);
   sb.append(" running time(millis)");
   sb.append('[')
       .append(this.start - profileStart)
       .append("->")
       .append(this.end - profileStart)
       .append(']');
   sb.append('=').append(getTotalTimeMillis());
   double rate = (double) this.getTotalTimeMillis() / TimeProfiler.this.getTotalTimeMillis();
   rate = rate * 100;
   sb.append(" ").append((int) rate).append('%');
   if (this.children != null) {
     for (ProfilerTask child : this.children) {
       sb.append(NewLine);
       for (int i = 0; i < this.deep; i++) {
         sb.append("--");
       }
       sb.append(child.prettyPrint(profileStart));
     }
   }
   return sb;
 }