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 #include "content/browser/tracing/tracing_controller_impl.h" | 4 #include "content/browser/tracing/tracing_controller_impl.h" |
| 5 | 5 |
| 6 #include "base/bind.h" | 6 #include "base/bind.h" |
| 7 #include "base/files/file_util.h" | 7 #include "base/files/file_util.h" |
| 8 #include "content/public/browser/browser_thread.h" | 8 #include "content/public/browser/browser_thread.h" |
| 9 #include "third_party/zlib/zlib.h" | 9 #include "third_party/zlib/zlib.h" |
| 10 | 10 |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 121 void AddTraceChunkAndPassToEndpoint(const std::string& chunk) { | 121 void AddTraceChunkAndPassToEndpoint(const std::string& chunk) { |
| 122 trace_ += chunk; | 122 trace_ += chunk; |
| 123 | 123 |
| 124 endpoint_->ReceiveTraceChunk(chunk); | 124 endpoint_->ReceiveTraceChunk(chunk); |
| 125 } | 125 } |
| 126 | 126 |
| 127 void SetSystemTrace(const std::string& data) override { | 127 void SetSystemTrace(const std::string& data) override { |
| 128 system_trace_ = data; | 128 system_trace_ = data; |
| 129 } | 129 } |
| 130 | 130 |
| 131 void SetMetadata(const std::string& data) override { | |
| 132 metadata_ = data; | |
| 133 } | |
| 134 | |
| 131 void Close() override { | 135 void Close() override { |
| 132 AddTraceChunkAndPassToEndpoint("]"); | 136 AddTraceChunkAndPassToEndpoint("]"); |
| 133 if (!system_trace_.empty()) | 137 if (!system_trace_.empty()) |
| 134 AddTraceChunkAndPassToEndpoint(",\"systemTraceEvents\": " + | 138 AddTraceChunkAndPassToEndpoint(",\"systemTraceEvents\": " + |
| 135 system_trace_); | 139 system_trace_); |
| 140 if (!metadata_.empty()) | |
| 141 AddTraceChunkAndPassToEndpoint(",\"metadata\": " + metadata_); | |
|
dsinclair
2015/06/12 19:38:51
Does this produce a valid file? This works above f
shatch
2015/06/12 20:53:48
It's actually a dict, so the contents the results
| |
| 136 AddTraceChunkAndPassToEndpoint("}"); | 142 AddTraceChunkAndPassToEndpoint("}"); |
| 137 | 143 |
| 138 endpoint_->ReceiveTraceFinalContents(trace_); | 144 endpoint_->ReceiveTraceFinalContents(trace_); |
| 139 } | 145 } |
| 140 | 146 |
| 141 private: | 147 private: |
| 142 ~StringTraceDataSink() override {} | 148 ~StringTraceDataSink() override {} |
| 143 | 149 |
| 144 scoped_refptr<TracingController::TraceDataEndpoint> endpoint_; | 150 scoped_refptr<TracingController::TraceDataEndpoint> endpoint_; |
| 145 std::string trace_; | 151 std::string trace_; |
| 146 std::string system_trace_; | 152 std::string system_trace_; |
| 153 std::string metadata_; | |
| 147 | 154 |
| 148 DISALLOW_COPY_AND_ASSIGN(StringTraceDataSink); | 155 DISALLOW_COPY_AND_ASSIGN(StringTraceDataSink); |
| 149 }; | 156 }; |
| 150 | 157 |
| 151 class CompressedStringTraceDataSink : public TracingController::TraceDataSink { | 158 class CompressedStringTraceDataSink : public TracingController::TraceDataSink { |
| 152 public: | 159 public: |
| 153 explicit CompressedStringTraceDataSink( | 160 explicit CompressedStringTraceDataSink( |
| 154 scoped_refptr<TracingController::TraceDataEndpoint> endpoint) | 161 scoped_refptr<TracingController::TraceDataEndpoint> endpoint) |
| 155 : endpoint_(endpoint), already_tried_open_(false) {} | 162 : endpoint_(endpoint), already_tried_open_(false) {} |
| 156 | 163 |
| 157 void AddTraceChunk(const std::string& chunk) override { | 164 void AddTraceChunk(const std::string& chunk) override { |
| 158 std::string tmp = chunk; | 165 std::string tmp = chunk; |
| 159 scoped_refptr<base::RefCountedString> chunk_ptr = | 166 scoped_refptr<base::RefCountedString> chunk_ptr = |
| 160 base::RefCountedString::TakeString(&tmp); | 167 base::RefCountedString::TakeString(&tmp); |
| 161 BrowserThread::PostTask( | 168 BrowserThread::PostTask( |
| 162 BrowserThread::FILE, FROM_HERE, | 169 BrowserThread::FILE, FROM_HERE, |
| 163 base::Bind(&CompressedStringTraceDataSink::AddTraceChunkOnFileThread, | 170 base::Bind(&CompressedStringTraceDataSink::AddTraceChunkOnFileThread, |
| 164 this, chunk_ptr)); | 171 this, chunk_ptr)); |
| 165 } | 172 } |
| 166 | 173 |
| 167 void SetSystemTrace(const std::string& data) override { | 174 void SetSystemTrace(const std::string& data) override { |
| 168 system_trace_ = data; | 175 system_trace_ = data; |
| 169 } | 176 } |
| 170 | 177 |
| 178 void SetMetadata(const std::string& data) override { | |
| 179 metadata_ = data; | |
| 180 } | |
| 181 | |
| 171 void Close() override { | 182 void Close() override { |
| 172 BrowserThread::PostTask( | 183 BrowserThread::PostTask( |
| 173 BrowserThread::FILE, FROM_HERE, | 184 BrowserThread::FILE, FROM_HERE, |
| 174 base::Bind(&CompressedStringTraceDataSink::CloseOnFileThread, this)); | 185 base::Bind(&CompressedStringTraceDataSink::CloseOnFileThread, this)); |
| 175 } | 186 } |
| 176 | 187 |
| 177 private: | 188 private: |
| 178 ~CompressedStringTraceDataSink() override {} | 189 ~CompressedStringTraceDataSink() override {} |
| 179 | 190 |
| 180 bool OpenZStreamOnFileThread() { | 191 bool OpenZStreamOnFileThread() { |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 248 return; | 259 return; |
| 249 | 260 |
| 250 if (compressed_trace_data_.empty()) | 261 if (compressed_trace_data_.empty()) |
| 251 AddTraceChunkAndCompressOnFileThread("{\"traceEvents\":[", false); | 262 AddTraceChunkAndCompressOnFileThread("{\"traceEvents\":[", false); |
| 252 | 263 |
| 253 AddTraceChunkAndCompressOnFileThread("]", false); | 264 AddTraceChunkAndCompressOnFileThread("]", false); |
| 254 if (!system_trace_.empty()) { | 265 if (!system_trace_.empty()) { |
| 255 AddTraceChunkAndCompressOnFileThread( | 266 AddTraceChunkAndCompressOnFileThread( |
| 256 ",\"systemTraceEvents\": " + system_trace_, false); | 267 ",\"systemTraceEvents\": " + system_trace_, false); |
| 257 } | 268 } |
| 269 if (!metadata_.empty()) | |
|
oystein (OOO til 10th of July)
2015/06/12 19:29:16
nit: braces
shatch
2015/06/12 20:53:48
Done.
| |
| 270 AddTraceChunkAndCompressOnFileThread(",\"metadata\": " + metadata_, | |
| 271 false); | |
| 258 AddTraceChunkAndCompressOnFileThread("}", true); | 272 AddTraceChunkAndCompressOnFileThread("}", true); |
| 259 | 273 |
| 260 deflateEnd(stream_.get()); | 274 deflateEnd(stream_.get()); |
| 261 stream_.reset(); | 275 stream_.reset(); |
| 262 | 276 |
| 263 endpoint_->ReceiveTraceFinalContents(compressed_trace_data_); | 277 endpoint_->ReceiveTraceFinalContents(compressed_trace_data_); |
| 264 } | 278 } |
| 265 | 279 |
| 266 scoped_refptr<TracingController::TraceDataEndpoint> endpoint_; | 280 scoped_refptr<TracingController::TraceDataEndpoint> endpoint_; |
| 267 scoped_ptr<z_stream> stream_; | 281 scoped_ptr<z_stream> stream_; |
| 268 bool already_tried_open_; | 282 bool already_tried_open_; |
| 269 std::string compressed_trace_data_; | 283 std::string compressed_trace_data_; |
| 270 std::string system_trace_; | 284 std::string system_trace_; |
| 285 std::string metadata_; | |
| 271 | 286 |
| 272 DISALLOW_COPY_AND_ASSIGN(CompressedStringTraceDataSink); | 287 DISALLOW_COPY_AND_ASSIGN(CompressedStringTraceDataSink); |
| 273 }; | 288 }; |
| 274 | 289 |
| 275 } // namespace | 290 } // namespace |
| 276 | 291 |
| 277 scoped_refptr<TracingController::TraceDataSink> | 292 scoped_refptr<TracingController::TraceDataSink> |
| 278 TracingController::CreateStringSink( | 293 TracingController::CreateStringSink( |
| 279 const base::Callback<void(base::RefCountedString*)>& callback) { | 294 const base::Callback<void(base::RefCountedString*)>& callback) { |
| 280 return new StringTraceDataSink(new StringTraceDataEndpoint(callback)); | 295 return new StringTraceDataSink(new StringTraceDataEndpoint(callback)); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 293 CreateFileEndpoint(file_path, callback)); | 308 CreateFileEndpoint(file_path, callback)); |
| 294 } | 309 } |
| 295 | 310 |
| 296 scoped_refptr<TracingController::TraceDataEndpoint> | 311 scoped_refptr<TracingController::TraceDataEndpoint> |
| 297 TracingController::CreateFileEndpoint(const base::FilePath& file_path, | 312 TracingController::CreateFileEndpoint(const base::FilePath& file_path, |
| 298 const base::Closure& callback) { | 313 const base::Closure& callback) { |
| 299 return new FileTraceDataEndpoint(file_path, callback); | 314 return new FileTraceDataEndpoint(file_path, callback); |
| 300 } | 315 } |
| 301 | 316 |
| 302 } // namespace content | 317 } // namespace content |
| OLD | NEW |