Close organizes collected Samples and calculates aggregates. After Close(), no more samples can be added.
()
| 66 | |
| 67 | // Close organizes collected Samples and calculates aggregates. After Close(), no more samples can be added. |
| 68 | func (bm *Benchmark) Close() { |
| 69 | close(bm.subChannel) |
| 70 | close(bm.pubChannel) |
| 71 | |
| 72 | for s := range bm.subChannel { |
| 73 | bm.Subs.AddSample(s) |
| 74 | } |
| 75 | for s := range bm.pubChannel { |
| 76 | bm.Pubs.AddSample(s) |
| 77 | } |
| 78 | |
| 79 | if bm.Subs.HasSamples() { |
| 80 | bm.Start = bm.Subs.Start |
| 81 | bm.End = bm.Subs.End |
| 82 | } else { |
| 83 | bm.Start = bm.Pubs.Start |
| 84 | bm.End = bm.Pubs.End |
| 85 | } |
| 86 | |
| 87 | if bm.Subs.HasSamples() && bm.Pubs.HasSamples() { |
| 88 | if bm.Start.After(bm.Subs.Start) { |
| 89 | bm.Start = bm.Subs.Start |
| 90 | } |
| 91 | if bm.Start.After(bm.Pubs.Start) { |
| 92 | bm.Start = bm.Pubs.Start |
| 93 | } |
| 94 | |
| 95 | if bm.End.Before(bm.Subs.End) { |
| 96 | bm.End = bm.Subs.End |
| 97 | } |
| 98 | if bm.End.Before(bm.Pubs.End) { |
| 99 | bm.End = bm.Pubs.End |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | bm.MsgBytes = bm.Pubs.MsgBytes + bm.Subs.MsgBytes |
| 104 | bm.IOBytes = bm.Pubs.IOBytes + bm.Subs.IOBytes |
| 105 | bm.MsgCnt = bm.Pubs.MsgCnt + bm.Subs.MsgCnt |
| 106 | bm.JobMsgCnt = bm.Pubs.JobMsgCnt + bm.Subs.JobMsgCnt |
| 107 | } |
| 108 | |
| 109 | // AddSubSample to the benchmark |
| 110 | func (bm *Benchmark) AddSubSample(s *Sample) { |