OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/task_profiler/task_profiler_data_serializer.h" | 5 #include "chrome/browser/task_profiler/task_profiler_data_serializer.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/json/json_string_value_serializer.h" | 9 #include "base/json/json_string_value_serializer.h" |
10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
11 #include "base/tracked_objects.h" | 11 #include "base/tracked_objects.h" |
12 #include "content/public/common/content_client.h" | 12 #include "chrome/common/chrome_content_client.h" |
13 #include "content/public/common/process_type.h" | 13 #include "content/public/common/process_type.h" |
14 #include "url/gurl.h" | 14 #include "url/gurl.h" |
15 | 15 |
16 using base::DictionaryValue; | 16 using base::DictionaryValue; |
17 using base::ListValue; | 17 using base::ListValue; |
18 using base::Value; | 18 using base::Value; |
19 using tracked_objects::BirthOnThreadSnapshot; | 19 using tracked_objects::BirthOnThreadSnapshot; |
20 using tracked_objects::DeathDataSnapshot; | 20 using tracked_objects::DeathDataSnapshot; |
21 using tracked_objects::LocationSnapshot; | 21 using tracked_objects::LocationSnapshot; |
22 using tracked_objects::ParentChildPairSnapshot; | 22 using tracked_objects::ParentChildPairSnapshot; |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 JSONStringValueSerializer serializer(&output); | 133 JSONStringValueSerializer serializer(&output); |
134 serializer.set_pretty_print(true); | 134 serializer.set_pretty_print(true); |
135 | 135 |
136 scoped_ptr<base::DictionaryValue> root(new base::DictionaryValue()); | 136 scoped_ptr<base::DictionaryValue> root(new base::DictionaryValue()); |
137 | 137 |
138 base::ListValue* snapshot_list = new base::ListValue(); | 138 base::ListValue* snapshot_list = new base::ListValue(); |
139 base::DictionaryValue* shutdown_snapshot = new base::DictionaryValue(); | 139 base::DictionaryValue* shutdown_snapshot = new base::DictionaryValue(); |
140 base::ListValue* per_process_data = new base::ListValue(); | 140 base::ListValue* per_process_data = new base::ListValue(); |
141 | 141 |
142 root->SetInteger("version", 1); | 142 root->SetInteger("version", 1); |
143 root->SetString("userAgent", content::GetUserAgent(GURL())); | 143 root->SetString("userAgent", GetUserAgent()); |
144 | 144 |
145 // TODO(ramant): Collect data from other processes, then add that data to the | 145 // TODO(ramant): Collect data from other processes, then add that data to the |
146 // 'per_process_data' array here. Should leverage the TrackingSynchronizer | 146 // 'per_process_data' array here. Should leverage the TrackingSynchronizer |
147 // class to implement this. | 147 // class to implement this. |
148 ProcessDataSnapshot this_process_data; | 148 ProcessDataSnapshot this_process_data; |
149 tracked_objects::ThreadData::Snapshot(false, &this_process_data); | 149 tracked_objects::ThreadData::Snapshot(false, &this_process_data); |
150 scoped_ptr<base::DictionaryValue> this_process_data_json( | 150 scoped_ptr<base::DictionaryValue> this_process_data_json( |
151 new base::DictionaryValue); | 151 new base::DictionaryValue); |
152 TaskProfilerDataSerializer::ToValue(this_process_data, | 152 TaskProfilerDataSerializer::ToValue(this_process_data, |
153 content::PROCESS_TYPE_BROWSER, | 153 content::PROCESS_TYPE_BROWSER, |
154 this_process_data_json.get()); | 154 this_process_data_json.get()); |
155 per_process_data->Append(this_process_data_json.release()); | 155 per_process_data->Append(this_process_data_json.release()); |
156 | 156 |
157 shutdown_snapshot->SetInteger( | 157 shutdown_snapshot->SetInteger( |
158 "timestamp", | 158 "timestamp", |
159 (base::Time::Now() - base::Time::UnixEpoch()).InSeconds()); | 159 (base::Time::Now() - base::Time::UnixEpoch()).InSeconds()); |
160 shutdown_snapshot->Set("data", per_process_data); | 160 shutdown_snapshot->Set("data", per_process_data); |
161 snapshot_list->Append(shutdown_snapshot); | 161 snapshot_list->Append(shutdown_snapshot); |
162 root->Set("snapshots", snapshot_list); | 162 root->Set("snapshots", snapshot_list); |
163 | 163 |
164 serializer.Serialize(*root); | 164 serializer.Serialize(*root); |
165 int data_size = static_cast<int>(output.size()); | 165 int data_size = static_cast<int>(output.size()); |
166 | 166 |
167 return data_size == base::WriteFile(path, output.data(), data_size); | 167 return data_size == base::WriteFile(path, output.data(), data_size); |
168 } | 168 } |
169 | 169 |
170 } // namespace task_profiler | 170 } // namespace task_profiler |
OLD | NEW |