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_path.h" | 7 #include "base/file_path.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/json/json_string_value_serializer.h" | 9 #include "base/json/json_string_value_serializer.h" |
10 #include "base/time.h" | 10 #include "base/time.h" |
11 #include "base/tracked_objects.h" | 11 #include "base/tracked_objects.h" |
12 #include "content/public/common/content_client.h" | 12 #include "content/public/common/content_client.h" |
| 13 #include "content/public/common/process_type.h" |
| 14 #include "content/public/common/serialized_profiler_data.h" |
13 #include "googleurl/src/gurl.h" | 15 #include "googleurl/src/gurl.h" |
14 | 16 |
15 namespace task_profiler { | 17 namespace task_profiler { |
16 | 18 |
17 bool TaskProfilerDataSerializer::WriteToFile(const FilePath &path) { | 19 bool TaskProfilerDataSerializer::WriteToFile(const FilePath& path) { |
18 std::string output; | 20 std::string output; |
19 JSONStringValueSerializer serializer(&output); | 21 JSONStringValueSerializer serializer(&output); |
20 serializer.set_pretty_print(true); | 22 serializer.set_pretty_print(true); |
21 | 23 |
22 scoped_ptr<base::DictionaryValue> root(new DictionaryValue()); | 24 scoped_ptr<base::DictionaryValue> root(new DictionaryValue()); |
23 | 25 |
24 base::ListValue* snapshot_list = new ListValue(); | 26 base::ListValue* snapshot_list = new ListValue(); |
25 base::DictionaryValue* shutdown_snapshot = new DictionaryValue(); | 27 base::DictionaryValue* shutdown_snapshot = new DictionaryValue(); |
26 base::ListValue* per_process_data = new ListValue(); | 28 base::ListValue* per_process_data = new ListValue(); |
27 | 29 |
28 root->SetInteger("version", 1); | 30 root->SetInteger("version", 1); |
29 root->SetString("userAgent", content::GetUserAgent(GURL())); | 31 root->SetString("userAgent", content::GetUserAgent(GURL())); |
30 | 32 |
31 // TODO(ramant): Collect data from other processes, then add that data to the | 33 // TODO(ramant): Collect data from other processes, then add that data to the |
32 // 'per_process_data' array here. | 34 // 'per_process_data' array here. Should leverage the TrackingSynchronizer |
33 base::DictionaryValue* this_process_data = | 35 // class to implement this. |
34 tracked_objects::ThreadData::ToValue(false); | 36 content::SerializedProfilerData this_process_data( |
35 per_process_data->Append(this_process_data); | 37 content::PROCESS_TYPE_BROWSER); |
| 38 tracked_objects::ThreadData::ToSerializedProcessData(false, |
| 39 &this_process_data); |
| 40 scoped_ptr<base::DictionaryValue> this_process_data_value( |
| 41 new base::DictionaryValue); |
| 42 this_process_data.ToValue(this_process_data_value.get()); |
| 43 per_process_data->Append(this_process_data_value.release()); |
36 | 44 |
37 shutdown_snapshot->SetInteger( | 45 shutdown_snapshot->SetInteger( |
38 "timestamp", | 46 "timestamp", |
39 (base::Time::Now() - base::Time::UnixEpoch()).InSeconds()); | 47 (base::Time::Now() - base::Time::UnixEpoch()).InSeconds()); |
40 shutdown_snapshot->Set("data", per_process_data); | 48 shutdown_snapshot->Set("data", per_process_data); |
41 snapshot_list->Append(shutdown_snapshot); | 49 snapshot_list->Append(shutdown_snapshot); |
42 root->Set("snapshots", snapshot_list); | 50 root->Set("snapshots", snapshot_list); |
43 | 51 |
44 serializer.Serialize(*root); | 52 serializer.Serialize(*root); |
45 int data_size = static_cast<int>(output.size()); | 53 int data_size = static_cast<int>(output.size()); |
46 | 54 |
47 return data_size == file_util::WriteFile(path, output.data(), data_size); | 55 return data_size == file_util::WriteFile(path, output.data(), data_size); |
48 } | 56 } |
49 | 57 |
50 } // namespace task_profiler | 58 } // namespace task_profiler |
OLD | NEW |