| Index: base/debug/trace_event_unittest.cc
|
| diff --git a/base/debug/trace_event_unittest.cc b/base/debug/trace_event_unittest.cc
|
| index 6b8f5f901ec9f733f8bde7da1f3bddf805850198..ff2e306cb32888d252ee8a899aca732a1657c637 100644
|
| --- a/base/debug/trace_event_unittest.cc
|
| +++ b/base/debug/trace_event_unittest.cc
|
| @@ -9,6 +9,7 @@
|
| #include "base/json/json_reader.h"
|
| #include "base/json/json_writer.h"
|
| #include "base/memory/scoped_ptr.h"
|
| +#include "base/process_util.h"
|
| #include "base/stringprintf.h"
|
| #include "base/synchronization/waitable_event.h"
|
| #include "base/threading/thread.h"
|
| @@ -154,7 +155,7 @@ bool IsStringInDict(const char* string_to_match, DictionaryValue* dict) {
|
| }
|
|
|
| DictionaryValue* FindTraceEntry(const ListValue& trace_parsed,
|
| - const char *string_to_match,
|
| + const char* string_to_match,
|
| DictionaryValue* match_after_this_item = NULL) {
|
| // Scan all items
|
| size_t trace_parsed_count = trace_parsed.GetSize();
|
| @@ -176,6 +177,24 @@ DictionaryValue* FindTraceEntry(const ListValue& trace_parsed,
|
| return NULL;
|
| }
|
|
|
| +std::vector<DictionaryValue*> FindTraceEntries(
|
| + const ListValue& trace_parsed,
|
| + const char* string_to_match) {
|
| + std::vector<DictionaryValue*> hits;
|
| + size_t trace_parsed_count = trace_parsed.GetSize();
|
| + for (size_t i = 0; i < trace_parsed_count; i++) {
|
| + Value* value = NULL;
|
| + trace_parsed.Get(i, &value);
|
| + if (!value || value->GetType() != Value::TYPE_DICTIONARY)
|
| + continue;
|
| + DictionaryValue* dict = static_cast<DictionaryValue*>(value);
|
| +
|
| + if (IsStringInDict(string_to_match, dict))
|
| + hits.push_back(dict);
|
| + }
|
| + return hits;
|
| +}
|
| +
|
| void DataCapturedCallTraces(WaitableEvent* task_complete_event) {
|
| {
|
| TRACE_EVENT_BEGIN_ETW("TRACE_EVENT_BEGIN_ETW call", 1122, "extrastring1");
|
| @@ -493,6 +512,75 @@ TEST_F(TraceEventTestFixture, DataCapturedManyThreads) {
|
| num_threads, num_events);
|
| }
|
|
|
| +// Test that thread and process names show up in the trace
|
| +TEST_F(TraceEventTestFixture, ThreadNames) {
|
| + ManualTestSetUp();
|
| +
|
| + // Create threads before we enable tracing to make sure
|
| + // that tracelog still captures them.
|
| + const int num_threads = 4;
|
| + const int num_events = 10;
|
| + Thread* threads[num_threads];
|
| + PlatformThreadId thread_ids[num_threads];
|
| + for (int i = 0; i < num_threads; i++)
|
| + threads[i] = new Thread(StringPrintf("Thread %d", i).c_str());
|
| +
|
| + // Enable tracing.
|
| + TraceLog::GetInstance()->SetEnabled(true);
|
| +
|
| + // Now run some trace code on these threads.
|
| + WaitableEvent* task_complete_events[num_threads];
|
| + for (int i = 0; i < num_threads; i++) {
|
| + task_complete_events[i] = new WaitableEvent(false, false);
|
| + threads[i]->Start();
|
| + thread_ids[i] = threads[i]->thread_id();
|
| + threads[i]->message_loop()->PostTask(
|
| + FROM_HERE, NewRunnableFunction(&DataCapturedCallManyTraces,
|
| + i, num_events, task_complete_events[i]));
|
| + }
|
| + for (int i = 0; i < num_threads; i++) {
|
| + task_complete_events[i]->Wait();
|
| + }
|
| +
|
| + // Shut things down.
|
| + TraceLog::GetInstance()->SetEnabled(false);
|
| + for (int i = 0; i < num_threads; i++) {
|
| + threads[i]->Stop();
|
| + delete threads[i];
|
| + delete task_complete_events[i];
|
| + }
|
| +
|
| + std::string tmp;
|
| + int tmp_int;
|
| + DictionaryValue* item;
|
| +
|
| + // Make sure we get thread name metadata.
|
| + // Note, the test suite may have created a ton of threads.
|
| + // So, we'll have thread names for threads we didn't create.
|
| + std::vector<DictionaryValue*> items =
|
| + FindTraceEntries(trace_parsed_, "thread_name");
|
| + for (int i = 0; i < static_cast<int>(items.size()); i++) {
|
| + item = items[i];
|
| + EXPECT_TRUE(item);
|
| + EXPECT_TRUE(item->GetInteger("tid", &tmp_int));
|
| +
|
| + // See if this thread name is one of the threads we just created
|
| + for (int j = 0; j < num_threads; j++) {
|
| + if(static_cast<int>(thread_ids[j]) != tmp_int)
|
| + continue;
|
| +
|
| + std::string expected_name = StringPrintf("Thread %d", j).c_str();
|
| + EXPECT_TRUE(item->GetString("ph", &tmp) && tmp == "M");
|
| + EXPECT_TRUE(item->GetInteger("pid", &tmp_int) &&
|
| + tmp_int == static_cast<int>(base::GetCurrentProcId()));
|
| + EXPECT_TRUE(item->GetString("args.name", &tmp) &&
|
| + tmp == expected_name);
|
| + }
|
| + }
|
| +}
|
| +
|
| +namespace {
|
| +
|
| void TraceCallsWithCachedCategoryPointersPointers(const char* name_str) {
|
| TRACE_EVENT0("category name1", name_str);
|
| TRACE_EVENT_INSTANT0("category name2", name_str);
|
| @@ -500,6 +588,10 @@ void TraceCallsWithCachedCategoryPointersPointers(const char* name_str) {
|
| TRACE_EVENT_END0("category name4", name_str);
|
| }
|
|
|
| +
|
| +} // namespace
|
| +
|
| +
|
| // Test trace calls made after tracing singleton shut down.
|
| //
|
| // The singleton is destroyed by our base::AtExitManager, but there can be
|
|
|