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

Side by Side Diff: base/debug/trace_event_unittest.cc

Issue 13590005: Add a ConvertableToTraceFormat type to the trace framework. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 8 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
« no previous file with comments | « base/debug/trace_event_impl.cc ('k') | content/renderer/render_thread_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/debug/trace_event_unittest.h" 5 #include "base/debug/trace_event_unittest.h"
6 6
7 #include <cstdlib> 7 #include <cstdlib>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 1573 matching lines...) Expand 10 before | Expand all | Expand 10 after
1584 TRACE_EVENT_SAMPLE_STATE(1, "cc", "Things"); 1584 TRACE_EVENT_SAMPLE_STATE(1, "cc", "Things");
1585 sampled->Wait(); 1585 sampled->Wait();
1586 1586
1587 EndTraceAndFlush(); 1587 EndTraceAndFlush();
1588 1588
1589 // Make sure we hit at least once. 1589 // Make sure we hit at least once.
1590 EXPECT_TRUE(FindNamePhase("Stuff", "P")); 1590 EXPECT_TRUE(FindNamePhase("Stuff", "P"));
1591 EXPECT_TRUE(FindNamePhase("Things", "P")); 1591 EXPECT_TRUE(FindNamePhase("Things", "P"));
1592 } 1592 }
1593 1593
1594 class MyData : public base::debug::ConvertableToTraceFormat {
1595 public:
1596 MyData() {}
1597 virtual ~MyData() {}
1598
1599 virtual void AppendAsTraceFormat(std::string* out) const OVERRIDE {
1600 out->append("{\"foo\":1}");
1601 }
1602
1603 private:
1604 DISALLOW_COPY_AND_ASSIGN(MyData);
1605 };
1606
1607 TEST_F(TraceEventTestFixture, ConvertableTypes) {
1608 ManualTestSetUp();
1609 TraceLog::GetInstance()->SetEnabled(true, TraceLog::RECORD_UNTIL_FULL);
1610
1611 scoped_ptr<MyData> data(new MyData());
1612 TRACE_EVENT1("foo", "bar", "data",
1613 data.PassAs<base::debug::ConvertableToTraceFormat>());
1614 EndTraceAndFlush();
1615
1616 DictionaryValue* dict = FindNamePhase("bar", "B");
1617 ASSERT_TRUE(dict);
1618
1619 const DictionaryValue* args_dict = NULL;
1620 dict->GetDictionary("args", &args_dict);
1621 ASSERT_TRUE(args_dict);
1622
1623 const Value* value = NULL;
1624 const DictionaryValue* convertable_dict = NULL;
1625 EXPECT_TRUE(args_dict->Get("data", &value));
1626 ASSERT_TRUE(value->GetAsDictionary(&convertable_dict));
1627
1628 int foo_val;
1629 EXPECT_TRUE(convertable_dict->GetInteger("foo", &foo_val));
1630 EXPECT_EQ(1, foo_val);
1631 }
1632
1633
1594 class TraceEventCallbackTest : public TraceEventTestFixture { 1634 class TraceEventCallbackTest : public TraceEventTestFixture {
1595 public: 1635 public:
1596 virtual void SetUp() OVERRIDE { 1636 virtual void SetUp() OVERRIDE {
1597 TraceEventTestFixture::SetUp(); 1637 TraceEventTestFixture::SetUp();
1598 ManualTestSetUp(); 1638 ManualTestSetUp();
1599 ASSERT_EQ(NULL, s_instance); 1639 ASSERT_EQ(NULL, s_instance);
1600 s_instance = this; 1640 s_instance = this;
1601 } 1641 }
1602 virtual void TearDown() OVERRIDE { 1642 virtual void TearDown() OVERRIDE {
1603 while (TraceLog::GetInstance()->IsEnabled()) 1643 while (TraceLog::GetInstance()->IsEnabled())
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1638 TRACE_EVENT_SCOPE_GLOBAL); 1678 TRACE_EVENT_SCOPE_GLOBAL);
1639 EXPECT_EQ(2u, collected_events_.size()); 1679 EXPECT_EQ(2u, collected_events_.size());
1640 EXPECT_EQ("event1", collected_events_[0]); 1680 EXPECT_EQ("event1", collected_events_[0]);
1641 EXPECT_EQ("event2", collected_events_[1]); 1681 EXPECT_EQ("event2", collected_events_[1]);
1642 } 1682 }
1643 1683
1644 // TODO(dsinclair): Continuous Tracing unit test. 1684 // TODO(dsinclair): Continuous Tracing unit test.
1645 1685
1646 } // namespace debug 1686 } // namespace debug
1647 } // namespace base 1687 } // namespace base
OLDNEW
« no previous file with comments | « base/debug/trace_event_impl.cc ('k') | content/renderer/render_thread_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698