Chromium Code Reviews| 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 <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 Loading... | |
| 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 |
|
ppi
2015/10/29 13:33:43
End the comment with a period.
nelly
2015/10/29 14:20:17
Done.
| |
| 48 // categories targeted in measurements. | 48 std::string categories_str = "*"; |
| 49 std::set<std::string> category_set; | 49 if (!args_.trace_all_categories) { |
| 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())); |
|
etiennej
2015/10/29 13:35:51
Beware of your whitespace.
qsr
2015/10/29 13:40:49
Using 'git cl format' should use clang to format y
nelly
2015/10/29 14:20:17
Done.
| |
| 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, |
| 70 base::Bind(&BenchmarkApp::StartTracedApplication, | 64 base::Bind(&BenchmarkApp::StartTracedApplication, |
| 71 base::Unretained(this), app), | 65 base::Unretained(this), app), |
| 72 base::TimeDelta::FromSeconds(1)); | 66 base::TimeDelta::FromMilliseconds(1000)); |
| 67 } | |
| 68 | |
| 69 // Compute the string of trace categories we want to collect: a union of all | |
|
ppi
2015/10/29 13:33:43
Function comments should be "third-person", ie. "C
nelly
2015/10/29 14:20:17
Done.
| |
| 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, ','); | |
| 73 } | 81 } |
| 74 | 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( |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 } |
| OLD | NEW |