OLD | NEW |
| (Empty) |
1 // Copyright 2006-2009 Google Inc. | |
2 // | |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | |
4 // you may not use this file except in compliance with the License. | |
5 // You may obtain a copy of the License at | |
6 // | |
7 // http://www.apache.org/licenses/LICENSE-2.0 | |
8 // | |
9 // Unless required by applicable law or agreed to in writing, software | |
10 // distributed under the License is distributed on an "AS IS" BASIS, | |
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
12 // See the License for the specific language governing permissions and | |
13 // limitations under the License. | |
14 // ======================================================================== | |
15 // | |
16 // | |
17 #include "formatter.h" | |
18 | |
19 namespace stats_report { | |
20 | |
21 Formatter::Formatter(const char *name, uint32 measurement_secs) { | |
22 output_ << name << "&" << measurement_secs; | |
23 } | |
24 | |
25 Formatter::~Formatter() { | |
26 } | |
27 | |
28 void Formatter::AddCount(const char *name, int64 value) { | |
29 output_ << "&" << name << ":c=" << value; | |
30 } | |
31 | |
32 void Formatter::AddTiming(const char *name, int64 num, int64 avg, | |
33 int64 min, int64 max) { | |
34 output_ << "&" << name << ":t=" << num << ";" | |
35 << avg << ";" << min << ";" << max; | |
36 } | |
37 | |
38 void Formatter::AddInteger(const char *name, int64 value) { | |
39 output_ << "&" << name << ":i=" << value; | |
40 } | |
41 | |
42 void Formatter::AddBoolean(const char *name, bool value) { | |
43 output_ << "&" << name << ":b=" << (value ? "t" : "f"); | |
44 } | |
45 | |
46 void Formatter::AddMetric(MetricBase *metric) { | |
47 switch (metric->type()) { | |
48 case kCountType: { | |
49 CountMetric &count = metric->AsCount(); | |
50 AddCount(count.name(), count.value()); | |
51 } | |
52 break; | |
53 | |
54 case kTimingType: { | |
55 TimingMetric &timing = metric->AsTiming(); | |
56 AddTiming(timing.name(), timing.count(), timing.average(), | |
57 timing.minimum(), timing.maximum()); | |
58 } | |
59 break; | |
60 | |
61 case kIntegerType: { | |
62 IntegerMetric &integer = metric->AsInteger(); | |
63 AddInteger(integer.name(), integer.value()); | |
64 } | |
65 break; | |
66 | |
67 case kBoolType: { | |
68 BoolMetric &boolean = metric->AsBool(); | |
69 // TODO(omaha): boolean.value() returns a TristateBoolValue. The | |
70 // formatter is going to serialize kBoolUnset to true. | |
71 DCHECK_NE(boolean.value(), BoolMetric::kBoolUnset); | |
72 AddBoolean(boolean.name(), boolean.value() != BoolMetric::kBoolFalse); | |
73 } | |
74 break; | |
75 | |
76 default: | |
77 DCHECK(false && "Impossible metric type"); | |
78 } | |
79 } | |
80 | |
81 } // namespace stats_report | |
OLD | NEW |