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

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: Benchmark Created 5 years, 1 month 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 | mojo/devtools/common/mojo_benchmark » ('j') | 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.
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"
(...skipping 26 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 // Don't compute the categories string if all categories should be traced.
48 // categories targeted in measurements. 48 std::string categories_str = "*";
49 std::set<std::string> category_set; 49 if (!args_.write_output_file) {
ppi 2015/10/29 16:02:09 nit: it's a bit weird to set the initial value to
nelly 2015/10/29 16:48:22 Done.
50 for (const Measurement& measurement : args_.measurements) { 50 categories_str = ComputeCategoriesStr();
51 std::vector<std::string> categories;
52 base::SplitString(measurement.target_event.categories, ',', &categories);
53 category_set.insert(categories.begin(), categories.end());
54 } 51 }
55 std::vector<std::string> unique_categories(category_set.begin(),
56 category_set.end());
57 std::string categories_str = JoinString(unique_categories, ',');
58 52
59 // Connect to trace collector, which will fetch the trace events produced by 53 // Connect to trace collector, which will fetch the trace events produced by
60 // the app being benchmarked. 54 // the app being benchmarked.
61 tracing::TraceCollectorPtr trace_collector; 55 tracing::TraceCollectorPtr trace_collector;
62 app->ConnectToService("mojo:tracing", &trace_collector); 56 app->ConnectToService("mojo:tracing", &trace_collector);
63 trace_collector_client_.reset( 57 trace_collector_client_.reset(
64 new TraceCollectorClient(this, trace_collector.Pass())); 58 new TraceCollectorClient(this, trace_collector.Pass()));
65 trace_collector_client_->Start(categories_str); 59 trace_collector_client_->Start(categories_str);
66 60
67 // Start tracing the application with 1 sec of delay. 61 // Start tracing the application with 1 sec of delay.
68 base::MessageLoop::current()->PostDelayedTask( 62 base::MessageLoop::current()->PostDelayedTask(
69 FROM_HERE, 63 FROM_HERE, base::Bind(&BenchmarkApp::StartTracedApplication,
70 base::Bind(&BenchmarkApp::StartTracedApplication, 64 base::Unretained(this), app),
71 base::Unretained(this), app), 65 base::TimeDelta::FromMilliseconds(1000));
ppi 2015/10/29 16:02:09 Why the change from s to ms?
nelly 2015/10/29 16:48:22 Done.
72 base::TimeDelta::FromSeconds(1)); 66 }
67
68 // Computes the string of trace categories we want to collect: a union of all
69 // categories targeted in measurements.
70 std::string ComputeCategoriesStr() {
71 std::set<std::string> category_set;
72 for (const Measurement& measurement : args_.measurements) {
73 std::vector<std::string> categories;
74 base::SplitString(measurement.target_event.categories, ',', &categories);
75 category_set.insert(categories.begin(), categories.end());
76 }
77 std::vector<std::string> unique_categories(category_set.begin(),
78 category_set.end());
79 return JoinString(unique_categories, ',');
73 } 80 }
74 81
75 void StartTracedApplication(mojo::ApplicationImpl* app) { 82 void StartTracedApplication(mojo::ApplicationImpl* app) {
76 // Record the time origin for measurements just before connecting to the app 83 // Record the time origin for measurements just before connecting to the app
77 // being benchmarked. 84 // being benchmarked.
78 time_origin_ = base::TimeTicks::FromInternalValue(MojoGetTimeTicksNow()); 85 time_origin_ = base::TimeTicks::FromInternalValue(MojoGetTimeTicksNow());
79 traced_app_connection_ = app->ConnectToApplication(args_.app); 86 traced_app_connection_ = app->ConnectToApplication(args_.app);
80 87
81 // Post task to stop tracing when the time is up. 88 // Post task to stop tracing when the time is up.
82 base::MessageLoop::current()->PostDelayedTask( 89 base::MessageLoop::current()->PostDelayedTask(
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 }; 153 };
147 } // namespace 154 } // namespace
148 } // namespace benchmark 155 } // namespace benchmark
149 156
150 MojoResult MojoMain(MojoHandle application_request) { 157 MojoResult MojoMain(MojoHandle application_request) {
151 mojo::ApplicationRunnerChromium runner(new benchmark::BenchmarkApp); 158 mojo::ApplicationRunnerChromium runner(new benchmark::BenchmarkApp);
152 auto ret = runner.Run(application_request); 159 auto ret = runner.Run(application_request);
153 fflush(nullptr); 160 fflush(nullptr);
154 return ret; 161 return ret;
155 } 162 }
OLDNEW
« no previous file with comments | « no previous file | mojo/devtools/common/mojo_benchmark » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698