001 package org.shiftone.jrat.provider.tree.ui.summary;
002
003 import org.shiftone.jrat.core.Accumulator;
004 import org.shiftone.jrat.core.MethodKey;
005 import org.shiftone.jrat.provider.tree.ui.TraceTreeNode;
006 import org.shiftone.jrat.util.Percent;
007
008 /**
009 * @author (jeff@shiftone.org) Jeff Drost
010 */
011 public class MethodSummary {
012
013 private final MethodKey methodKey;
014 private long totalEnters;
015 private long totalExists;
016 private long totalErrors;
017 private long minDuration = Long.MAX_VALUE;
018 private long maxDuration = Long.MIN_VALUE;
019 private long totalDuration;
020 private long totalMethodDuration;
021 private int totalCallers;
022
023
024 public MethodSummary(MethodKey methodKey) {
025 this.methodKey = methodKey;
026 }
027
028 public void addStatistics(TraceTreeNode node) {
029 Accumulator accumulator = node.getAccumulator();
030 totalEnters += accumulator.getTotalEnters();
031 totalExists += accumulator.getTotalExits();
032 totalErrors += accumulator.getTotalErrors();
033 if (totalExists > 0) {
034 // if the node has not been existed, then the min and max times
035 // will only have the MAX_VALUE and MIN_VALUE.
036 minDuration = Math.min(minDuration, accumulator.getMinDuration());
037 maxDuration = Math.max(maxDuration, accumulator.getMaxDuration());
038 }
039 totalDuration += accumulator.getTotalDuration();
040 totalMethodDuration += node.getTotalMethodDuration();
041 totalCallers++;
042 }
043
044
045 /**
046 * It the method has been entered but not exited, then it is
047 * possible that the method time would end up negative. I'm not
048 * showing it at all in this case to avoid confusion.
049 */
050 public Long getTotalMethodDuration() {
051 return totalEnters != totalExists
052 ? null
053 : new Long(totalMethodDuration);
054 }
055
056 public Double getAverageMethodDuration() {
057 return (totalExists == 0) || (totalEnters != totalExists)
058 ? null
059 : new Double((double) totalMethodDuration / (double) totalExists);
060 }
061
062 public Double getAverageDuration() {
063 return totalExists == 0
064 ? null
065 : new Double((double) totalDuration / (double) totalExists);
066 }
067
068 public Percent getErrorRate() {
069 return (totalExists == 0)
070 ? null
071 : new Percent(((double) totalErrors * 100.0) / (double) totalExists);
072 }
073
074 public long getUncompletedCalls() {
075 return totalEnters - totalExists;
076 }
077
078
079 public long getTotalEnters() {
080 return totalEnters;
081 }
082
083 public long getTotalExists() {
084 return totalExists;
085 }
086
087 public long getTotalErrors() {
088 return totalErrors;
089 }
090
091 public Long getMinDuration() {
092 return minDuration == Long.MAX_VALUE ? null : new Long(minDuration);
093 }
094
095 public Long getMaxDuration() {
096 return maxDuration == Long.MIN_VALUE ? null : new Long(maxDuration);
097 }
098
099 public long getTotalDuration() {
100 return totalDuration;
101 }
102
103 public int getTotalCallers() {
104 return totalCallers;
105 }
106
107 public MethodKey getMethodKey() {
108 return methodKey;
109 }
110 }