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" |
(...skipping 28 matching lines...) Expand all Loading... |
39 LOG(ERROR) << "Failed to open performance trace file: " << | 39 LOG(ERROR) << "Failed to open performance trace file: " << |
40 file_name.value(); | 40 file_name.value(); |
41 return; | 41 return; |
42 } | 42 } |
43 WriteString("{\"traceEvents\":"); | 43 WriteString("{\"traceEvents\":"); |
44 WriteString("["); | 44 WriteString("["); |
45 | 45 |
46 base::debug::TraceLog::GetInstance()->Flush( | 46 base::debug::TraceLog::GetInstance()->Flush( |
47 base::Bind(&BrowserShutdownProfileDumper::WriteTraceDataCollected, | 47 base::Bind(&BrowserShutdownProfileDumper::WriteTraceDataCollected, |
48 base::Unretained(this))); | 48 base::Unretained(this))); |
49 | |
50 WriteString("]"); | |
51 WriteString("}"); | |
52 CloseFile(); | |
53 } | 49 } |
54 | 50 |
55 base::FilePath BrowserShutdownProfileDumper::GetFileName() { | 51 base::FilePath BrowserShutdownProfileDumper::GetFileName() { |
56 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 52 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
57 base::FilePath trace_file = | 53 base::FilePath trace_file = |
58 command_line.GetSwitchValuePath(switches::kTraceShutdownFile); | 54 command_line.GetSwitchValuePath(switches::kTraceShutdownFile); |
59 | 55 |
60 if (!trace_file.empty()) | 56 if (!trace_file.empty()) |
61 return trace_file; | 57 return trace_file; |
62 | 58 |
63 // Default to saving the startup trace into the current dir. | 59 // Default to saving the startup trace into the current dir. |
64 return base::FilePath().AppendASCII("chrometrace.log"); | 60 return base::FilePath().AppendASCII("chrometrace.log"); |
65 } | 61 } |
66 | 62 |
67 void BrowserShutdownProfileDumper::WriteTraceDataCollected( | 63 void BrowserShutdownProfileDumper::WriteTraceDataCollected( |
68 const scoped_refptr<base::RefCountedString>& events_str) { | 64 const scoped_refptr<base::RefCountedString>& events_str, |
| 65 bool has_more_events) { |
69 if (!IsFileValid()) | 66 if (!IsFileValid()) |
70 return; | 67 return; |
71 if (blocks_) { | 68 if (blocks_) { |
72 // Blocks are not comma separated. Beginning with the second block we | 69 // Blocks are not comma separated. Beginning with the second block we |
73 // start therefore to add one in front of the previous block. | 70 // start therefore to add one in front of the previous block. |
74 WriteString(","); | 71 WriteString(","); |
75 } | 72 } |
76 ++blocks_; | 73 ++blocks_; |
77 WriteString(events_str->data()); | 74 WriteString(events_str->data()); |
| 75 |
| 76 if (!has_more_events) { |
| 77 WriteString("]"); |
| 78 WriteString("}"); |
| 79 CloseFile(); |
| 80 } |
78 } | 81 } |
79 | 82 |
80 bool BrowserShutdownProfileDumper::IsFileValid() { | 83 bool BrowserShutdownProfileDumper::IsFileValid() { |
81 return dump_file_ && (ferror(dump_file_) == 0); | 84 return dump_file_ && (ferror(dump_file_) == 0); |
82 } | 85 } |
83 | 86 |
84 void BrowserShutdownProfileDumper::WriteString(const std::string& string) { | 87 void BrowserShutdownProfileDumper::WriteString(const std::string& string) { |
85 WriteChars(string.data(), string.size()); | 88 WriteChars(string.data(), string.size()); |
86 } | 89 } |
87 | 90 |
(...skipping 10 matching lines...) Expand all Loading... |
98 } | 101 } |
99 | 102 |
100 void BrowserShutdownProfileDumper::CloseFile() { | 103 void BrowserShutdownProfileDumper::CloseFile() { |
101 if (!dump_file_) | 104 if (!dump_file_) |
102 return; | 105 return; |
103 file_util::CloseFile(dump_file_); | 106 file_util::CloseFile(dump_file_); |
104 dump_file_ = NULL; | 107 dump_file_ = NULL; |
105 } | 108 } |
106 | 109 |
107 } // namespace content | 110 } // namespace content |
OLD | NEW |