| 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
| 9 #include "base/process_util.h" | 9 #include "base/process_util.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| 11 #include "base/tracked_objects.h" | 11 #include "base/tracked_objects.h" |
| 12 #include "base/values.h" | 12 #include "base/values.h" |
| 13 #include "chrome/browser/task_profiler/task_profiler_data_serializer.h" | 13 #include "chrome/browser/task_profiler/task_profiler_data_serializer.h" |
| 14 #include "content/public/common/process_type.h" | 14 #include "content/public/common/process_type.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 std::string GetProcessIdString() { | 19 std::string GetProcessIdString() { |
| 20 return base::IntToString(base::GetCurrentProcId()); | 20 return base::IntToString(base::GetCurrentProcId()); |
| 21 } | 21 } |
| 22 | 22 |
| 23 void ExpectSerialization( | 23 void ExpectSerialization( |
| 24 const tracked_objects::ProcessDataSnapshot& process_data, | 24 const tracked_objects::ProcessDataSnapshot& process_data, |
| 25 content::ProcessType process_type, | 25 int process_type, |
| 26 const std::string& expected_json) { | 26 const std::string& expected_json) { |
| 27 base::DictionaryValue serialized_value; | 27 base::DictionaryValue serialized_value; |
| 28 task_profiler::TaskProfilerDataSerializer::ToValue( | 28 task_profiler::TaskProfilerDataSerializer::ToValue( |
| 29 process_data, process_type, &serialized_value); | 29 process_data, process_type, &serialized_value); |
| 30 | 30 |
| 31 std::string serialized_json; | 31 std::string serialized_json; |
| 32 base::JSONWriter::Write(&serialized_value, &serialized_json); | 32 base::JSONWriter::Write(&serialized_value, &serialized_json); |
| 33 | 33 |
| 34 EXPECT_EQ(expected_json, serialized_json); | 34 EXPECT_EQ(expected_json, serialized_json); |
| 35 } | 35 } |
| 36 | 36 |
| 37 } // anonymous namespace | 37 } // anonymous namespace |
| 38 | 38 |
| 39 // Tests the JSON serialization format for profiled process data. | 39 // Tests the JSON serialization format for profiled process data. |
| 40 TEST(TaskProfilerDataSerializerTest, SerializeProcessDataToJson) { | 40 TEST(TaskProfilerDataSerializerTest, SerializeProcessDataToJson) { |
| 41 { | 41 { |
| 42 // Empty data. | 42 // Empty data. |
| 43 tracked_objects::ProcessDataSnapshot process_data; | 43 tracked_objects::ProcessDataSnapshot process_data; |
| 44 content::ProcessType process_type = content::PROCESS_TYPE_BROWSER; | 44 int process_type = content::PROCESS_TYPE_BROWSER; |
| 45 ExpectSerialization(process_data, process_type, | 45 ExpectSerialization(process_data, process_type, |
| 46 "{" | 46 "{" |
| 47 "\"descendants\":[" | 47 "\"descendants\":[" |
| 48 "]," | 48 "]," |
| 49 "\"list\":[" | 49 "\"list\":[" |
| 50 "]," | 50 "]," |
| 51 "\"process_id\":" + GetProcessIdString() + "," | 51 "\"process_id\":" + GetProcessIdString() + "," |
| 52 "\"process_type\":\"Browser\"" | 52 "\"process_type\":\"Browser\"" |
| 53 "}"); | 53 "}"); |
| 54 } | 54 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 process_data.tasks.back().death_data.queue_duration_sample = 2013; | 93 process_data.tasks.back().death_data.queue_duration_sample = 2013; |
| 94 process_data.tasks.back().death_data.queue_duration_sum = 2079; | 94 process_data.tasks.back().death_data.queue_duration_sum = 2079; |
| 95 process_data.tasks.back().death_thread_name = "PAC thread #3"; | 95 process_data.tasks.back().death_thread_name = "PAC thread #3"; |
| 96 | 96 |
| 97 // Add a parent-child pair. | 97 // Add a parent-child pair. |
| 98 process_data.descendants.push_back( | 98 process_data.descendants.push_back( |
| 99 tracked_objects::ParentChildPairSnapshot()); | 99 tracked_objects::ParentChildPairSnapshot()); |
| 100 process_data.descendants.back().parent = parent; | 100 process_data.descendants.back().parent = parent; |
| 101 process_data.descendants.back().child = child; | 101 process_data.descendants.back().child = child; |
| 102 | 102 |
| 103 content::ProcessType process_type = content::PROCESS_TYPE_RENDERER; | 103 int process_type = content::PROCESS_TYPE_RENDERER; |
| 104 ExpectSerialization(process_data, process_type, | 104 ExpectSerialization(process_data, process_type, |
| 105 "{" | 105 "{" |
| 106 "\"descendants\":[" | 106 "\"descendants\":[" |
| 107 "{" | 107 "{" |
| 108 "\"child_location\":{" | 108 "\"child_location\":{" |
| 109 "\"file_name\":\"path/to/bar.cc\"," | 109 "\"file_name\":\"path/to/bar.cc\"," |
| 110 "\"function_name\":\"FizzBoom\"," | 110 "\"function_name\":\"FizzBoom\"," |
| 111 "\"line_number\":433" | 111 "\"line_number\":433" |
| 112 "}," | 112 "}," |
| 113 "\"child_thread\":\"Chrome_IOThread\"," | 113 "\"child_thread\":\"Chrome_IOThread\"," |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 "\"run_ms_max\":205," | 152 "\"run_ms_max\":205," |
| 153 "\"run_ms_sample\":203" | 153 "\"run_ms_sample\":203" |
| 154 "}," | 154 "}," |
| 155 "\"death_thread\":\"PAC thread #3\"" | 155 "\"death_thread\":\"PAC thread #3\"" |
| 156 "}]," | 156 "}]," |
| 157 "\"process_id\":" + GetProcessIdString() + "," | 157 "\"process_id\":" + GetProcessIdString() + "," |
| 158 "\"process_type\":\"Tab\"" | 158 "\"process_type\":\"Tab\"" |
| 159 "}"); | 159 "}"); |
| 160 } | 160 } |
| 161 } | 161 } |
| OLD | NEW |