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" |
(...skipping 10 matching lines...) Expand all Loading... |
21 using tracked_objects::LocationSnapshot; | 21 using tracked_objects::LocationSnapshot; |
22 using tracked_objects::ParentChildPairSnapshot; | 22 using tracked_objects::ParentChildPairSnapshot; |
23 using tracked_objects::TaskSnapshot; | 23 using tracked_objects::TaskSnapshot; |
24 using tracked_objects::ProcessDataSnapshot; | 24 using tracked_objects::ProcessDataSnapshot; |
25 | 25 |
26 namespace { | 26 namespace { |
27 | 27 |
28 // Re-serializes the |location| into |dictionary|. | 28 // Re-serializes the |location| into |dictionary|. |
29 void LocationSnapshotToValue(const LocationSnapshot& location, | 29 void LocationSnapshotToValue(const LocationSnapshot& location, |
30 base::DictionaryValue* dictionary) { | 30 base::DictionaryValue* dictionary) { |
31 dictionary->Set("file_name", | 31 dictionary->Set("file_name", new base::StringValue(location.file_name)); |
32 base::Value::CreateStringValue(location.file_name)); | |
33 // Note: This function name is not escaped, and templates have less-than | 32 // Note: This function name is not escaped, and templates have less-than |
34 // characters, which means this is not suitable for display as HTML unless | 33 // characters, which means this is not suitable for display as HTML unless |
35 // properly escaped. | 34 // properly escaped. |
36 dictionary->Set("function_name", | 35 dictionary->Set("function_name", |
37 base::Value::CreateStringValue(location.function_name)); | 36 new base::StringValue(location.function_name)); |
38 dictionary->Set("line_number", | 37 dictionary->Set("line_number", |
39 base::Value::CreateIntegerValue(location.line_number)); | 38 base::Value::CreateIntegerValue(location.line_number)); |
40 } | 39 } |
41 | 40 |
42 // Re-serializes the |birth| into |dictionary|. Prepends the |prefix| to the | 41 // Re-serializes the |birth| into |dictionary|. Prepends the |prefix| to the |
43 // "thread" and "location" key names in the dictionary. | 42 // "thread" and "location" key names in the dictionary. |
44 void BirthOnThreadSnapshotToValue(const BirthOnThreadSnapshot& birth, | 43 void BirthOnThreadSnapshotToValue(const BirthOnThreadSnapshot& birth, |
45 const std::string& prefix, | 44 const std::string& prefix, |
46 base::DictionaryValue* dictionary) { | 45 base::DictionaryValue* dictionary) { |
47 DCHECK(!prefix.empty()); | 46 DCHECK(!prefix.empty()); |
48 | 47 |
49 scoped_ptr<base::DictionaryValue> location_value(new base::DictionaryValue); | 48 scoped_ptr<base::DictionaryValue> location_value(new base::DictionaryValue); |
50 LocationSnapshotToValue(birth.location, location_value.get()); | 49 LocationSnapshotToValue(birth.location, location_value.get()); |
51 dictionary->Set(prefix + "_location", location_value.release()); | 50 dictionary->Set(prefix + "_location", location_value.release()); |
52 | 51 |
53 dictionary->Set(prefix + "_thread", | 52 dictionary->Set(prefix + "_thread", new base::StringValue(birth.thread_name)); |
54 base::Value::CreateStringValue(birth.thread_name)); | |
55 } | 53 } |
56 | 54 |
57 // Re-serializes the |death_data| into |dictionary|. | 55 // Re-serializes the |death_data| into |dictionary|. |
58 void DeathDataSnapshotToValue(const DeathDataSnapshot& death_data, | 56 void DeathDataSnapshotToValue(const DeathDataSnapshot& death_data, |
59 base::DictionaryValue* dictionary) { | 57 base::DictionaryValue* dictionary) { |
60 dictionary->Set("count", | 58 dictionary->Set("count", |
61 base::Value::CreateIntegerValue(death_data.count)); | 59 base::Value::CreateIntegerValue(death_data.count)); |
62 dictionary->Set("run_ms", | 60 dictionary->Set("run_ms", |
63 base::Value::CreateIntegerValue(death_data.run_duration_sum)); | 61 base::Value::CreateIntegerValue(death_data.run_duration_sum)); |
64 dictionary->Set("run_ms_max", | 62 dictionary->Set("run_ms_max", |
(...skipping 16 matching lines...) Expand all Loading... |
81 // Re-serializes the |snapshot| into |dictionary|. | 79 // Re-serializes the |snapshot| into |dictionary|. |
82 void TaskSnapshotToValue(const TaskSnapshot& snapshot, | 80 void TaskSnapshotToValue(const TaskSnapshot& snapshot, |
83 base::DictionaryValue* dictionary) { | 81 base::DictionaryValue* dictionary) { |
84 BirthOnThreadSnapshotToValue(snapshot.birth, "birth", dictionary); | 82 BirthOnThreadSnapshotToValue(snapshot.birth, "birth", dictionary); |
85 | 83 |
86 scoped_ptr<base::DictionaryValue> death_data(new base::DictionaryValue); | 84 scoped_ptr<base::DictionaryValue> death_data(new base::DictionaryValue); |
87 DeathDataSnapshotToValue(snapshot.death_data, death_data.get()); | 85 DeathDataSnapshotToValue(snapshot.death_data, death_data.get()); |
88 dictionary->Set("death_data", death_data.release()); | 86 dictionary->Set("death_data", death_data.release()); |
89 | 87 |
90 dictionary->Set("death_thread", | 88 dictionary->Set("death_thread", |
91 base::Value::CreateStringValue(snapshot.death_thread_name)); | 89 new base::StringValue(snapshot.death_thread_name)); |
92 | |
93 } | 90 } |
94 | 91 |
95 } // anonymous namespace | 92 } // anonymous namespace |
96 | 93 |
97 namespace task_profiler { | 94 namespace task_profiler { |
98 | 95 |
99 // static | 96 // static |
100 void TaskProfilerDataSerializer::ToValue( | 97 void TaskProfilerDataSerializer::ToValue( |
101 const ProcessDataSnapshot& process_data, | 98 const ProcessDataSnapshot& process_data, |
102 int process_type, | 99 int process_type, |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 snapshot_list->Append(shutdown_snapshot); | 158 snapshot_list->Append(shutdown_snapshot); |
162 root->Set("snapshots", snapshot_list); | 159 root->Set("snapshots", snapshot_list); |
163 | 160 |
164 serializer.Serialize(*root); | 161 serializer.Serialize(*root); |
165 int data_size = static_cast<int>(output.size()); | 162 int data_size = static_cast<int>(output.size()); |
166 | 163 |
167 return data_size == base::WriteFile(path, output.data(), data_size); | 164 return data_size == base::WriteFile(path, output.data(), data_size); |
168 } | 165 } |
169 | 166 |
170 } // namespace task_profiler | 167 } // namespace task_profiler |
OLD | NEW |