OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef COMPONENTS_METRICS_CHROMEOS_METRICS_UTILS_H_ | |
6 #define COMPONENTS_METRICS_CHROMEOS_METRICS_UTILS_H_ | |
7 | |
8 #include <string> | |
9 | |
10 #include "base/memory/scoped_ptr.h" | |
11 #include "base/memory/scoped_vector.h" | |
12 | |
13 namespace metrics { | |
14 | |
15 class MetricSample; | |
16 | |
17 // Metrics helpers to serialize and deserialize metrics collected by | |
18 // ChromeOS. | |
19 namespace MetricsUtils { | |
Alexei Svitkine (slow)
2014/05/15 13:43:26
Can this have a better name? It's already in the m
bsimonnet
2014/05/15 19:23:40
Done.
| |
20 | |
21 // Deserialize a sample passed as a string and return a sample. | |
22 // The return value will either be a scoped_ptr to a Metric sample (if the | |
23 // deserialization was successful) or a NULL scoped_ptr. | |
24 scoped_ptr<MetricSample> ReadSample(const std::string& sample); | |
Alexei Svitkine (slow)
2014/05/15 13:43:26
Nit: A better name might be "ParseSample", since t
bsimonnet
2014/05/15 19:23:40
Done.
| |
25 | |
26 // Read all samples from a file and truncate the file when done. | |
27 void ReadAndTruncateMetricsFromFile(const std::string& filename, | |
28 ScopedVector<MetricSample>* metrics); | |
29 | |
30 // Serialize a sample and write it to filename. | |
31 // The format for the message is: | |
32 // message_size, serialized_message | |
33 // where | |
34 // * message_size is the total length of the message (message_size + | |
35 // serialized_message) on 4 bytes | |
36 // * serialized_message is the serialized version of sample (using ToString) | |
37 // | |
38 // NB: the file will never leave the device so message_size will be written | |
39 // with the architecture's endianness. | |
40 bool WriteMetricToFile(const MetricSample* sample, const std::string& filename); | |
41 | |
42 // Maximum length of a serialized message | |
43 const int kMessageMaxLength = 1024; | |
44 | |
45 } // namespace MetricsUtils | |
46 } // namespace metrics | |
47 | |
48 #endif // COMPONENTS_METRICS_CHROMEOS_METRICS_UTILS_H_ | |
OLD | NEW |