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", new base::StringValue(location.file_name)); | 31 dictionary->SetString("file_name", location.file_name); |
32 // 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 |
33 // 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 |
34 // properly escaped. | 34 // properly escaped. |
35 dictionary->Set("function_name", | 35 dictionary->SetString("function_name", location.function_name); |
36 new base::StringValue(location.function_name)); | 36 dictionary->SetInteger("line_number", location.line_number); |
37 dictionary->Set("line_number", | |
38 base::Value::CreateIntegerValue(location.line_number)); | |
39 } | 37 } |
40 | 38 |
41 // Re-serializes the |birth| into |dictionary|. Prepends the |prefix| to the | 39 // Re-serializes the |birth| into |dictionary|. Prepends the |prefix| to the |
42 // "thread" and "location" key names in the dictionary. | 40 // "thread" and "location" key names in the dictionary. |
43 void BirthOnThreadSnapshotToValue(const BirthOnThreadSnapshot& birth, | 41 void BirthOnThreadSnapshotToValue(const BirthOnThreadSnapshot& birth, |
44 const std::string& prefix, | 42 const std::string& prefix, |
45 base::DictionaryValue* dictionary) { | 43 base::DictionaryValue* dictionary) { |
46 DCHECK(!prefix.empty()); | 44 DCHECK(!prefix.empty()); |
47 | 45 |
48 scoped_ptr<base::DictionaryValue> location_value(new base::DictionaryValue); | 46 scoped_ptr<base::DictionaryValue> location_value(new base::DictionaryValue); |
49 LocationSnapshotToValue(birth.location, location_value.get()); | 47 LocationSnapshotToValue(birth.location, location_value.get()); |
50 dictionary->Set(prefix + "_location", location_value.release()); | 48 dictionary->Set(prefix + "_location", location_value.release()); |
51 | 49 |
52 dictionary->Set(prefix + "_thread", new base::StringValue(birth.thread_name)); | 50 dictionary->Set(prefix + "_thread", new base::StringValue(birth.thread_name)); |
53 } | 51 } |
54 | 52 |
55 // Re-serializes the |death_data| into |dictionary|. | 53 // Re-serializes the |death_data| into |dictionary|. |
56 void DeathDataSnapshotToValue(const DeathDataSnapshot& death_data, | 54 void DeathDataSnapshotToValue(const DeathDataSnapshot& death_data, |
57 base::DictionaryValue* dictionary) { | 55 base::DictionaryValue* dictionary) { |
58 dictionary->Set("count", | 56 dictionary->SetInteger("count", death_data.count); |
59 base::Value::CreateIntegerValue(death_data.count)); | 57 dictionary->SetInteger("run_ms", death_data.run_duration_sum); |
60 dictionary->Set("run_ms", | 58 dictionary->SetInteger("run_ms_max", death_data.run_duration_max); |
61 base::Value::CreateIntegerValue(death_data.run_duration_sum)); | 59 dictionary->SetInteger("run_ms_sample", death_data.run_duration_sample); |
62 dictionary->Set("run_ms_max", | 60 dictionary->SetInteger("queue_ms", death_data.queue_duration_sum); |
63 base::Value::CreateIntegerValue(death_data.run_duration_max)); | 61 dictionary->SetInteger("queue_ms_max", death_data.queue_duration_max); |
64 dictionary->Set("run_ms_sample", | 62 dictionary->SetInteger("queue_ms_sample", death_data.queue_duration_sample); |
65 base::Value::CreateIntegerValue( | |
66 death_data.run_duration_sample)); | |
67 dictionary->Set("queue_ms", | |
68 base::Value::CreateIntegerValue( | |
69 death_data.queue_duration_sum)); | |
70 dictionary->Set("queue_ms_max", | |
71 base::Value::CreateIntegerValue( | |
72 death_data.queue_duration_max)); | |
73 dictionary->Set("queue_ms_sample", | |
74 base::Value::CreateIntegerValue( | |
75 death_data.queue_duration_sample)); | |
76 | |
77 } | 63 } |
78 | 64 |
79 // Re-serializes the |snapshot| into |dictionary|. | 65 // Re-serializes the |snapshot| into |dictionary|. |
80 void TaskSnapshotToValue(const TaskSnapshot& snapshot, | 66 void TaskSnapshotToValue(const TaskSnapshot& snapshot, |
81 base::DictionaryValue* dictionary) { | 67 base::DictionaryValue* dictionary) { |
82 BirthOnThreadSnapshotToValue(snapshot.birth, "birth", dictionary); | 68 BirthOnThreadSnapshotToValue(snapshot.birth, "birth", dictionary); |
83 | 69 |
84 scoped_ptr<base::DictionaryValue> death_data(new base::DictionaryValue); | 70 scoped_ptr<base::DictionaryValue> death_data(new base::DictionaryValue); |
85 DeathDataSnapshotToValue(snapshot.death_data, death_data.get()); | 71 DeathDataSnapshotToValue(snapshot.death_data, death_data.get()); |
86 dictionary->Set("death_data", death_data.release()); | 72 dictionary->Set("death_data", death_data.release()); |
87 | 73 |
88 dictionary->Set("death_thread", | 74 dictionary->SetString("death_thread", snapshot.death_thread_name); |
89 new base::StringValue(snapshot.death_thread_name)); | |
90 } | 75 } |
91 | 76 |
92 } // anonymous namespace | 77 } // anonymous namespace |
93 | 78 |
94 namespace task_profiler { | 79 namespace task_profiler { |
95 | 80 |
96 // static | 81 // static |
97 void TaskProfilerDataSerializer::ToValue( | 82 void TaskProfilerDataSerializer::ToValue( |
98 const ProcessDataSnapshot& process_data, | 83 const ProcessDataSnapshot& process_data, |
99 int process_type, | 84 int process_type, |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 snapshot_list->Append(shutdown_snapshot); | 143 snapshot_list->Append(shutdown_snapshot); |
159 root->Set("snapshots", snapshot_list); | 144 root->Set("snapshots", snapshot_list); |
160 | 145 |
161 serializer.Serialize(*root); | 146 serializer.Serialize(*root); |
162 int data_size = static_cast<int>(output.size()); | 147 int data_size = static_cast<int>(output.size()); |
163 | 148 |
164 return data_size == base::WriteFile(path, output.data(), data_size); | 149 return data_size == base::WriteFile(path, output.data(), data_size); |
165 } | 150 } |
166 | 151 |
167 } // namespace task_profiler | 152 } // namespace task_profiler |
OLD | NEW |