diff options
Diffstat (limited to 'pki/base/common/src/com/netscape/certsrv/util/StatsEvent.java')
-rw-r--r-- | pki/base/common/src/com/netscape/certsrv/util/StatsEvent.java | 309 |
1 files changed, 145 insertions, 164 deletions
diff --git a/pki/base/common/src/com/netscape/certsrv/util/StatsEvent.java b/pki/base/common/src/com/netscape/certsrv/util/StatsEvent.java index 7c510b889..9e004b629 100644 --- a/pki/base/common/src/com/netscape/certsrv/util/StatsEvent.java +++ b/pki/base/common/src/com/netscape/certsrv/util/StatsEvent.java @@ -17,7 +17,6 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.certsrv.util; - import java.util.Enumeration; import java.util.Vector; @@ -28,167 +27,149 @@ import java.util.Vector; * @author thomask * @version $Revision$, $Date$ */ -public class StatsEvent -{ - private String mName = null; - private long mMin = -1; - private long mMax = -1; - private long mTimeTaken = 0; - private long mTimeTakenSqSum = 0; - private long mNoOfOperations = 0; - private Vector mSubEvents = new Vector(); - private StatsEvent mParent = null; - - public StatsEvent(StatsEvent parent) - { - mParent = parent; - } - - public void setName(String name) - { - mName = name; - } - - /** - * Retrieves Transaction name. - */ - public String getName() - { - return mName; - } - - public void addSubEvent(StatsEvent st) - { - mSubEvents.addElement(st); - } - - /** - * Retrieves a list of sub transaction names. - */ - public Enumeration getSubEventNames() - { - Vector names = new Vector(); - Enumeration e = mSubEvents.elements(); - while (e.hasMoreElements()) { - StatsEvent st = (StatsEvent)e.nextElement(); - names.addElement(st.getName()); - } - return names.elements(); - } - - /** - * Retrieves a sub transaction. - */ - public StatsEvent getSubEvent(String name) - { - Enumeration e = mSubEvents.elements(); - while (e.hasMoreElements()) { - StatsEvent st = (StatsEvent)e.nextElement(); - if (st.getName().equals(name)) { - return st; - } - } - return null; - } - - public void resetCounters() - { - mMin = -1; - mMax = -1; - mNoOfOperations = 0; - mTimeTaken = 0; - mTimeTakenSqSum = 0; - Enumeration e = getSubEventNames(); - while (e.hasMoreElements()) { - String n = (String)e.nextElement(); - StatsEvent c = getSubEvent(n); - c.resetCounters(); - } - } - - public long getMax() - { - return mMax; - } - - public long getMin() - { - return mMin; - } - - public void incNoOfOperations(long c) - { - mNoOfOperations += c; - } - - public long getTimeTakenSqSum() - { - return mTimeTakenSqSum; - } - - public long getPercentage() - { - if (mParent == null || mParent.getTimeTaken() == 0) { - return 100; - } else { - return (mTimeTaken * 100 / mParent.getTimeTaken()); - } - } - - public long getStdDev() - { - if (getNoOfOperations() == 0) { - return 0; - } else { - long a = getTimeTakenSqSum(); - long b = (-2 * getAvg() *getTimeTaken()); - long c = getAvg() * getAvg() * getNoOfOperations(); - return (long)Math.sqrt((a + b + c)/getNoOfOperations()); - } - } - - public long getAvg() - { - if (mNoOfOperations == 0) { - return -1; - } else { - return mTimeTaken/mNoOfOperations; - } - } - - /** - * Retrieves number of operations performed. - */ - public long getNoOfOperations() - { - return mNoOfOperations; - } - - public void incTimeTaken(long c) - { - if (mMin == -1) { - mMin = c; - } else { - if (c < mMin) { - mMin = c; - } - } - if (mMax == -1) { - mMax = c; - } else { - if (c > mMax) { - mMax = c; - } - } - mTimeTaken += c; - mTimeTakenSqSum += (c * c); - } - - /** - * Retrieves total time token in msec. - */ - public long getTimeTaken() - { - return mTimeTaken; - } +public class StatsEvent { + private String mName = null; + private long mMin = -1; + private long mMax = -1; + private long mTimeTaken = 0; + private long mTimeTakenSqSum = 0; + private long mNoOfOperations = 0; + private Vector mSubEvents = new Vector(); + private StatsEvent mParent = null; + + public StatsEvent(StatsEvent parent) { + mParent = parent; + } + + public void setName(String name) { + mName = name; + } + + /** + * Retrieves Transaction name. + */ + public String getName() { + return mName; + } + + public void addSubEvent(StatsEvent st) { + mSubEvents.addElement(st); + } + + /** + * Retrieves a list of sub transaction names. + */ + public Enumeration getSubEventNames() { + Vector names = new Vector(); + Enumeration e = mSubEvents.elements(); + while (e.hasMoreElements()) { + StatsEvent st = (StatsEvent) e.nextElement(); + names.addElement(st.getName()); + } + return names.elements(); + } + + /** + * Retrieves a sub transaction. + */ + public StatsEvent getSubEvent(String name) { + Enumeration e = mSubEvents.elements(); + while (e.hasMoreElements()) { + StatsEvent st = (StatsEvent) e.nextElement(); + if (st.getName().equals(name)) { + return st; + } + } + return null; + } + + public void resetCounters() { + mMin = -1; + mMax = -1; + mNoOfOperations = 0; + mTimeTaken = 0; + mTimeTakenSqSum = 0; + Enumeration e = getSubEventNames(); + while (e.hasMoreElements()) { + String n = (String) e.nextElement(); + StatsEvent c = getSubEvent(n); + c.resetCounters(); + } + } + + public long getMax() { + return mMax; + } + + public long getMin() { + return mMin; + } + + public void incNoOfOperations(long c) { + mNoOfOperations += c; + } + + public long getTimeTakenSqSum() { + return mTimeTakenSqSum; + } + + public long getPercentage() { + if (mParent == null || mParent.getTimeTaken() == 0) { + return 100; + } else { + return (mTimeTaken * 100 / mParent.getTimeTaken()); + } + } + + public long getStdDev() { + if (getNoOfOperations() == 0) { + return 0; + } else { + long a = getTimeTakenSqSum(); + long b = (-2 * getAvg() * getTimeTaken()); + long c = getAvg() * getAvg() * getNoOfOperations(); + return (long) Math.sqrt((a + b + c) / getNoOfOperations()); + } + } + + public long getAvg() { + if (mNoOfOperations == 0) { + return -1; + } else { + return mTimeTaken / mNoOfOperations; + } + } + + /** + * Retrieves number of operations performed. + */ + public long getNoOfOperations() { + return mNoOfOperations; + } + + public void incTimeTaken(long c) { + if (mMin == -1) { + mMin = c; + } else { + if (c < mMin) { + mMin = c; + } + } + if (mMax == -1) { + mMax = c; + } else { + if (c > mMax) { + mMax = c; + } + } + mTimeTaken += c; + mTimeTakenSqSum += (c * c); + } + + /** + * Retrieves total time token in msec. + */ + public long getTimeTaken() { + return mTimeTaken; + } } |