Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(353)

Side by Side Diff: chrome/browser/task_profiler/task_profiler_data_serializer_unittest.cc

Issue 985773002: Introducing phased profiling framework (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@write_to_file
Patch Set: More asvitkine@ comments. Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/process_handle.h" 9 #include "base/process/process_handle.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 }
Ilya Sherman 2015/03/17 23:57:38 Should this function be removed?
vadimt 2015/03/19 00:20:44 Done.
22 22
23 void ExpectSerialization( 23 void ExpectSerialization(
24 const tracked_objects::ProcessDataSnapshot& process_data, 24 const tracked_objects::ProcessDataPhaseSnapshot& process_data_phase,
25 base::ProcessId process_id,
25 int process_type, 26 int process_type,
26 const std::string& expected_json) { 27 const std::string& expected_json) {
27 base::DictionaryValue serialized_value; 28 base::DictionaryValue serialized_value;
28 task_profiler::TaskProfilerDataSerializer::ToValue( 29 task_profiler::TaskProfilerDataSerializer::ToValue(
29 process_data, process_type, &serialized_value); 30 process_data_phase, process_id, process_type, &serialized_value);
30 31
31 std::string serialized_json; 32 std::string serialized_json;
32 base::JSONWriter::Write(&serialized_value, &serialized_json); 33 base::JSONWriter::Write(&serialized_value, &serialized_json);
33 34
34 EXPECT_EQ(expected_json, serialized_json); 35 EXPECT_EQ(expected_json, serialized_json);
35 } 36 }
36 37
37 } // anonymous namespace 38 } // anonymous namespace
38 39
39 // Tests the JSON serialization format for profiled process data. 40 // Tests the JSON serialization format for profiled process data.
40 TEST(TaskProfilerDataSerializerTest, SerializeProcessDataToJson) { 41 TEST(TaskProfilerDataSerializerTest, SerializeProcessDataToJson) {
41 { 42 {
42 // Empty data. 43 // Empty data.
43 tracked_objects::ProcessDataSnapshot process_data; 44 tracked_objects::ProcessDataPhaseSnapshot process_data_phase;
44 int process_type = content::PROCESS_TYPE_BROWSER; 45 int process_type = content::PROCESS_TYPE_BROWSER;
45 ExpectSerialization(process_data, process_type, 46 ExpectSerialization(process_data_phase, 239, process_type,
46 "{" 47 "{"
47 "\"descendants\":[" 48 "\"descendants\":["
48 "]," 49 "],"
49 "\"list\":[" 50 "\"list\":["
50 "]," 51 "],"
51 "\"process_id\":" + GetProcessIdString() + "," 52 "\"process_id\":239,"
52 "\"process_type\":\"Browser\"" 53 "\"process_type\":\"Browser\""
53 "}"); 54 "}");
54 } 55 }
55 56
56 { 57 {
57 // Non-empty data. 58 // Non-empty data.
58 tracked_objects::ProcessDataSnapshot process_data; 59 tracked_objects::ProcessDataPhaseSnapshot process_data_phase;
59 60
60 tracked_objects::BirthOnThreadSnapshot parent; 61 tracked_objects::BirthOnThreadSnapshot parent;
61 parent.location.file_name = "path/to/foo.cc"; 62 parent.location.file_name = "path/to/foo.cc";
62 parent.location.function_name = "WhizBang"; 63 parent.location.function_name = "WhizBang";
63 parent.location.line_number = 101; 64 parent.location.line_number = 101;
64 parent.thread_name = "CrBrowserMain"; 65 parent.thread_name = "CrBrowserMain";
65 66
66 tracked_objects::BirthOnThreadSnapshot child; 67 tracked_objects::BirthOnThreadSnapshot child;
67 child.location.file_name = "path/to/bar.cc"; 68 child.location.file_name = "path/to/bar.cc";
68 child.location.function_name = "FizzBoom"; 69 child.location.function_name = "FizzBoom";
69 child.location.line_number = 433; 70 child.location.line_number = 433;
70 child.thread_name = "Chrome_IOThread"; 71 child.thread_name = "Chrome_IOThread";
71 72
72 73
73 // Add a snapshot. 74 // Add a snapshot.
74 process_data.tasks.push_back(tracked_objects::TaskSnapshot()); 75 process_data_phase.tasks.push_back(tracked_objects::TaskSnapshot());
75 process_data.tasks.back().birth = parent; 76 process_data_phase.tasks.back().birth = parent;
76 process_data.tasks.back().death_data.count = 37; 77 process_data_phase.tasks.back().death_data.count = 37;
77 process_data.tasks.back().death_data.run_duration_max = 5; 78 process_data_phase.tasks.back().death_data.run_duration_max = 5;
78 process_data.tasks.back().death_data.run_duration_sample = 3; 79 process_data_phase.tasks.back().death_data.run_duration_sample = 3;
79 process_data.tasks.back().death_data.run_duration_sum = 17; 80 process_data_phase.tasks.back().death_data.run_duration_sum = 17;
80 process_data.tasks.back().death_data.queue_duration_max = 53; 81 process_data_phase.tasks.back().death_data.queue_duration_max = 53;
81 process_data.tasks.back().death_data.queue_duration_sample = 13; 82 process_data_phase.tasks.back().death_data.queue_duration_sample = 13;
82 process_data.tasks.back().death_data.queue_duration_sum = 79; 83 process_data_phase.tasks.back().death_data.queue_duration_sum = 79;
83 process_data.tasks.back().death_thread_name = "WorkerPool/-1340960768"; 84 process_data_phase.tasks.back().death_thread_name =
85 "WorkerPool/-1340960768";
84 86
85 // Add a second snapshot. 87 // Add a second snapshot.
86 process_data.tasks.push_back(tracked_objects::TaskSnapshot()); 88 process_data_phase.tasks.push_back(tracked_objects::TaskSnapshot());
87 process_data.tasks.back().birth = child; 89 process_data_phase.tasks.back().birth = child;
88 process_data.tasks.back().death_data.count = 41; 90 process_data_phase.tasks.back().death_data.count = 41;
89 process_data.tasks.back().death_data.run_duration_max = 205; 91 process_data_phase.tasks.back().death_data.run_duration_max = 205;
90 process_data.tasks.back().death_data.run_duration_sample = 203; 92 process_data_phase.tasks.back().death_data.run_duration_sample = 203;
91 process_data.tasks.back().death_data.run_duration_sum = 2017; 93 process_data_phase.tasks.back().death_data.run_duration_sum = 2017;
92 process_data.tasks.back().death_data.queue_duration_max = 2053; 94 process_data_phase.tasks.back().death_data.queue_duration_max = 2053;
93 process_data.tasks.back().death_data.queue_duration_sample = 2013; 95 process_data_phase.tasks.back().death_data.queue_duration_sample = 2013;
94 process_data.tasks.back().death_data.queue_duration_sum = 2079; 96 process_data_phase.tasks.back().death_data.queue_duration_sum = 2079;
95 process_data.tasks.back().death_thread_name = "PAC thread #3"; 97 process_data_phase.tasks.back().death_thread_name = "PAC thread #3";
96 98
97 // Add a parent-child pair. 99 // Add a parent-child pair.
98 process_data.descendants.push_back( 100 process_data_phase.descendants.push_back(
99 tracked_objects::ParentChildPairSnapshot()); 101 tracked_objects::ParentChildPairSnapshot());
100 process_data.descendants.back().parent = parent; 102 process_data_phase.descendants.back().parent = parent;
101 process_data.descendants.back().child = child; 103 process_data_phase.descendants.back().child = child;
102 104
103 int process_type = content::PROCESS_TYPE_RENDERER; 105 int process_type = content::PROCESS_TYPE_RENDERER;
104 ExpectSerialization(process_data, process_type, 106 ExpectSerialization(process_data_phase, 239, process_type,
105 "{" 107 "{"
106 "\"descendants\":[" 108 "\"descendants\":["
107 "{" 109 "{"
108 "\"child_location\":{" 110 "\"child_location\":{"
109 "\"file_name\":\"path/to/bar.cc\"," 111 "\"file_name\":\"path/to/bar.cc\","
110 "\"function_name\":\"FizzBoom\"," 112 "\"function_name\":\"FizzBoom\","
111 "\"line_number\":433" 113 "\"line_number\":433"
112 "}," 114 "},"
113 "\"child_thread\":\"Chrome_IOThread\"," 115 "\"child_thread\":\"Chrome_IOThread\","
114 "\"parent_location\":{" 116 "\"parent_location\":{"
115 "\"file_name\":\"path/to/foo.cc\"," 117 "\"file_name\":\"path/to/foo.cc\","
116 "\"function_name\":\"WhizBang\"," 118 "\"function_name\":\"WhizBang\","
117 "\"line_number\":101" 119 "\"line_number\":101"
118 "}," 120 "},"
119 "\"parent_thread\":\"CrBrowserMain\"" 121 "\"parent_thread\":\"CrBrowserMain\""
120 "}" 122 "}"
121 "]," 123 "],"
122 "\"list\":[{" 124 "\"list\":[{"
123 "\"birth_location\":{" 125 "\"birth_location\":{"
124 "\"file_name\":\"path/to/foo.cc\"," 126 "\"file_name\":\"path/to/foo.cc\","
125 "\"function_name\":\"WhizBang\"," 127 "\"function_name\":\"WhizBang\","
126 "\"line_number\":101" 128 "\"line_number\":101"
127 "}," 129 "},"
128 "\"birth_thread\":\"CrBrowserMain\"," 130 "\"birth_thread\":\"CrBrowserMain\","
129 "\"death_data\":{" 131 "\"death_data\":{"
130 "\"count\":37," 132 "\"count\":37,"
131 "\"queue_ms\":79," 133 "\"queue_ms\":79,"
132 "\"queue_ms_max\":53," 134 "\"queue_ms_max\":53,"
133 "\"queue_ms_sample\":13," 135 "\"queue_ms_sample\":13,"
134 "\"run_ms\":17," 136 "\"run_ms\":17,"
135 "\"run_ms_max\":5," 137 "\"run_ms_max\":5,"
136 "\"run_ms_sample\":3" 138 "\"run_ms_sample\":3"
137 "}," 139 "},"
138 "\"death_thread\":\"WorkerPool/-1340960768\"" 140 "\"death_thread\":\"WorkerPool/-1340960768\""
139 "},{" 141 "},{"
140 "\"birth_location\":{" 142 "\"birth_location\":{"
141 "\"file_name\":\"path/to/bar.cc\"," 143 "\"file_name\":\"path/to/bar.cc\","
142 "\"function_name\":\"FizzBoom\"," 144 "\"function_name\":\"FizzBoom\","
143 "\"line_number\":433" 145 "\"line_number\":433"
144 "}," 146 "},"
145 "\"birth_thread\":\"Chrome_IOThread\"," 147 "\"birth_thread\":\"Chrome_IOThread\","
146 "\"death_data\":{" 148 "\"death_data\":{"
147 "\"count\":41," 149 "\"count\":41,"
148 "\"queue_ms\":2079," 150 "\"queue_ms\":2079,"
149 "\"queue_ms_max\":2053," 151 "\"queue_ms_max\":2053,"
150 "\"queue_ms_sample\":2013," 152 "\"queue_ms_sample\":2013,"
151 "\"run_ms\":2017," 153 "\"run_ms\":2017,"
152 "\"run_ms_max\":205," 154 "\"run_ms_max\":205,"
153 "\"run_ms_sample\":203" 155 "\"run_ms_sample\":203"
154 "}," 156 "},"
155 "\"death_thread\":\"PAC thread #3\"" 157 "\"death_thread\":\"PAC thread #3\""
156 "}]," 158 "}],"
157 "\"process_id\":" + GetProcessIdString() + "," 159 "\"process_id\":239,"
158 "\"process_type\":\"Tab\"" 160 "\"process_type\":\"Tab\""
159 "}"); 161 "}");
160 } 162 }
161 } 163 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698