Skip to content

Commit

Permalink
Use disabled-by-default prefix in logging NetLog events to TraceLog
Browse files Browse the repository at this point in the history
BUG=399701

Review URL: https://codereview.chromium.org/671533005

Cr-Commit-Position: refs/heads/master@{#300543}
  • Loading branch information
xunjieli authored and Commit bot committed Oct 21, 2014
1 parent e3b2f50 commit 1d2e6f5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
12 changes: 9 additions & 3 deletions net/base/trace_net_log_observer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ namespace net {

namespace {

// TraceLog category for NetLog events.
const char kNetLogTracingCategory[] = TRACE_DISABLED_BY_DEFAULT("netlog");

class TracedValue : public base::debug::ConvertableToTraceFormat {
public:
explicit TracedValue(scoped_ptr<base::Value> value) : value_(value.Pass()) {}
Expand Down Expand Up @@ -55,21 +58,24 @@ void TraceNetLogObserver::OnAddEntry(const NetLog::Entry& entry) {
switch (entry.phase()) {
case NetLog::PHASE_BEGIN:
TRACE_EVENT_NESTABLE_ASYNC_BEGIN2(
"netlog", NetLog::EventTypeToString(entry.type()), entry.source().id,
kNetLogTracingCategory,
NetLog::EventTypeToString(entry.type()), entry.source().id,
"source_type", NetLog::SourceTypeToString(entry.source().type),
"params", scoped_refptr<base::debug::ConvertableToTraceFormat>(
new TracedValue(params.Pass())));
break;
case NetLog::PHASE_END:
TRACE_EVENT_NESTABLE_ASYNC_END2(
"netlog", NetLog::EventTypeToString(entry.type()), entry.source().id,
kNetLogTracingCategory,
NetLog::EventTypeToString(entry.type()), entry.source().id,
"source_type", NetLog::SourceTypeToString(entry.source().type),
"params", scoped_refptr<base::debug::ConvertableToTraceFormat>(
new TracedValue(params.Pass())));
break;
case NetLog::PHASE_NONE:
TRACE_EVENT_NESTABLE_ASYNC_INSTANT2(
"netlog", NetLog::EventTypeToString(entry.type()), entry.source().id,
kNetLogTracingCategory,
NetLog::EventTypeToString(entry.type()), entry.source().id,
"source_type", NetLog::SourceTypeToString(entry.source().type),
"params", scoped_refptr<base::debug::ConvertableToTraceFormat>(
new TracedValue(params.Pass())));
Expand Down
28 changes: 16 additions & 12 deletions net/base/trace_net_log_observer_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ namespace net {

namespace {

// TraceLog category for NetLog events.
const char kNetLogTracingCategory[] = TRACE_DISABLED_BY_DEFAULT("netlog");

struct TraceEntryInfo {
std::string category;
std::string id;
Expand Down Expand Up @@ -86,9 +89,10 @@ class TraceNetLogObserverTest : public testing::Test {
}

static void EnableTraceLog() {
TraceLog::GetInstance()->SetEnabled(base::debug::CategoryFilter("netlog"),
TraceLog::RECORDING_MODE,
base::debug::TraceOptions());
TraceLog::GetInstance()->SetEnabled(
base::debug::CategoryFilter(kNetLogTracingCategory),
TraceLog::RECORDING_MODE,
base::debug::TraceOptions());
}

void EndTraceAndFlush() {
Expand Down Expand Up @@ -120,7 +124,7 @@ class TraceNetLogObserverTest : public testing::Test {
<< "Unexpected item without a category field in trace_events";
continue;
}
if (category != "netlog")
if (category != kNetLogTracingCategory)
continue;
filtered_trace_events->Append(dict->DeepCopy());
}
Expand Down Expand Up @@ -185,7 +189,7 @@ TEST_F(TraceNetLogObserverTest, TraceEventCaptured) {
TraceEntryInfo actual_item1 = GetTraceEntryInfoFromValue(*item1);
TraceEntryInfo actual_item2 = GetTraceEntryInfoFromValue(*item2);
TraceEntryInfo actual_item3 = GetTraceEntryInfoFromValue(*item3);
EXPECT_EQ("netlog", actual_item1.category);
EXPECT_EQ(kNetLogTracingCategory, actual_item1.category);
EXPECT_EQ(base::StringPrintf("0x%d", entries[0].source.id), actual_item1.id);
EXPECT_EQ(std::string(1, TRACE_EVENT_PHASE_NESTABLE_ASYNC_INSTANT),
actual_item1.phase);
Expand All @@ -194,7 +198,7 @@ TEST_F(TraceNetLogObserverTest, TraceEventCaptured) {
EXPECT_EQ(NetLog::SourceTypeToString(entries[0].source.type),
actual_item1.source_type);

EXPECT_EQ("netlog", actual_item2.category);
EXPECT_EQ(kNetLogTracingCategory, actual_item2.category);
EXPECT_EQ(base::StringPrintf("0x%d", entries[1].source.id), actual_item2.id);
EXPECT_EQ(std::string(1, TRACE_EVENT_PHASE_NESTABLE_ASYNC_BEGIN),
actual_item2.phase);
Expand All @@ -203,7 +207,7 @@ TEST_F(TraceNetLogObserverTest, TraceEventCaptured) {
EXPECT_EQ(NetLog::SourceTypeToString(entries[1].source.type),
actual_item2.source_type);

EXPECT_EQ("netlog", actual_item3.category);
EXPECT_EQ(kNetLogTracingCategory, actual_item3.category);
EXPECT_EQ(base::StringPrintf("0x%d", entries[2].source.id), actual_item3.id);
EXPECT_EQ(std::string(1, TRACE_EVENT_PHASE_NESTABLE_ASYNC_END),
actual_item3.phase);
Expand Down Expand Up @@ -236,7 +240,7 @@ TEST_F(TraceNetLogObserverTest, EnableAndDisableTracing) {

TraceEntryInfo actual_item1 = GetTraceEntryInfoFromValue(*item1);
TraceEntryInfo actual_item2 = GetTraceEntryInfoFromValue(*item2);
EXPECT_EQ("netlog", actual_item1.category);
EXPECT_EQ(kNetLogTracingCategory, actual_item1.category);
EXPECT_EQ(base::StringPrintf("0x%d", entries[0].source.id), actual_item1.id);
EXPECT_EQ(std::string(1, TRACE_EVENT_PHASE_NESTABLE_ASYNC_INSTANT),
actual_item1.phase);
Expand All @@ -245,7 +249,7 @@ TEST_F(TraceNetLogObserverTest, EnableAndDisableTracing) {
EXPECT_EQ(NetLog::SourceTypeToString(entries[0].source.type),
actual_item1.source_type);

EXPECT_EQ("netlog", actual_item2.category);
EXPECT_EQ(kNetLogTracingCategory, actual_item2.category);
EXPECT_EQ(base::StringPrintf("0x%d", entries[2].source.id), actual_item2.id);
EXPECT_EQ(std::string(1, TRACE_EVENT_PHASE_NESTABLE_ASYNC_INSTANT),
actual_item2.phase);
Expand Down Expand Up @@ -274,7 +278,7 @@ TEST_F(TraceNetLogObserverTest, DestroyObserverWhileTracing) {
ASSERT_TRUE(trace_events()->GetDictionary(0, &item1));

TraceEntryInfo actual_item1 = GetTraceEntryInfoFromValue(*item1);
EXPECT_EQ("netlog", actual_item1.category);
EXPECT_EQ(kNetLogTracingCategory, actual_item1.category);
EXPECT_EQ(base::StringPrintf("0x%d", entries[0].source.id), actual_item1.id);
EXPECT_EQ(std::string(1, TRACE_EVENT_PHASE_NESTABLE_ASYNC_INSTANT),
actual_item1.phase);
Expand Down Expand Up @@ -342,7 +346,7 @@ TEST_F(TraceNetLogObserverTest, EventsWithAndWithoutParameters) {

TraceEntryInfo actual_item1 = GetTraceEntryInfoFromValue(*item1);
TraceEntryInfo actual_item2 = GetTraceEntryInfoFromValue(*item2);
EXPECT_EQ("netlog", actual_item1.category);
EXPECT_EQ(kNetLogTracingCategory, actual_item1.category);
EXPECT_EQ(base::StringPrintf("0x%d", entries[0].source.id), actual_item1.id);
EXPECT_EQ(std::string(1, TRACE_EVENT_PHASE_NESTABLE_ASYNC_INSTANT),
actual_item1.phase);
Expand All @@ -351,7 +355,7 @@ TEST_F(TraceNetLogObserverTest, EventsWithAndWithoutParameters) {
EXPECT_EQ(NetLog::SourceTypeToString(entries[0].source.type),
actual_item1.source_type);

EXPECT_EQ("netlog", actual_item2.category);
EXPECT_EQ(kNetLogTracingCategory, actual_item2.category);
EXPECT_EQ(base::StringPrintf("0x%d", entries[1].source.id), actual_item2.id);
EXPECT_EQ(std::string(1, TRACE_EVENT_PHASE_NESTABLE_ASYNC_INSTANT),
actual_item2.phase);
Expand Down

0 comments on commit 1d2e6f5

Please sign in to comment.