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