OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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 | 4 |
5 #include "content/browser/browser_shutdown_profile_dumper.h" | 5 #include "content/browser/browser_shutdown_profile_dumper.h" |
6 | 6 |
7 #include "base/base_switches.h" | 7 #include "base/base_switches.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
10 #include "base/debug/trace_event_impl.h" | 10 #include "base/debug/trace_event_impl.h" |
11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
12 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/synchronization/waitable_event.h" | 14 #include "base/synchronization/waitable_event.h" |
15 #include "base/threading/thread.h" | 15 #include "base/threading/thread.h" |
16 #include "base/threading/thread_restrictions.h" | 16 #include "base/threading/thread_restrictions.h" |
17 #include "content/public/common/content_switches.h" | 17 #include "content/public/common/content_switches.h" |
18 | 18 |
19 namespace content { | 19 namespace content { |
20 | 20 |
| 21 static size_t GetTraceBufferPercentFull() { |
| 22 float unused; |
| 23 size_t num_events; |
| 24 base::debug::TraceLog::GetInstance()->GetBufferUsage(&unused, &num_events); |
| 25 return num_events; |
| 26 } |
| 27 |
21 BrowserShutdownProfileDumper::BrowserShutdownProfileDumper( | 28 BrowserShutdownProfileDumper::BrowserShutdownProfileDumper( |
22 const base::FilePath& dump_file_name) | 29 const base::FilePath& dump_file_name) |
23 : dump_file_name_(dump_file_name), | 30 : dump_file_name_(dump_file_name), |
24 blocks_(0), | 31 blocks_(0), |
25 dump_file_(NULL) { | 32 dump_file_(NULL) { |
26 } | 33 } |
27 | 34 |
28 BrowserShutdownProfileDumper::~BrowserShutdownProfileDumper() { | 35 BrowserShutdownProfileDumper::~BrowserShutdownProfileDumper() { |
29 WriteTracesToDisc(); | 36 WriteTracesToDisc(); |
30 } | 37 } |
31 | 38 |
32 void BrowserShutdownProfileDumper::WriteTracesToDisc() { | 39 void BrowserShutdownProfileDumper::WriteTracesToDisc() { |
33 // Note: I have seen a usage of 0.000xx% when dumping - which fits easily. | 40 // Note: I have seen a usage of 0.000xx% when dumping - which fits easily. |
34 // Since the tracer stops when the trace buffer is filled, we'd rather save | 41 // Since the tracer stops when the trace buffer is filled, we'd rather save |
35 // what we have than nothing since we might see from the amount of events | 42 // what we have than nothing since we might see from the amount of events |
36 // that caused the problem. | 43 // that caused the problem. |
37 DVLOG(1) << "Flushing shutdown traces to disc. The buffer is %" << | 44 DVLOG(1) << "Flushing shutdown traces to disc. The buffer is %" |
38 base::debug::TraceLog::GetInstance()->GetBufferPercentFull() << | 45 << GetTraceBufferPercentFull() << " full."; |
39 " full."; | |
40 DCHECK(!dump_file_); | 46 DCHECK(!dump_file_); |
41 dump_file_ = base::OpenFile(dump_file_name_, "w+"); | 47 dump_file_ = base::OpenFile(dump_file_name_, "w+"); |
42 if (!IsFileValid()) { | 48 if (!IsFileValid()) { |
43 LOG(ERROR) << "Failed to open performance trace file: " | 49 LOG(ERROR) << "Failed to open performance trace file: " |
44 << dump_file_name_.value(); | 50 << dump_file_name_.value(); |
45 return; | 51 return; |
46 } | 52 } |
47 WriteString("{\"traceEvents\":"); | 53 WriteString("{\"traceEvents\":"); |
48 WriteString("["); | 54 WriteString("["); |
49 | 55 |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 } | 139 } |
134 | 140 |
135 void BrowserShutdownProfileDumper::CloseFile() { | 141 void BrowserShutdownProfileDumper::CloseFile() { |
136 if (!dump_file_) | 142 if (!dump_file_) |
137 return; | 143 return; |
138 base::CloseFile(dump_file_); | 144 base::CloseFile(dump_file_); |
139 dump_file_ = NULL; | 145 dump_file_ = NULL; |
140 } | 146 } |
141 | 147 |
142 } // namespace content | 148 } // namespace content |
OLD | NEW |