01: /*
02: * Created on 27.05.2005
03: *
04: * TODO To change the template for this generated file go to
05: * Window - Preferences - Java - Code Style - Code Templates
06: */
07: package de.schlund.pfixxml.perflogging;
08:
09: import org.apache.log4j.Logger;
10:
11: /**
12: * @author jh
13: *
14: */
15: public class PerfEvent {
16: private static Logger LOG = Logger.getLogger(PerfEvent.class);
17: private String category;
18: private String identifier;
19: private long duration;
20: private long starttime;
21:
22: public PerfEvent(String category, String identifier) {
23: this .category = category;
24: this .identifier = identifier;
25: }
26:
27: public PerfEvent(String category) {
28: this .category = category;
29: }
30:
31: public String getCategory() {
32: return category;
33: }
34:
35: public String getIdentifier() {
36: return identifier;
37: }
38:
39: public void setIdentfier(String identifier) {
40: this .identifier = identifier;
41: }
42:
43: public void start() {
44: if (!isActive())
45: return;
46: starttime = System.currentTimeMillis();
47: }
48:
49: public void save() {
50: if (!isActive())
51: return;
52: stop();
53: doSave();
54: }
55:
56: public void stop() {
57: if (!isActive())
58: return;
59: duration += System.currentTimeMillis() - starttime;
60: }
61:
62: private void doSave() {
63: if (!isActive())
64: return;
65: PerfEventPut.getInstance().logPerf(this );
66: }
67:
68: long getDuration() {
69: return duration;
70: }
71:
72: public String toString() {
73: return category + "|" + identifier + ":" + duration;
74: }
75:
76: String getKey() {
77: return category + "_" + identifier;
78: }
79:
80: private boolean isActive() {
81: PerfLogging perf = PerfLogging.getInstance();
82: boolean ret1 = perf.isPerfLogggingEnabled();
83: boolean ret2 = perf.isPerfLoggingActive();
84: if (LOG.isDebugEnabled())
85: LOG.debug("Enabled: " + ret1 + " Active: " + ret2);
86: return ret1 && ret2;
87: }
88:
89: }
|