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

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

Issue 1391013005: Benchmark: `--save-all-traces` argument (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: merge Created 5 years, 2 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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
ppi 2015/10/12 19:32:50 nits about the commit message: please break the f
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 <memory> 5 #include <memory>
6 #include <set> 6 #include <set>
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "apps/benchmark/event.h" 10 #include "apps/benchmark/event.h"
11 #include "apps/benchmark/measurements.h" 11 #include "apps/benchmark/measurements.h"
(...skipping 25 matching lines...) Expand all
37 37
38 // mojo:ApplicationDelegate: 38 // mojo:ApplicationDelegate:
39 void Initialize(mojo::ApplicationImpl* app) override { 39 void Initialize(mojo::ApplicationImpl* app) override {
40 // Parse command-line arguments. 40 // Parse command-line arguments.
41 if (!GetRunArgs(app->args(), &args_)) { 41 if (!GetRunArgs(app->args(), &args_)) {
42 LOG(ERROR) << "Failed to parse the input arguments."; 42 LOG(ERROR) << "Failed to parse the input arguments.";
43 mojo::ApplicationImpl::Terminate(); 43 mojo::ApplicationImpl::Terminate();
44 return; 44 return;
45 } 45 }
46 46
47 // Calculate a list of trace categories we want to collect: a union of all 47 // Trace all categories when results will be written in a file. No need
48 // categories targeted in measurements. 48 // to compute the categories string in that case (using "*" instead).
49 std::set<std::string> category_set; 49 std::string categories_str = "*";
50 for (const Measurement& measurement : args_.measurements) { 50 if (!args_.write_output_file) {
ppi 2015/10/12 19:30:52 I'd argue that we should record all categories ind
51 std::vector<std::string> categories; 51 categories_str = ComputeCategoriesStr();
52 base::SplitString(measurement.target_event.categories, ',', &categories);
53 category_set.insert(categories.begin(), categories.end());
54 } 52 }
55 std::vector<std::string> unique_categories(category_set.begin(),
56 category_set.end());
57 std::string categories_str = JoinString(unique_categories, ',');
58 53
59 // Connect to trace collector, which will fetch the trace events produced by 54 // Connect to trace collector, which will fetch the trace events produced by
60 // the app being benchmarked. 55 // the app being benchmarked.
61 tracing::TraceCollectorPtr trace_collector; 56 tracing::TraceCollectorPtr trace_collector;
62 app->ConnectToService("mojo:tracing", &trace_collector); 57 app->ConnectToService("mojo:tracing", &trace_collector);
63 trace_collector_client_.reset( 58 trace_collector_client_.reset(
64 new TraceCollectorClient(this, trace_collector.Pass())); 59 new TraceCollectorClient(this, trace_collector.Pass()));
65 trace_collector_client_->Start(categories_str); 60 trace_collector_client_->Start(categories_str);
66 61
67 // Start tracing the application with 1 sec of delay. 62 // Start tracing the application with 1 sec of delay.
68 base::MessageLoop::current()->PostDelayedTask( 63 base::MessageLoop::current()->PostDelayedTask(
69 FROM_HERE, 64 FROM_HERE, base::Bind(&BenchmarkApp::StartTracedApplication,
70 base::Bind(&BenchmarkApp::StartTracedApplication, 65 base::Unretained(this), app),
71 base::Unretained(this), app),
72 base::TimeDelta::FromSeconds(1)); 66 base::TimeDelta::FromSeconds(1));
73 } 67 }
74 68
69 // Calculate a list of trace categories we want to collect: a union of all
70 // categories targeted in measurements.
71 std::string ComputeCategoriesStr() {
72 std::set<std::string> category_set;
73 for (const Measurement& measurement : args_.measurements) {
74 std::vector<std::string> categories;
75 base::SplitString(measurement.target_event.categories, ',', &categories);
76 category_set.insert(categories.begin(), categories.end());
77 }
78 std::vector<std::string> unique_categories(category_set.begin(),
79 category_set.end());
80 return JoinString(unique_categories, ',');
81 }
82
75 void StartTracedApplication(mojo::ApplicationImpl* app) { 83 void StartTracedApplication(mojo::ApplicationImpl* app) {
76 // Record the time origin for measurements just before connecting to the app 84 // Record the time origin for measurements just before connecting to the app
77 // being benchmarked. 85 // being benchmarked.
78 time_origin_ = base::TimeTicks::FromInternalValue(MojoGetTimeTicksNow()); 86 time_origin_ = base::TimeTicks::FromInternalValue(MojoGetTimeTicksNow());
79 traced_app_connection_ = app->ConnectToApplication(args_.app); 87 traced_app_connection_ = app->ConnectToApplication(args_.app);
80 88
81 // Post task to stop tracing when the time is up. 89 // Post task to stop tracing when the time is up.
82 base::MessageLoop::current()->PostDelayedTask( 90 base::MessageLoop::current()->PostDelayedTask(
83 FROM_HERE, 91 FROM_HERE,
84 base::Bind(&BenchmarkApp::StopTracing, base::Unretained(this)), 92 base::Bind(&BenchmarkApp::StopTracing, base::Unretained(this)),
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 }; 154 };
147 } // namespace 155 } // namespace
148 } // namespace benchmark 156 } // namespace benchmark
149 157
150 MojoResult MojoMain(MojoHandle application_request) { 158 MojoResult MojoMain(MojoHandle application_request) {
151 mojo::ApplicationRunnerChromium runner(new benchmark::BenchmarkApp); 159 mojo::ApplicationRunnerChromium runner(new benchmark::BenchmarkApp);
152 auto ret = runner.Run(application_request); 160 auto ret = runner.Run(application_request);
153 fflush(nullptr); 161 fflush(nullptr);
154 return ret; 162 return ret;
155 } 163 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698