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

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

Issue 1347063002: Teach `benchmark.mojo` to save the collected trace file to disk. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 3 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 | « apps/benchmark/README.md ('k') | apps/benchmark/run_args.h » ('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"
11 #include "apps/benchmark/measurements.h" 11 #include "apps/benchmark/measurements.h"
12 #include "apps/benchmark/run_args.h" 12 #include "apps/benchmark/run_args.h"
13 #include "apps/benchmark/trace_collector_client.h" 13 #include "apps/benchmark/trace_collector_client.h"
14 #include "base/bind.h" 14 #include "base/bind.h"
15 #include "base/files/file_util.h"
15 #include "base/macros.h" 16 #include "base/macros.h"
16 #include "base/memory/scoped_ptr.h" 17 #include "base/memory/scoped_ptr.h"
17 #include "base/strings/string_split.h" 18 #include "base/strings/string_split.h"
18 #include "base/strings/string_util.h" 19 #include "base/strings/string_util.h"
19 #include "base/time/time.h" 20 #include "base/time/time.h"
20 #include "base/trace_event/trace_event.h" 21 #include "base/trace_event/trace_event.h"
21 #include "mojo/application/application_runner_chromium.h" 22 #include "mojo/application/application_runner_chromium.h"
22 #include "mojo/public/c/system/main.h" 23 #include "mojo/public/c/system/main.h"
23 #include "mojo/public/cpp/application/application_connection.h" 24 #include "mojo/public/cpp/application/application_connection.h"
24 #include "mojo/public/cpp/application/application_delegate.h" 25 #include "mojo/public/cpp/application/application_delegate.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 } 77 }
77 78
78 void StopTracing() { 79 void StopTracing() {
79 // Request the trace collector to send back the data. When the data is ready 80 // Request the trace collector to send back the data. When the data is ready
80 // we will be called at OnTraceCollected(). 81 // we will be called at OnTraceCollected().
81 trace_collector_client_->Stop(); 82 trace_collector_client_->Stop();
82 } 83 }
83 84
84 // TraceCollectorClient::Receiver: 85 // TraceCollectorClient::Receiver:
85 void OnTraceCollected(std::string trace_data) override { 86 void OnTraceCollected(std::string trace_data) override {
87 if (args_.write_output_file) {
88 // Write the trace file regardless of whether it can be parsed (or whether
89 // the measurements succeed), as it can be useful to debug failures.
90 base::File trace_file(
91 args_.output_file_path,
92 base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE);
93 trace_file.WriteAtCurrentPos(trace_data.data(), trace_data.size());
94 printf("wrote trace file at: %s\n",
95 args_.output_file_path.value().c_str());
96 }
97
86 // Parse trace events. 98 // Parse trace events.
87 std::vector<Event> events; 99 std::vector<Event> events;
88 if (!GetEvents(trace_data, &events)) { 100 if (!GetEvents(trace_data, &events)) {
89 LOG(ERROR) << "Failed to parse the trace data"; 101 LOG(ERROR) << "Failed to parse the trace data";
90 mojo::ApplicationImpl::Terminate(); 102 mojo::ApplicationImpl::Terminate();
91 return; 103 return;
92 } 104 }
93 105
94 // Calculate and print the results. 106 // Calculate and print the results.
95 bool succeeded = true; 107 bool succeeded = true;
(...skipping 29 matching lines...) Expand all
125 }; 137 };
126 } // namespace 138 } // namespace
127 } // namespace benchmark 139 } // namespace benchmark
128 140
129 MojoResult MojoMain(MojoHandle application_request) { 141 MojoResult MojoMain(MojoHandle application_request) {
130 mojo::ApplicationRunnerChromium runner(new benchmark::BenchmarkApp); 142 mojo::ApplicationRunnerChromium runner(new benchmark::BenchmarkApp);
131 auto ret = runner.Run(application_request); 143 auto ret = runner.Run(application_request);
132 fflush(nullptr); 144 fflush(nullptr);
133 return ret; 145 return ret;
134 } 146 }
OLDNEW
« no previous file with comments | « apps/benchmark/README.md ('k') | apps/benchmark/run_args.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698