View Javadoc
1 package com.atlassian.util.profiling; 2 3 import java.util.*; 4 import javax.servlet.http.*; 5 6 /*** 7 * Bean to contain information about the pages profiled 8 * 9 * @author <a href="mailto:mike@atlassian.com">Mike Cannon-Brookes</a> 10 * @author <a href="mailto:scott@atlassian.com">Scott Farquhar</a> 11 */ 12 public class ProfilingTimerBean implements java.io.Serializable 13 { 14 List children = new ArrayList(); 15 ProfilingTimerBean parent = null; 16 17 String resource; 18 19 long startTime; 20 long totalTime; 21 22 public ProfilingTimerBean(String resource) 23 { 24 this.resource = resource; 25 } 26 27 protected void addParent(ProfilingTimerBean parent) 28 { 29 this.parent = parent; 30 } 31 32 public ProfilingTimerBean getParent() 33 { 34 return parent; 35 } 36 37 38 public void addChild(ProfilingTimerBean child) 39 { 40 children.add(child); 41 child.addParent(this); 42 } 43 44 45 public void setStartTime() 46 { 47 this.startTime = System.currentTimeMillis(); 48 } 49 50 public void setEndTime() 51 { 52 this.totalTime = System.currentTimeMillis() - startTime; 53 } 54 55 public String getResource() 56 { 57 return resource; 58 } 59 60 /*** 61 * Get a formatted string representing all the methods that took longer than a specified time. 62 */ 63 64 public String getPrintable(long minTime) 65 { 66 return getPrintable("", minTime); 67 } 68 69 protected String getPrintable(String indent, long minTime) 70 { 71 //only print the value if we are larger or equal to the min time. 72 if (totalTime >= minTime) 73 { 74 StringBuffer buffer = new StringBuffer(); 75 buffer.append(indent); 76 buffer.append("[" + totalTime + "ms] - " + resource); 77 buffer.append("\n"); 78 79 Iterator childrenIt = children.iterator(); 80 while (childrenIt.hasNext()) 81 { 82 buffer.append(((ProfilingTimerBean) childrenIt.next()).getPrintable(indent + " ", minTime)); 83 } 84 85 return buffer.toString(); 86 } 87 else 88 return ""; 89 } 90 } 91

This page was automatically generated by Maven