blob: 3e9734b7450656c155d69fc81e1dafdadfe0c404 [file] [log] [blame]
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -08001package net.floodlightcontroller.perfmon;
2
3import org.codehaus.jackson.annotate.JsonProperty;
4
5import net.floodlightcontroller.core.IOFMessageListener;
6
7/**
8 * Holds OF message processing time information for one IFloodlightModule.
9 * @author Subrata
10 */
11public class OneComponentTime {
12 private int compId; // hascode of IOFMessageListener
13 private String compName;
14 private int pktCnt;
15 // all times in nanoseconds
16 private long totalProcTimeNs;
17 private long sumSquaredProcTimeNs2; // squared
18 private long maxProcTimeNs;
19 private long minProcTimeNs;
20 private long avgProcTimeNs;
21 private long sigmaProcTimeNs; // std. deviation
22
23 public OneComponentTime(IOFMessageListener module) {
24 compId = module.hashCode();
25 compName = module.getClass().getCanonicalName();
26 resetAllCounters();
27 }
28
29 public void resetAllCounters() {
30 maxProcTimeNs = Long.MIN_VALUE;
31 minProcTimeNs = Long.MAX_VALUE;
32 pktCnt = 0;
33 totalProcTimeNs = 0;
34 sumSquaredProcTimeNs2 = 0;
35 avgProcTimeNs = 0;
36 sigmaProcTimeNs = 0;
37 }
38
39 @JsonProperty("module-name")
40 public String getCompName() {
41 return compName;
42 }
43
44 @JsonProperty("num-packets")
45 public int getPktCnt() {
46 return pktCnt;
47 }
48
49 @JsonProperty("total")
50 public long getSumProcTimeNs() {
51 return totalProcTimeNs;
52 }
53
54 @JsonProperty("max")
55 public long getMaxProcTimeNs() {
56 return maxProcTimeNs;
57 }
58
59 @JsonProperty("min")
60 public long getMinProcTimeNs() {
61 return minProcTimeNs;
62 }
63
64 @JsonProperty("average")
65 public long getAvgProcTimeNs() {
66 return avgProcTimeNs;
67 }
68
69 @JsonProperty("std-dev")
70 public long getSigmaProcTimeNs() {
71 return sigmaProcTimeNs;
72 }
73
74 @JsonProperty("average-squared")
75 public long getSumSquaredProcTimeNs() {
76 return sumSquaredProcTimeNs2;
77 }
78
79 // Methods used to update the counters
80
81 private void increasePktCount() {
82 pktCnt++;
83 }
84
85 private void updateTotalProcessingTime(long procTimeNs) {
86 totalProcTimeNs += procTimeNs;
87 }
88
89 private void updateAvgProcessTime() {
90 avgProcTimeNs = totalProcTimeNs / pktCnt;
91 }
92
93 private void updateSquaredProcessingTime(long procTimeNs) {
94 sumSquaredProcTimeNs2 += (Math.pow(procTimeNs, 2));
95 }
96
97 private void calculateMinProcTime(long curTimeNs) {
98 if (curTimeNs < minProcTimeNs)
99 minProcTimeNs = curTimeNs;
100 }
101
102 private void calculateMaxProcTime(long curTimeNs) {
103 if (curTimeNs > maxProcTimeNs)
104 maxProcTimeNs = curTimeNs;
105 }
106
107 public void computeSigma() {
108 // Computes std. deviation from the sum of count numbers and from
109 // the sum of the squares of count numbers
110 double temp = totalProcTimeNs;
111 temp = Math.pow(temp, 2) / pktCnt;
112 temp = (sumSquaredProcTimeNs2 - temp) / pktCnt;
113 sigmaProcTimeNs = (long) Math.sqrt(temp);
114 }
115
116 public void updatePerPacketCounters(long procTimeNs) {
117 increasePktCount();
118 updateTotalProcessingTime(procTimeNs);
119 calculateMinProcTime(procTimeNs);
120 calculateMaxProcTime(procTimeNs);
121 updateAvgProcessTime();
122 updateSquaredProcessingTime(procTimeNs);
123 }
124
125 @Override
126 public int hashCode() {
127 return compId;
128 }
129}