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 <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
11 #include "base/files/file_util.h" | 11 #include "base/files/file_util.h" |
12 #include "base/json/json_string_value_serializer.h" | 12 #include "base/json/json_string_value_serializer.h" |
13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
14 #include "base/tracked_objects.h" | 14 #include "base/tracked_objects.h" |
| 15 #include "base/values.h" |
15 #include "chrome/common/chrome_content_client.h" | 16 #include "chrome/common/chrome_content_client.h" |
16 #include "components/nacl/common/nacl_process_type.h" | 17 #include "components/nacl/common/nacl_process_type.h" |
17 #include "content/public/common/process_type.h" | 18 #include "content/public/common/process_type.h" |
18 #include "url/gurl.h" | 19 #include "url/gurl.h" |
19 | 20 |
20 using base::DictionaryValue; | 21 using base::DictionaryValue; |
21 using base::ListValue; | 22 using base::ListValue; |
22 using base::Value; | 23 using base::Value; |
23 using tracked_objects::BirthOnThreadSnapshot; | 24 using tracked_objects::BirthOnThreadSnapshot; |
24 using tracked_objects::DeathDataSnapshot; | 25 using tracked_objects::DeathDataSnapshot; |
(...skipping 17 matching lines...) Expand all Loading... |
42 // Re-serializes the |birth| into |dictionary|. Prepends the |prefix| to the | 43 // Re-serializes the |birth| into |dictionary|. Prepends the |prefix| to the |
43 // "thread" and "location" key names in the dictionary. | 44 // "thread" and "location" key names in the dictionary. |
44 void BirthOnThreadSnapshotToValue(const BirthOnThreadSnapshot& birth, | 45 void BirthOnThreadSnapshotToValue(const BirthOnThreadSnapshot& birth, |
45 const std::string& prefix, | 46 const std::string& prefix, |
46 base::DictionaryValue* dictionary) { | 47 base::DictionaryValue* dictionary) { |
47 DCHECK(!prefix.empty()); | 48 DCHECK(!prefix.empty()); |
48 | 49 |
49 std::unique_ptr<base::DictionaryValue> location_value( | 50 std::unique_ptr<base::DictionaryValue> location_value( |
50 new base::DictionaryValue); | 51 new base::DictionaryValue); |
51 LocationSnapshotToValue(birth.location, location_value.get()); | 52 LocationSnapshotToValue(birth.location, location_value.get()); |
52 dictionary->Set(prefix + "_location", location_value.release()); | 53 dictionary->Set(prefix + "_location", std::move(location_value)); |
53 | 54 |
54 dictionary->Set(prefix + "_thread", | 55 dictionary->SetString(prefix + "_thread", birth.sanitized_thread_name); |
55 new base::Value(birth.sanitized_thread_name)); | |
56 } | 56 } |
57 | 57 |
58 // Re-serializes the |death_data| into |dictionary|. | 58 // Re-serializes the |death_data| into |dictionary|. |
59 void DeathDataSnapshotToValue(const DeathDataSnapshot& death_data, | 59 void DeathDataSnapshotToValue(const DeathDataSnapshot& death_data, |
60 base::DictionaryValue* dictionary) { | 60 base::DictionaryValue* dictionary) { |
61 dictionary->SetInteger("count", death_data.count); | 61 dictionary->SetInteger("count", death_data.count); |
62 dictionary->SetInteger("run_ms", death_data.run_duration_sum); | 62 dictionary->SetInteger("run_ms", death_data.run_duration_sum); |
63 dictionary->SetInteger("run_ms_max", death_data.run_duration_max); | 63 dictionary->SetInteger("run_ms_max", death_data.run_duration_max); |
64 dictionary->SetInteger("run_ms_sample", death_data.run_duration_sample); | 64 dictionary->SetInteger("run_ms_sample", death_data.run_duration_sample); |
65 dictionary->SetInteger("queue_ms", death_data.queue_duration_sum); | 65 dictionary->SetInteger("queue_ms", death_data.queue_duration_sum); |
(...skipping 11 matching lines...) Expand all Loading... |
77 dictionary->SetInteger("max_allocated_bytes", death_data.max_allocated_bytes); | 77 dictionary->SetInteger("max_allocated_bytes", death_data.max_allocated_bytes); |
78 } | 78 } |
79 | 79 |
80 // Re-serializes the |snapshot| into |dictionary|. | 80 // Re-serializes the |snapshot| into |dictionary|. |
81 void TaskSnapshotToValue(const TaskSnapshot& snapshot, | 81 void TaskSnapshotToValue(const TaskSnapshot& snapshot, |
82 base::DictionaryValue* dictionary) { | 82 base::DictionaryValue* dictionary) { |
83 BirthOnThreadSnapshotToValue(snapshot.birth, "birth", dictionary); | 83 BirthOnThreadSnapshotToValue(snapshot.birth, "birth", dictionary); |
84 | 84 |
85 std::unique_ptr<base::DictionaryValue> death_data(new base::DictionaryValue); | 85 std::unique_ptr<base::DictionaryValue> death_data(new base::DictionaryValue); |
86 DeathDataSnapshotToValue(snapshot.death_data, death_data.get()); | 86 DeathDataSnapshotToValue(snapshot.death_data, death_data.get()); |
87 dictionary->Set("death_data", death_data.release()); | 87 dictionary->Set("death_data", std::move(death_data)); |
88 | 88 |
89 dictionary->SetString("death_thread", snapshot.death_sanitized_thread_name); | 89 dictionary->SetString("death_thread", snapshot.death_sanitized_thread_name); |
90 } | 90 } |
91 | 91 |
92 int AsChromeProcessType( | 92 int AsChromeProcessType( |
93 metrics::ProfilerEventProto::TrackedObject::ProcessType process_type) { | 93 metrics::ProfilerEventProto::TrackedObject::ProcessType process_type) { |
94 switch (process_type) { | 94 switch (process_type) { |
95 case metrics::ProfilerEventProto::TrackedObject::UNKNOWN: | 95 case metrics::ProfilerEventProto::TrackedObject::UNKNOWN: |
96 case metrics::ProfilerEventProto::TrackedObject::PLUGIN: | 96 case metrics::ProfilerEventProto::TrackedObject::PLUGIN: |
97 return content::PROCESS_TYPE_UNKNOWN; | 97 return content::PROCESS_TYPE_UNKNOWN; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 const ProcessDataPhaseSnapshot& process_data_phase, | 133 const ProcessDataPhaseSnapshot& process_data_phase, |
134 base::ProcessId process_id, | 134 base::ProcessId process_id, |
135 metrics::ProfilerEventProto::TrackedObject::ProcessType process_type, | 135 metrics::ProfilerEventProto::TrackedObject::ProcessType process_type, |
136 base::DictionaryValue* dictionary) { | 136 base::DictionaryValue* dictionary) { |
137 std::unique_ptr<base::ListValue> tasks_list(new base::ListValue); | 137 std::unique_ptr<base::ListValue> tasks_list(new base::ListValue); |
138 for (const auto& task : process_data_phase.tasks) { | 138 for (const auto& task : process_data_phase.tasks) { |
139 std::unique_ptr<base::DictionaryValue> snapshot(new base::DictionaryValue); | 139 std::unique_ptr<base::DictionaryValue> snapshot(new base::DictionaryValue); |
140 TaskSnapshotToValue(task, snapshot.get()); | 140 TaskSnapshotToValue(task, snapshot.get()); |
141 tasks_list->Append(std::move(snapshot)); | 141 tasks_list->Append(std::move(snapshot)); |
142 } | 142 } |
143 dictionary->Set("list", tasks_list.release()); | 143 dictionary->Set("list", std::move(tasks_list)); |
144 | 144 |
145 dictionary->SetInteger("process_id", process_id); | 145 dictionary->SetInteger("process_id", process_id); |
146 dictionary->SetString("process_type", content::GetProcessTypeNameInEnglish( | 146 dictionary->SetString("process_type", content::GetProcessTypeNameInEnglish( |
147 AsChromeProcessType(process_type))); | 147 AsChromeProcessType(process_type))); |
148 } | 148 } |
149 | 149 |
150 } // namespace task_profiler | 150 } // namespace task_profiler |
OLD | NEW |