OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "apps/benchmark/run_args.h" | 5 #include "apps/benchmark/run_args.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
12 #include "base/strings/string_split.h" | 12 #include "base/strings/string_split.h" |
13 | 13 |
14 namespace benchmark { | 14 namespace benchmark { |
15 namespace { | 15 namespace { |
16 | 16 |
| 17 bool CheckMeasurementFormat(const std::string& type, |
| 18 int required_args, |
| 19 int provided_args) { |
| 20 if (required_args != provided_args) { |
| 21 LOG(ERROR) << "Could not parse a measurement of type " << type |
| 22 << ", expected " << required_args << " while " << provided_args |
| 23 << " were provided"; |
| 24 return false; |
| 25 } |
| 26 return true; |
| 27 } |
| 28 |
17 bool GetMeasurement(const std::string& measurement_spec, Measurement* result) { | 29 bool GetMeasurement(const std::string& measurement_spec, Measurement* result) { |
18 // Measurements are described in the format: | 30 // Measurements are described in the format: |
19 // <measurement type>/<event category>/<event name>. | 31 // <measurement type>/<event category>/<event name>. |
20 std::vector<std::string> parts; | 32 std::vector<std::string> parts; |
21 base::SplitString(measurement_spec, '/', &parts); | 33 base::SplitString(measurement_spec, '/', &parts); |
22 if (parts.size() != 3) { | 34 if (parts.size() < 1) { |
23 LOG(ERROR) << "Could not parse the measurement description: " | 35 LOG(ERROR) << "Could not parse the measurement description: " |
24 << measurement_spec; | 36 << measurement_spec; |
25 return false; | 37 return false; |
26 } | 38 } |
27 | 39 |
28 if (parts[0] == "time_until") { | 40 if (parts[0] == "time_until") { |
29 result->type = MeasurementType::TIME_UNTIL; | 41 if (!CheckMeasurementFormat(parts[0], 3, parts.size())) |
| 42 return false; |
| 43 *result = |
| 44 Measurement(MeasurementType::TIME_UNTIL, EventSpec(parts[1], parts[2])); |
| 45 } else if (parts[0] == "time_between") { |
| 46 if (!CheckMeasurementFormat(parts[0], 5, parts.size())) |
| 47 return false; |
| 48 *result = Measurement(MeasurementType::TIME_BETWEEN, |
| 49 EventSpec(parts[1], parts[2]), |
| 50 EventSpec(parts[3], parts[4])); |
30 } else if (parts[0] == "avg_duration") { | 51 } else if (parts[0] == "avg_duration") { |
31 result->type = MeasurementType::AVG_DURATION; | 52 if (!CheckMeasurementFormat(parts[0], 3, parts.size())) |
| 53 return false; |
| 54 *result = Measurement(MeasurementType::AVG_DURATION, |
| 55 EventSpec(parts[1], parts[2])); |
32 } else { | 56 } else { |
33 LOG(ERROR) << "Could not recognize the measurement type: " << parts[0]; | 57 LOG(ERROR) << "Could not recognize the measurement type: " << parts[0]; |
34 return false; | 58 return false; |
35 } | 59 } |
36 | 60 |
37 result->target_event.categories = parts[1]; | |
38 result->target_event.name = parts[2]; | |
39 result->spec = measurement_spec; | 61 result->spec = measurement_spec; |
40 return true; | 62 return true; |
41 } | 63 } |
42 | 64 |
43 } // namespace | 65 } // namespace |
44 | 66 |
45 RunArgs::RunArgs() {} | 67 RunArgs::RunArgs() {} |
46 | 68 |
47 RunArgs::~RunArgs() {} | 69 RunArgs::~RunArgs() {} |
48 | 70 |
(...skipping 33 matching lines...) Loading... |
82 if (!GetMeasurement(measurement_spec, &measurement)) { | 104 if (!GetMeasurement(measurement_spec, &measurement)) { |
83 return false; | 105 return false; |
84 } | 106 } |
85 result->measurements.push_back(measurement); | 107 result->measurements.push_back(measurement); |
86 } | 108 } |
87 | 109 |
88 return true; | 110 return true; |
89 } | 111 } |
90 | 112 |
91 } // namespace benchmark | 113 } // namespace benchmark |
OLD | NEW |