Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(43)

Side by Side Diff: apps/benchmark/run_args.cc

Issue 1305193002: Trace-based benchmarking via a mojo app. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Further address Etienne's comments. Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « apps/benchmark/run_args.h ('k') | apps/benchmark/trace_collector_client.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "apps/benchmark/run_args.h"
6
7 #include <algorithm>
8
9 #include "base/command_line.h"
10 #include "base/logging.h"
11 #include "base/strings/string_number_conversions.h"
12 #include "base/strings/string_split.h"
13
14 namespace benchmark {
15 namespace {
16
17 bool GetMeasurement(const std::string& measurement_spec, Measurement* result) {
18 // Measurements are described in the format:
19 // <measurement type>/<event category>/<event name>.
20 std::vector<std::string> parts;
21 base::SplitString(measurement_spec, '/', &parts);
22 if (parts.size() != 3) {
23 LOG(ERROR) << "Could not parse the measurement description: "
24 << measurement_spec;
25 return false;
26 }
27
28 if (parts[0] == "time_until") {
29 result->type = MeasurementType::TIME_UNTIL;
30 } else if (parts[0] == "avg_duration") {
31 result->type = MeasurementType::AVG_DURATION;
32 } else {
33 LOG(ERROR) << "Could not recognize the measurement type: " << parts[0];
34 return false;
35 }
36
37 result->target_event.category = parts[1];
38 result->target_event.name = parts[2];
39 result->spec = measurement_spec;
40 return true;
41 }
42
43 } // namespace
44
45 RunArgs::RunArgs() {}
46
47 RunArgs::~RunArgs() {}
48
49 bool GetRunArgs(const std::vector<std::string>& input_args, RunArgs* result) {
50 base::CommandLine command_line(input_args);
51
52 result->app = command_line.GetSwitchValueASCII("app");
53 if (result->app.empty()) {
54 LOG(ERROR) << "The required --app argument is empty or missing.";
55 return false;
56 }
57
58 std::string duration_str = command_line.GetSwitchValueASCII("duration");
59 if (duration_str.empty()) {
60 LOG(ERROR) << "The required --duration argument is empty or missing.";
61 return false;
62 }
63 int duration_int;
64 if (!base::StringToInt(duration_str, &duration_int) || duration_int <= 0) {
65 LOG(ERROR) << "Could not parse the --duration value as a positive integer: "
66 << duration_str;
67 return false;
68 }
69 result->duration = base::TimeDelta::FromSeconds(duration_int);
70
71 // All regular arguments (not switches, ie. not preceded by "--") describe
72 // measurements.
73 for (const std::string& measurement_spec : command_line.GetArgs()) {
74 Measurement measurement;
75 if (!GetMeasurement(measurement_spec, &measurement)) {
76 return false;
77 }
78 result->measurements.push_back(measurement);
79 }
80
81 return true;
82 }
83
84 } // namespace benchmark
OLDNEW
« no previous file with comments | « apps/benchmark/run_args.h ('k') | apps/benchmark/trace_collector_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698