OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/json/string_escape.h" | 9 #include "base/json/string_escape.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 base::Bind(&FileTraceDataSink::CloseOnFileThread, this)); | 62 base::Bind(&FileTraceDataSink::CloseOnFileThread, this)); |
63 } | 63 } |
64 | 64 |
65 private: | 65 private: |
66 virtual ~FileTraceDataSink() { DCHECK(file_ == NULL); } | 66 virtual ~FileTraceDataSink() { DCHECK(file_ == NULL); } |
67 | 67 |
68 void AddTraceChunkOnFileThread( | 68 void AddTraceChunkOnFileThread( |
69 const scoped_refptr<base::RefCountedString> chunk) { | 69 const scoped_refptr<base::RefCountedString> chunk) { |
70 if (!OpenFileIfNeededOnFileThread()) | 70 if (!OpenFileIfNeededOnFileThread()) |
71 return; | 71 return; |
72 fwrite(chunk->data().c_str(), strlen(chunk->data().c_str()), 1, file_); | 72 size_t written = fwrite(chunk->data().c_str(), |
| 73 strlen(chunk->data().c_str()), 1, file_); |
| 74 DCHECK_EQ(1u, written); |
73 } | 75 } |
74 | 76 |
75 bool OpenFileIfNeededOnFileThread() { | 77 bool OpenFileIfNeededOnFileThread() { |
76 if (file_ != NULL) | 78 if (file_ != NULL) |
77 return true; | 79 return true; |
78 file_ = base::OpenFile(file_path_, "w"); | 80 file_ = base::OpenFile(file_path_, "w"); |
79 if (file_ == NULL) { | 81 if (file_ == NULL) { |
80 LOG(ERROR) << "Failed to open " << file_path_.value(); | 82 LOG(ERROR) << "Failed to open " << file_path_.value(); |
81 return false; | 83 return false; |
82 } | 84 } |
83 const char preamble[] = "{\"traceEvents\": ["; | 85 const char preamble[] = "{\"traceEvents\": ["; |
84 fwrite(preamble, strlen(preamble), 1, file_); | 86 size_t written = fwrite(preamble, strlen(preamble), 1, file_); |
| 87 DCHECK_EQ(1u, written); |
85 return true; | 88 return true; |
86 } | 89 } |
87 | 90 |
88 void CloseOnFileThread() { | 91 void CloseOnFileThread() { |
89 if (OpenFileIfNeededOnFileThread()) { | 92 if (OpenFileIfNeededOnFileThread()) { |
90 fputc(']', file_); | 93 fputc(']', file_); |
91 if (!system_trace_.empty()) { | 94 if (!system_trace_.empty()) { |
92 const char systemTraceEvents[] = ",\"systemTraceEvents\": "; | 95 const char systemTraceEvents[] = ",\"systemTraceEvents\": "; |
93 fwrite(systemTraceEvents, strlen(systemTraceEvents), 1, file_); | 96 size_t written = fwrite(systemTraceEvents, strlen(systemTraceEvents), |
94 fwrite(system_trace_.c_str(), strlen(system_trace_.c_str()), 1, file_); | 97 1, file_); |
| 98 DCHECK_EQ(1u, written); |
| 99 written = fwrite(system_trace_.c_str(), |
| 100 strlen(system_trace_.c_str()), 1, file_); |
| 101 DCHECK_EQ(1u, written); |
95 } | 102 } |
96 fputc('}', file_); | 103 fputc('}', file_); |
97 base::CloseFile(file_); | 104 base::CloseFile(file_); |
98 file_ = NULL; | 105 file_ = NULL; |
99 } | 106 } |
100 BrowserThread::PostTask( | 107 BrowserThread::PostTask( |
101 BrowserThread::UI, | 108 BrowserThread::UI, |
102 FROM_HERE, | 109 FROM_HERE, |
103 base::Bind(&FileTraceDataSink::FinalizeOnUIThread, this)); | 110 base::Bind(&FileTraceDataSink::FinalizeOnUIThread, this)); |
104 } | 111 } |
(...skipping 766 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
871 is_monitoring_ = is_monitoring; | 878 is_monitoring_ = is_monitoring; |
872 #if !defined(OS_ANDROID) | 879 #if !defined(OS_ANDROID) |
873 for (std::set<TracingUI*>::iterator it = tracing_uis_.begin(); | 880 for (std::set<TracingUI*>::iterator it = tracing_uis_.begin(); |
874 it != tracing_uis_.end(); it++) { | 881 it != tracing_uis_.end(); it++) { |
875 (*it)->OnMonitoringStateChanged(is_monitoring); | 882 (*it)->OnMonitoringStateChanged(is_monitoring); |
876 } | 883 } |
877 #endif | 884 #endif |
878 } | 885 } |
879 | 886 |
880 } // namespace content | 887 } // namespace content |
OLD | NEW |