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 // Utility class to format metrics to a string suitable for posting to | |
17 // TB stats server. | |
18 #ifndef OMAHA_STATSREPORT_FORMATTER_H__ | |
19 #define OMAHA_STATSREPORT_FORMATTER_H__ | |
20 | |
21 #include "base/basictypes.h" | |
22 #include "metrics.h" | |
23 #include <strstream> | |
24 | |
25 namespace stats_report { | |
26 | |
27 /// A utility class that knows how to turn metrics into a string for | |
28 /// reporting to the Toolbar stats server. | |
29 /// This code is mostly appropriated from the toolbars stats formatter | |
30 class Formatter { | |
31 public: | |
32 /// @param name the name of the application to report stats against | |
33 Formatter(const char *name, uint32 measurement_secs); | |
34 ~Formatter(); | |
35 | |
36 /// Add metric to the output string | |
37 void AddMetric(MetricBase *metric); | |
38 | |
39 /// Add typed metrics to the output string | |
40 /// @{ | |
41 void AddCount(const char *name, int64 value); | |
42 void AddTiming(const char *name, int64 num, int64 avg, int64 min, | |
43 int64 max); | |
44 void AddInteger(const char *name, int64 value); | |
45 void AddBoolean(const char *name, bool value); | |
46 /// @} | |
47 | |
48 /// Terminates the output string and returns it. | |
49 /// It is an error to add metrics after output() is called. | |
50 const char *output() { output_ << std::ends; return output_.str(); } | |
51 | |
52 private: | |
53 DISALLOW_EVIL_CONSTRUCTORS(Formatter); | |
54 | |
55 mutable std::strstream output_; | |
56 }; | |
57 | |
58 } // namespace stats_report | |
59 | |
60 #endif // OMAHA_STATSREPORT_FORMATTER_H__ | |
OLD | NEW |