| 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. |
| 48 // categories targeted in measurements. | 48 std::string categories_str; |
| 49 std::set<std::string> category_set; | 49 if (args_.write_output_file) { |
| 50 for (const Measurement& measurement : args_.measurements) { | 50 categories_str = "*"; |
| 51 std::vector<std::string> categories; | 51 } else { |
| 52 base::SplitString(measurement.target_event.categories, ',', &categories); | 52 categories_str = ComputeCategoriesStr(); |
| 53 category_set.insert(categories.begin(), categories.end()); | |
| 54 } | 53 } |
| 55 std::vector<std::string> unique_categories(category_set.begin(), | |
| 56 category_set.end()); | |
| 57 std::string categories_str = JoinString(unique_categories, ','); | |
| 58 | 54 |
| 59 // Connect to trace collector, which will fetch the trace events produced by | 55 // Connect to trace collector, which will fetch the trace events produced by |
| 60 // the app being benchmarked. | 56 // the app being benchmarked. |
| 61 tracing::TraceCollectorPtr trace_collector; | 57 tracing::TraceCollectorPtr trace_collector; |
| 62 app->ConnectToService("mojo:tracing", &trace_collector); | 58 app->ConnectToService("mojo:tracing", &trace_collector); |
| 63 trace_collector_client_.reset( | 59 trace_collector_client_.reset( |
| 64 new TraceCollectorClient(this, trace_collector.Pass())); | 60 new TraceCollectorClient(this, trace_collector.Pass())); |
| 65 trace_collector_client_->Start(categories_str); | 61 trace_collector_client_->Start(categories_str); |
| 66 | 62 |
| 67 // Start tracing the application with 1 sec of delay. | 63 // Start tracing the application with 1 sec of delay. |
| 68 base::MessageLoop::current()->PostDelayedTask( | 64 base::MessageLoop::current()->PostDelayedTask( |
| 69 FROM_HERE, | 65 FROM_HERE, base::Bind(&BenchmarkApp::StartTracedApplication, |
| 70 base::Bind(&BenchmarkApp::StartTracedApplication, | 66 base::Unretained(this), app), |
| 71 base::Unretained(this), app), | |
| 72 base::TimeDelta::FromSeconds(1)); | 67 base::TimeDelta::FromSeconds(1)); |
| 73 } | 68 } |
| 74 | 69 |
| 70 // Computes the string of trace categories we want to collect: a union of all |
| 71 // categories targeted in measurements. |
| 72 std::string ComputeCategoriesStr() { |
| 73 std::set<std::string> category_set; |
| 74 for (const Measurement& measurement : args_.measurements) { |
| 75 std::vector<std::string> categories; |
| 76 base::SplitString(measurement.target_event.categories, ',', &categories); |
| 77 category_set.insert(categories.begin(), categories.end()); |
| 78 } |
| 79 std::vector<std::string> unique_categories(category_set.begin(), |
| 80 category_set.end()); |
| 81 return JoinString(unique_categories, ','); |
| 82 } |
| 83 |
| 75 void StartTracedApplication(mojo::ApplicationImpl* app) { | 84 void StartTracedApplication(mojo::ApplicationImpl* app) { |
| 76 // Record the time origin for measurements just before connecting to the app | 85 // Record the time origin for measurements just before connecting to the app |
| 77 // being benchmarked. | 86 // being benchmarked. |
| 78 time_origin_ = base::TimeTicks::FromInternalValue(MojoGetTimeTicksNow()); | 87 time_origin_ = base::TimeTicks::FromInternalValue(MojoGetTimeTicksNow()); |
| 79 traced_app_connection_ = app->ConnectToApplication(args_.app); | 88 traced_app_connection_ = app->ConnectToApplication(args_.app); |
| 80 | 89 |
| 81 // Post task to stop tracing when the time is up. | 90 // Post task to stop tracing when the time is up. |
| 82 base::MessageLoop::current()->PostDelayedTask( | 91 base::MessageLoop::current()->PostDelayedTask( |
| 83 FROM_HERE, | 92 FROM_HERE, |
| 84 base::Bind(&BenchmarkApp::StopTracing, base::Unretained(this)), | 93 base::Bind(&BenchmarkApp::StopTracing, base::Unretained(this)), |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 }; | 155 }; |
| 147 } // namespace | 156 } // namespace |
| 148 } // namespace benchmark | 157 } // namespace benchmark |
| 149 | 158 |
| 150 MojoResult MojoMain(MojoHandle application_request) { | 159 MojoResult MojoMain(MojoHandle application_request) { |
| 151 mojo::ApplicationRunnerChromium runner(new benchmark::BenchmarkApp); | 160 mojo::ApplicationRunnerChromium runner(new benchmark::BenchmarkApp); |
| 152 auto ret = runner.Run(application_request); | 161 auto ret = runner.Run(application_request); |
| 153 fflush(nullptr); | 162 fflush(nullptr); |
| 154 return ret; | 163 return ret; |
| 155 } | 164 } |
| OLD | NEW |