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 "base/debug/trace_event.h" | 5 #include "base/debug/trace_event.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 | 213 |
214 bool TraceEventTestFixture::FindNonMatchingValue(const char* key, | 214 bool TraceEventTestFixture::FindNonMatchingValue(const char* key, |
215 const char* value) { | 215 const char* value) { |
216 JsonKeyValue key_values[] = { | 216 JsonKeyValue key_values[] = { |
217 {key, value, IS_NOT_EQUAL}, | 217 {key, value, IS_NOT_EQUAL}, |
218 {0, 0, IS_EQUAL} | 218 {0, 0, IS_EQUAL} |
219 }; | 219 }; |
220 return FindMatchingTraceEntry(key_values); | 220 return FindMatchingTraceEntry(key_values); |
221 } | 221 } |
222 | 222 |
223 bool IsStringInDict(const char* string_to_match, DictionaryValue* dict) { | 223 bool IsStringInDict(const char* string_to_match, const DictionaryValue* dict) { |
224 for (DictionaryValue::key_iterator ikey = dict->begin_keys(); | 224 for (DictionaryValue::key_iterator ikey = dict->begin_keys(); |
225 ikey != dict->end_keys(); ++ikey) { | 225 ikey != dict->end_keys(); ++ikey) { |
226 Value* child = NULL; | 226 const Value* child = NULL; |
227 if (!dict->GetWithoutPathExpansion(*ikey, &child)) | 227 if (!dict->GetWithoutPathExpansion(*ikey, &child)) |
228 continue; | 228 continue; |
229 | 229 |
230 if ((*ikey).find(string_to_match) != std::string::npos) | 230 if ((*ikey).find(string_to_match) != std::string::npos) |
231 return true; | 231 return true; |
232 | 232 |
233 std::string value_str; | 233 std::string value_str; |
234 child->GetAsString(&value_str); | 234 child->GetAsString(&value_str); |
235 if (value_str.find(string_to_match) != std::string::npos) | 235 if (value_str.find(string_to_match) != std::string::npos) |
236 return true; | 236 return true; |
237 } | 237 } |
238 | 238 |
239 // Recurse to test arguments | 239 // Recurse to test arguments |
240 DictionaryValue* args_dict = NULL; | 240 const DictionaryValue* args_dict = NULL; |
241 dict->GetDictionary("args", &args_dict); | 241 dict->GetDictionary("args", &args_dict); |
242 if (args_dict) | 242 if (args_dict) |
243 return IsStringInDict(string_to_match, args_dict); | 243 return IsStringInDict(string_to_match, args_dict); |
244 | 244 |
245 return false; | 245 return false; |
246 } | 246 } |
247 | 247 |
248 DictionaryValue* FindTraceEntry(const ListValue& trace_parsed, | 248 const DictionaryValue* FindTraceEntry( |
249 const char* string_to_match, | 249 const ListValue& trace_parsed, |
250 DictionaryValue* match_after_this_item = NULL) { | 250 const char* string_to_match, |
| 251 const DictionaryValue* match_after_this_item = NULL) { |
251 // Scan all items | 252 // Scan all items |
252 size_t trace_parsed_count = trace_parsed.GetSize(); | 253 size_t trace_parsed_count = trace_parsed.GetSize(); |
253 for (size_t i = 0; i < trace_parsed_count; i++) { | 254 for (size_t i = 0; i < trace_parsed_count; i++) { |
254 Value* value = NULL; | 255 const Value* value = NULL; |
255 trace_parsed.Get(i, &value); | 256 trace_parsed.Get(i, &value); |
256 if (match_after_this_item) { | 257 if (match_after_this_item) { |
257 if (value == match_after_this_item) | 258 if (value == match_after_this_item) |
258 match_after_this_item = NULL; | 259 match_after_this_item = NULL; |
259 continue; | 260 continue; |
260 } | 261 } |
261 if (!value || value->GetType() != Value::TYPE_DICTIONARY) | 262 if (!value || value->GetType() != Value::TYPE_DICTIONARY) |
262 continue; | 263 continue; |
263 DictionaryValue* dict = static_cast<DictionaryValue*>(value); | 264 const DictionaryValue* dict = static_cast<const DictionaryValue*>(value); |
264 | 265 |
265 if (IsStringInDict(string_to_match, dict)) | 266 if (IsStringInDict(string_to_match, dict)) |
266 return dict; | 267 return dict; |
267 } | 268 } |
268 return NULL; | 269 return NULL; |
269 } | 270 } |
270 | 271 |
271 std::vector<DictionaryValue*> FindTraceEntries( | 272 std::vector<const DictionaryValue*> FindTraceEntries( |
272 const ListValue& trace_parsed, | 273 const ListValue& trace_parsed, |
273 const char* string_to_match) { | 274 const char* string_to_match) { |
274 std::vector<DictionaryValue*> hits; | 275 std::vector<const DictionaryValue*> hits; |
275 size_t trace_parsed_count = trace_parsed.GetSize(); | 276 size_t trace_parsed_count = trace_parsed.GetSize(); |
276 for (size_t i = 0; i < trace_parsed_count; i++) { | 277 for (size_t i = 0; i < trace_parsed_count; i++) { |
277 Value* value = NULL; | 278 const Value* value = NULL; |
278 trace_parsed.Get(i, &value); | 279 trace_parsed.Get(i, &value); |
279 if (!value || value->GetType() != Value::TYPE_DICTIONARY) | 280 if (!value || value->GetType() != Value::TYPE_DICTIONARY) |
280 continue; | 281 continue; |
281 DictionaryValue* dict = static_cast<DictionaryValue*>(value); | 282 const DictionaryValue* dict = static_cast<const DictionaryValue*>(value); |
282 | 283 |
283 if (IsStringInDict(string_to_match, dict)) | 284 if (IsStringInDict(string_to_match, dict)) |
284 hits.push_back(dict); | 285 hits.push_back(dict); |
285 } | 286 } |
286 return hits; | 287 return hits; |
287 } | 288 } |
288 | 289 |
289 void TraceWithAllMacroVariants(WaitableEvent* task_complete_event) { | 290 void TraceWithAllMacroVariants(WaitableEvent* task_complete_event) { |
290 { | 291 { |
291 TRACE_EVENT_BEGIN_ETW("TRACE_EVENT_BEGIN_ETW call", 0x1122, "extrastring1"); | 292 TRACE_EVENT_BEGIN_ETW("TRACE_EVENT_BEGIN_ETW call", 0x1122, "extrastring1"); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
358 TRACE_COUNTER_ID1("all", "TRACE_COUNTER_ID1 call", 0x319009, 31415); | 359 TRACE_COUNTER_ID1("all", "TRACE_COUNTER_ID1 call", 0x319009, 31415); |
359 TRACE_COUNTER_ID2("all", "TRACE_COUNTER_ID2 call", 0x319009, | 360 TRACE_COUNTER_ID2("all", "TRACE_COUNTER_ID2 call", 0x319009, |
360 "a", 30000, "b", 1415); | 361 "a", 30000, "b", 1415); |
361 } // Scope close causes TRACE_EVENT0 etc to send their END events. | 362 } // Scope close causes TRACE_EVENT0 etc to send their END events. |
362 | 363 |
363 if (task_complete_event) | 364 if (task_complete_event) |
364 task_complete_event->Signal(); | 365 task_complete_event->Signal(); |
365 } | 366 } |
366 | 367 |
367 void ValidateAllTraceMacrosCreatedData(const ListValue& trace_parsed) { | 368 void ValidateAllTraceMacrosCreatedData(const ListValue& trace_parsed) { |
368 DictionaryValue* item = NULL; | 369 const DictionaryValue* item = NULL; |
369 | 370 |
370 #define EXPECT_FIND_(string) \ | 371 #define EXPECT_FIND_(string) \ |
371 EXPECT_TRUE((item = FindTraceEntry(trace_parsed, string))); | 372 EXPECT_TRUE((item = FindTraceEntry(trace_parsed, string))); |
372 #define EXPECT_NOT_FIND_(string) \ | 373 #define EXPECT_NOT_FIND_(string) \ |
373 EXPECT_FALSE((item = FindTraceEntry(trace_parsed, string))); | 374 EXPECT_FALSE((item = FindTraceEntry(trace_parsed, string))); |
374 #define EXPECT_SUB_FIND_(string) \ | 375 #define EXPECT_SUB_FIND_(string) \ |
375 if (item) EXPECT_TRUE((IsStringInDict(string, item))); | 376 if (item) EXPECT_TRUE((IsStringInDict(string, item))); |
376 | 377 |
377 EXPECT_FIND_("ETW Trace Event"); | 378 EXPECT_FIND_("ETW Trace Event"); |
378 EXPECT_FIND_("all"); | 379 EXPECT_FIND_("all"); |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
591 task_complete_event->Signal(); | 592 task_complete_event->Signal(); |
592 } | 593 } |
593 | 594 |
594 void ValidateInstantEventPresentOnEveryThread(const ListValue& trace_parsed, | 595 void ValidateInstantEventPresentOnEveryThread(const ListValue& trace_parsed, |
595 int num_threads, | 596 int num_threads, |
596 int num_events) { | 597 int num_events) { |
597 std::map<int, std::map<int, bool> > results; | 598 std::map<int, std::map<int, bool> > results; |
598 | 599 |
599 size_t trace_parsed_count = trace_parsed.GetSize(); | 600 size_t trace_parsed_count = trace_parsed.GetSize(); |
600 for (size_t i = 0; i < trace_parsed_count; i++) { | 601 for (size_t i = 0; i < trace_parsed_count; i++) { |
601 Value* value = NULL; | 602 const Value* value = NULL; |
602 trace_parsed.Get(i, &value); | 603 trace_parsed.Get(i, &value); |
603 if (!value || value->GetType() != Value::TYPE_DICTIONARY) | 604 if (!value || value->GetType() != Value::TYPE_DICTIONARY) |
604 continue; | 605 continue; |
605 DictionaryValue* dict = static_cast<DictionaryValue*>(value); | 606 const DictionaryValue* dict = static_cast<const DictionaryValue*>(value); |
606 std::string name; | 607 std::string name; |
607 dict->GetString("name", &name); | 608 dict->GetString("name", &name); |
608 if (name != "multi thread event") | 609 if (name != "multi thread event") |
609 continue; | 610 continue; |
610 | 611 |
611 int thread = 0; | 612 int thread = 0; |
612 int event = 0; | 613 int event = 0; |
613 EXPECT_TRUE(dict->GetInteger("args.thread", &thread)); | 614 EXPECT_TRUE(dict->GetInteger("args.thread", &thread)); |
614 EXPECT_TRUE(dict->GetInteger("args.event", &event)); | 615 EXPECT_TRUE(dict->GetInteger("args.event", &event)); |
615 results[thread][event] = true; | 616 results[thread][event] = true; |
(...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1142 for (int i = 0; i < num_threads; i++) { | 1143 for (int i = 0; i < num_threads; i++) { |
1143 threads[i]->Stop(); | 1144 threads[i]->Stop(); |
1144 delete threads[i]; | 1145 delete threads[i]; |
1145 delete task_complete_events[i]; | 1146 delete task_complete_events[i]; |
1146 } | 1147 } |
1147 | 1148 |
1148 TraceLog::GetInstance()->SetEnabled(false); | 1149 TraceLog::GetInstance()->SetEnabled(false); |
1149 | 1150 |
1150 std::string tmp; | 1151 std::string tmp; |
1151 int tmp_int; | 1152 int tmp_int; |
1152 DictionaryValue* item; | 1153 const DictionaryValue* item; |
1153 | 1154 |
1154 // Make sure we get thread name metadata. | 1155 // Make sure we get thread name metadata. |
1155 // Note, the test suite may have created a ton of threads. | 1156 // Note, the test suite may have created a ton of threads. |
1156 // So, we'll have thread names for threads we didn't create. | 1157 // So, we'll have thread names for threads we didn't create. |
1157 std::vector<DictionaryValue*> items = | 1158 std::vector<const DictionaryValue*> items = |
1158 FindTraceEntries(trace_parsed_, "thread_name"); | 1159 FindTraceEntries(trace_parsed_, "thread_name"); |
1159 for (int i = 0; i < static_cast<int>(items.size()); i++) { | 1160 for (int i = 0; i < static_cast<int>(items.size()); i++) { |
1160 item = items[i]; | 1161 item = items[i]; |
1161 ASSERT_TRUE(item); | 1162 ASSERT_TRUE(item); |
1162 EXPECT_TRUE(item->GetInteger("tid", &tmp_int)); | 1163 EXPECT_TRUE(item->GetInteger("tid", &tmp_int)); |
1163 | 1164 |
1164 // See if this thread name is one of the threads we just created | 1165 // See if this thread name is one of the threads we just created |
1165 for (int j = 0; j < num_threads; j++) { | 1166 for (int j = 0; j < num_threads; j++) { |
1166 if(static_cast<int>(thread_ids[j]) != tmp_int) | 1167 if(static_cast<int>(thread_ids[j]) != tmp_int) |
1167 continue; | 1168 continue; |
(...skipping 26 matching lines...) Expand all Loading... |
1194 | 1195 |
1195 PlatformThread::SetName("pub"); | 1196 PlatformThread::SetName("pub"); |
1196 TRACE_EVENT_INSTANT0("drink", "beer"); | 1197 TRACE_EVENT_INSTANT0("drink", "beer"); |
1197 TRACE_EVENT_INSTANT0("drink", "wine"); | 1198 TRACE_EVENT_INSTANT0("drink", "wine"); |
1198 | 1199 |
1199 PlatformThread::SetName(" bar"); | 1200 PlatformThread::SetName(" bar"); |
1200 TRACE_EVENT_INSTANT0("drink", "whisky"); | 1201 TRACE_EVENT_INSTANT0("drink", "whisky"); |
1201 | 1202 |
1202 TraceLog::GetInstance()->SetEnabled(false); | 1203 TraceLog::GetInstance()->SetEnabled(false); |
1203 | 1204 |
1204 std::vector<DictionaryValue*> items = | 1205 std::vector<const DictionaryValue*> items = |
1205 FindTraceEntries(trace_parsed_, "thread_name"); | 1206 FindTraceEntries(trace_parsed_, "thread_name"); |
1206 EXPECT_EQ(1u, items.size()); | 1207 EXPECT_EQ(1u, items.size()); |
1207 ASSERT_GT(items.size(), 0u); | 1208 ASSERT_GT(items.size(), 0u); |
1208 DictionaryValue* item = items[0]; | 1209 const DictionaryValue* item = items[0]; |
1209 ASSERT_TRUE(item); | 1210 ASSERT_TRUE(item); |
1210 int tid; | 1211 int tid; |
1211 EXPECT_TRUE(item->GetInteger("tid", &tid)); | 1212 EXPECT_TRUE(item->GetInteger("tid", &tid)); |
1212 EXPECT_EQ(PlatformThread::CurrentId(), static_cast<PlatformThreadId>(tid)); | 1213 EXPECT_EQ(PlatformThread::CurrentId(), static_cast<PlatformThreadId>(tid)); |
1213 | 1214 |
1214 std::string expected_name = "cafe,pub, bar"; | 1215 std::string expected_name = "cafe,pub, bar"; |
1215 std::string tmp; | 1216 std::string tmp; |
1216 EXPECT_TRUE(item->GetString("args.name", &tmp)); | 1217 EXPECT_TRUE(item->GetString("args.name", &tmp)); |
1217 EXPECT_EQ(expected_name, tmp); | 1218 EXPECT_EQ(expected_name, tmp); |
1218 } | 1219 } |
(...skipping 24 matching lines...) Expand all Loading... |
1243 TRACE_EVENT_INSTANT0("all", "is recorded 1; system has been enabled"); | 1244 TRACE_EVENT_INSTANT0("all", "is recorded 1; system has been enabled"); |
1244 // Trace calls that will cache pointers to categories; they're valid here | 1245 // Trace calls that will cache pointers to categories; they're valid here |
1245 TraceCallsWithCachedCategoryPointersPointers( | 1246 TraceCallsWithCachedCategoryPointersPointers( |
1246 "is recorded 2; system has been enabled"); | 1247 "is recorded 2; system has been enabled"); |
1247 | 1248 |
1248 TraceLog::GetInstance()->SetEnabled(false); | 1249 TraceLog::GetInstance()->SetEnabled(false); |
1249 } // scope to destroy singleton | 1250 } // scope to destroy singleton |
1250 ASSERT_FALSE(TraceLog::GetInstance()); | 1251 ASSERT_FALSE(TraceLog::GetInstance()); |
1251 | 1252 |
1252 // Now that singleton is destroyed, check what trace events were recorded | 1253 // Now that singleton is destroyed, check what trace events were recorded |
1253 DictionaryValue* item = NULL; | 1254 const DictionaryValue* item = NULL; |
1254 ListValue& trace_parsed = trace_parsed_; | 1255 ListValue& trace_parsed = trace_parsed_; |
1255 EXPECT_FIND_("is recorded 1"); | 1256 EXPECT_FIND_("is recorded 1"); |
1256 EXPECT_FIND_("is recorded 2"); | 1257 EXPECT_FIND_("is recorded 2"); |
1257 EXPECT_NOT_FIND_("not recorded"); | 1258 EXPECT_NOT_FIND_("not recorded"); |
1258 | 1259 |
1259 // Make additional trace event calls on the shutdown system. They should | 1260 // Make additional trace event calls on the shutdown system. They should |
1260 // all pass cleanly, but the data not be recorded. We'll verify that next | 1261 // all pass cleanly, but the data not be recorded. We'll verify that next |
1261 // time around the loop (the only way to flush the trace buffers). | 1262 // time around the loop (the only way to flush the trace buffers). |
1262 TRACE_EVENT_BEGIN_ETW("not recorded; system shutdown", 0, NULL); | 1263 TRACE_EVENT_BEGIN_ETW("not recorded; system shutdown", 0, NULL); |
1263 TRACE_EVENT_END_ETW("not recorded; system shutdown", 0, NULL); | 1264 TRACE_EVENT_END_ETW("not recorded; system shutdown", 0, NULL); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1323 | 1324 |
1324 // As per NormallyNoDeepCopy, modify the strings in place. | 1325 // As per NormallyNoDeepCopy, modify the strings in place. |
1325 name1[0] = name2[0] = name3[0] = arg1[0] = arg2[0] = val1[0] = val2[0] = '@'; | 1326 name1[0] = name2[0] = name3[0] = arg1[0] = arg2[0] = val1[0] = val2[0] = '@'; |
1326 | 1327 |
1327 TraceLog::GetInstance()->SetEnabled(false); | 1328 TraceLog::GetInstance()->SetEnabled(false); |
1328 | 1329 |
1329 EXPECT_FALSE(FindTraceEntry(trace_parsed_, name1.c_str())); | 1330 EXPECT_FALSE(FindTraceEntry(trace_parsed_, name1.c_str())); |
1330 EXPECT_FALSE(FindTraceEntry(trace_parsed_, name2.c_str())); | 1331 EXPECT_FALSE(FindTraceEntry(trace_parsed_, name2.c_str())); |
1331 EXPECT_FALSE(FindTraceEntry(trace_parsed_, name3.c_str())); | 1332 EXPECT_FALSE(FindTraceEntry(trace_parsed_, name3.c_str())); |
1332 | 1333 |
1333 DictionaryValue* entry1 = FindTraceEntry(trace_parsed_, kOriginalName1); | 1334 const DictionaryValue* entry1 = FindTraceEntry(trace_parsed_, kOriginalName1); |
1334 DictionaryValue* entry2 = FindTraceEntry(trace_parsed_, kOriginalName2); | 1335 const DictionaryValue* entry2 = FindTraceEntry(trace_parsed_, kOriginalName2); |
1335 DictionaryValue* entry3 = FindTraceEntry(trace_parsed_, kOriginalName3); | 1336 const DictionaryValue* entry3 = FindTraceEntry(trace_parsed_, kOriginalName3); |
1336 ASSERT_TRUE(entry1); | 1337 ASSERT_TRUE(entry1); |
1337 ASSERT_TRUE(entry2); | 1338 ASSERT_TRUE(entry2); |
1338 ASSERT_TRUE(entry3); | 1339 ASSERT_TRUE(entry3); |
1339 | 1340 |
1340 int i; | 1341 int i; |
1341 EXPECT_FALSE(entry2->GetInteger("args.@rg1", &i)); | 1342 EXPECT_FALSE(entry2->GetInteger("args.@rg1", &i)); |
1342 EXPECT_TRUE(entry2->GetInteger("args.arg1", &i)); | 1343 EXPECT_TRUE(entry2->GetInteger("args.arg1", &i)); |
1343 EXPECT_EQ(5, i); | 1344 EXPECT_EQ(5, i); |
1344 | 1345 |
1345 std::string s; | 1346 std::string s; |
(...skipping 20 matching lines...) Expand all Loading... |
1366 Clear(); | 1367 Clear(); |
1367 | 1368 |
1368 trace_buffer_.Start(); | 1369 trace_buffer_.Start(); |
1369 trace_buffer_.AddFragment("bla1,bla2,bla3,bla4"); | 1370 trace_buffer_.AddFragment("bla1,bla2,bla3,bla4"); |
1370 trace_buffer_.Finish(); | 1371 trace_buffer_.Finish(); |
1371 EXPECT_STREQ(json_output_.json_output.c_str(), "[bla1,bla2,bla3,bla4]"); | 1372 EXPECT_STREQ(json_output_.json_output.c_str(), "[bla1,bla2,bla3,bla4]"); |
1372 } | 1373 } |
1373 | 1374 |
1374 } // namespace debug | 1375 } // namespace debug |
1375 } // namespace base | 1376 } // namespace base |
OLD | NEW |