1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package net.sf.jour.statistic;
22
23 import net.sf.jour.rt.agent.ProfilerEvent;
24
25 import org.apache.log4j.Logger;
26
27 /***
28 * TODO Add docs
29 *
30 * Created on 13.12.2004
31 * Contributing Author(s):
32 *
33 * Misha Lifschitz <mishalifschitz at users.sourceforge.net> (Inital implementation)
34 * Vlad Skarzhevskyy <vlads at users.sourceforge.net> (Inital implementation)
35 *
36 * @author vlads
37 * @version $Revision: 1.4 $ ($Author: vlads $) $Date: 2004/12/16 17:40:19 $
38 */
39 public class MethodAccumulation extends TimeBaseAccumulationList {
40
41 protected static final Logger log = Logger.getLogger(MethodAccumulation.class);
42
43 private int firstExecNumber = 1;
44
45 private int countFirst = 0;
46
47 private double firstExec;
48
49 private long exceptionCount = 0;
50
51 public static final String ATTRIBUTE_NAME = "MethodAccumulation.NAME";
52
53 /***
54 *
55 */
56 public MethodAccumulation(String name) {
57 super();
58 setName(name);
59 }
60
61 public void reset() {
62 super.reset();
63 this.firstExec = 0;
64 this.countFirst = 0;
65 this.exceptionCount = 0;
66 }
67
68 public void setName(String name) {
69 setAttribute(ATTRIBUTE_NAME, name);
70 }
71
72 public void add(ProfilerEvent startMethodEvent, ProfilerEvent endMethodEvent) {
73 double time = endMethodEvent.getTimestamp() - startMethodEvent.getTimestamp();
74
75 if (endMethodEvent.getThrowable() != null) {
76 this.exceptionCount ++;
77 }
78
79 if (this.countFirst <= firstExecNumber) {
80 this.countFirst ++;
81 this.firstExec += time;
82 } else {
83 super.add(endMethodEvent.getTimestamp(), new Double(time));
84 }
85 }
86
87
88
89
90 public long getCount() {
91 return super.getCount() + this.countFirst;
92 }
93
94 public double getFirstRunElapsedTime() {
95 if (this.firstExecNumber == 0) {
96 return this.firstExec;
97 }
98 return this.firstExec / this.firstExecNumber;
99 }
100
101 public String getName() {
102 return (String)getAttribute(ATTRIBUTE_NAME);
103 }
104 /***
105 * @return Returns the firstExec.
106 */
107 public double getFirstExec() {
108 return firstExec;
109 }
110 /***
111 * @param firstExec The firstExec to set.
112 */
113 public void setFirstExec(double firstExec) {
114 this.firstExec = firstExec;
115 }
116 /***
117 * @return Returns the exceptionCount.
118 */
119 public long getExceptionCount() {
120 return exceptionCount;
121 }
122 }