| 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/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "base/files/file_util.h" | 8 #include "base/files/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/time.h" | 10 #include "base/time/time.h" |
| 11 #include "base/tracked_objects.h" | 11 #include "base/tracked_objects.h" |
| 12 #include "chrome/common/chrome_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; |
| 23 using tracked_objects::TaskSnapshot; | 23 using tracked_objects::TaskSnapshot; |
| 24 using tracked_objects::ProcessDataSnapshot; | 24 using tracked_objects::ProcessDataPhaseSnapshot; |
| 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->SetString("file_name", 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. |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 | 73 |
| 74 dictionary->SetString("death_thread", snapshot.death_thread_name); | 74 dictionary->SetString("death_thread", snapshot.death_thread_name); |
| 75 } | 75 } |
| 76 | 76 |
| 77 } // anonymous namespace | 77 } // anonymous namespace |
| 78 | 78 |
| 79 namespace task_profiler { | 79 namespace task_profiler { |
| 80 | 80 |
| 81 // static | 81 // static |
| 82 void TaskProfilerDataSerializer::ToValue( | 82 void TaskProfilerDataSerializer::ToValue( |
| 83 const ProcessDataSnapshot& process_data, | 83 const ProcessDataPhaseSnapshot& process_data_phase, |
| 84 int process_id, |
| 84 int process_type, | 85 int process_type, |
| 85 base::DictionaryValue* dictionary) { | 86 base::DictionaryValue* dictionary) { |
| 86 scoped_ptr<base::ListValue> tasks_list(new base::ListValue); | 87 scoped_ptr<base::ListValue> tasks_list(new base::ListValue); |
| 87 for (std::vector<TaskSnapshot>::const_iterator it = | 88 for (const auto& i : process_data_phase.tasks) { |
| 88 process_data.tasks.begin(); | |
| 89 it != process_data.tasks.end(); ++it) { | |
| 90 scoped_ptr<base::DictionaryValue> snapshot(new base::DictionaryValue); | 89 scoped_ptr<base::DictionaryValue> snapshot(new base::DictionaryValue); |
| 91 TaskSnapshotToValue(*it, snapshot.get()); | 90 TaskSnapshotToValue(i, snapshot.get()); |
| 92 tasks_list->Append(snapshot.release()); | 91 tasks_list->Append(snapshot.release()); |
| 93 } | 92 } |
| 94 dictionary->Set("list", tasks_list.release()); | 93 dictionary->Set("list", tasks_list.release()); |
| 95 | 94 |
| 96 dictionary->SetInteger("process_id", process_data.process_id); | 95 dictionary->SetInteger("process_id", process_id); |
| 97 dictionary->SetString("process_type", | 96 dictionary->SetString("process_type", |
| 98 content::GetProcessTypeNameInEnglish(process_type)); | 97 content::GetProcessTypeNameInEnglish(process_type)); |
| 99 | 98 |
| 100 scoped_ptr<base::ListValue> descendants_list(new base::ListValue); | 99 scoped_ptr<base::ListValue> descendants_list(new base::ListValue); |
| 101 for (std::vector<ParentChildPairSnapshot>::const_iterator it = | 100 for (const auto& i : process_data_phase.descendants) { |
| 102 process_data.descendants.begin(); | |
| 103 it != process_data.descendants.end(); ++it) { | |
| 104 scoped_ptr<base::DictionaryValue> parent_child(new base::DictionaryValue); | 101 scoped_ptr<base::DictionaryValue> parent_child(new base::DictionaryValue); |
| 105 BirthOnThreadSnapshotToValue(it->parent, "parent", parent_child.get()); | 102 BirthOnThreadSnapshotToValue(i.parent, "parent", parent_child.get()); |
| 106 BirthOnThreadSnapshotToValue(it->child, "child", parent_child.get()); | 103 BirthOnThreadSnapshotToValue(i.child, "child", parent_child.get()); |
| 107 descendants_list->Append(parent_child.release()); | 104 descendants_list->Append(parent_child.release()); |
| 108 } | 105 } |
| 109 dictionary->Set("descendants", descendants_list.release()); | 106 dictionary->Set("descendants", descendants_list.release()); |
| 110 } | 107 } |
| 111 | 108 |
| 112 } // namespace task_profiler | 109 } // namespace task_profiler |
| OLD | NEW |