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

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

Issue 23556003: Implement about:tracing UI for the sampling profiler (Chromium part) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « base/debug/trace_event_impl.cc ('k') | components/tracing/child_trace_message_filter.h » ('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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 } 83 }
84 84
85 void EndTraceAndFlush() { 85 void EndTraceAndFlush() {
86 while (TraceLog::GetInstance()->IsEnabled()) 86 while (TraceLog::GetInstance()->IsEnabled())
87 TraceLog::GetInstance()->SetDisabled(); 87 TraceLog::GetInstance()->SetDisabled();
88 TraceLog::GetInstance()->Flush( 88 TraceLog::GetInstance()->Flush(
89 base::Bind(&TraceEventTestFixture::OnTraceDataCollected, 89 base::Bind(&TraceEventTestFixture::OnTraceDataCollected,
90 base::Unretained(this))); 90 base::Unretained(this)));
91 } 91 }
92 92
93 void FlushContinuousSampling() {
94 TraceLog::GetInstance()->FlushContinuousSamplingTracing(
95 base::Bind(&TraceEventTestFixture::OnTraceDataCollected,
96 base::Unretained(this)));
97 }
98
93 virtual void SetUp() OVERRIDE { 99 virtual void SetUp() OVERRIDE {
94 const char* name = PlatformThread::GetName(); 100 const char* name = PlatformThread::GetName();
95 old_thread_name_ = name ? strdup(name) : NULL; 101 old_thread_name_ = name ? strdup(name) : NULL;
96 notifications_received_ = 0; 102 notifications_received_ = 0;
97 103
98 TraceLog::DeleteForTesting(); 104 TraceLog::DeleteForTesting();
99 TraceLog* tracelog = TraceLog::GetInstance(); 105 TraceLog* tracelog = TraceLog::GetInstance();
100 ASSERT_TRUE(tracelog); 106 ASSERT_TRUE(tracelog);
101 ASSERT_FALSE(tracelog->IsEnabled()); 107 ASSERT_FALSE(tracelog->IsEnabled());
102 tracelog->SetNotificationCallback( 108 tracelog->SetNotificationCallback(
(...skipping 1627 matching lines...) Expand 10 before | Expand all | Expand 10 after
1730 TRACE_EVENT_SET_SAMPLING_STATE("DDD", "name"); 1736 TRACE_EVENT_SET_SAMPLING_STATE("DDD", "name");
1731 sampled->Wait(); 1737 sampled->Wait();
1732 EXPECT_STREQ(TRACE_EVENT_GET_SAMPLING_STATE(), "DDD"); 1738 EXPECT_STREQ(TRACE_EVENT_GET_SAMPLING_STATE(), "DDD");
1733 } 1739 }
1734 sampled->Wait(); 1740 sampled->Wait();
1735 EXPECT_STREQ(TRACE_EVENT_GET_SAMPLING_STATE(), "DDD"); 1741 EXPECT_STREQ(TRACE_EVENT_GET_SAMPLING_STATE(), "DDD");
1736 1742
1737 EndTraceAndFlush(); 1743 EndTraceAndFlush();
1738 } 1744 }
1739 1745
1746 TEST_F(TraceEventTestFixture, TraceContinuousSampling) {
1747 event_watch_notification_ = 0;
1748 TraceLog::GetInstance()->SetContinuousSamplingEnabled();
1749
1750 WaitableEvent* sampled = new WaitableEvent(false, false);
1751 TraceLog::GetInstance()->InstallWaitableEventForContinuousSamplingTesting(
1752 sampled);
1753
1754 TRACE_EVENT_SET_SAMPLING_STATE_FOR_BUCKET(1, "category", "AAA");
1755 sampled->Wait();
1756 TRACE_EVENT_SET_SAMPLING_STATE_FOR_BUCKET(1, "category", "BBB");
1757 sampled->Wait();
1758
1759 FlushContinuousSampling();
1760
1761 // Make sure we can get the profiled data.
1762 EXPECT_TRUE(FindNamePhase("AAA", "P"));
1763 EXPECT_TRUE(FindNamePhase("BBB", "P"));
1764
1765 Clear();
1766
1767 TRACE_EVENT_SET_SAMPLING_STATE_FOR_BUCKET(1, "category", "CCC");
1768 sampled->Wait();
1769 TRACE_EVENT_SET_SAMPLING_STATE_FOR_BUCKET(1, "category", "DDD");
1770 sampled->Wait();
1771
1772 FlushContinuousSampling();
1773
1774 // Make sure the profiled data is accumulated.
1775 EXPECT_TRUE(FindNamePhase("AAA", "P"));
1776 EXPECT_TRUE(FindNamePhase("BBB", "P"));
1777 EXPECT_TRUE(FindNamePhase("CCC", "P"));
1778 EXPECT_TRUE(FindNamePhase("DDD", "P"));
1779
1780 Clear();
1781
1782 TraceLog::GetInstance()->SetContinuousSamplingDisabled();
1783
1784 FlushContinuousSampling();
1785
1786 // Make sure disabling the continuous sampling thread clears
1787 // the profiled data.
1788 EXPECT_FALSE(FindNamePhase("AAA", "P"));
1789 EXPECT_FALSE(FindNamePhase("BBB", "P"));
1790 EXPECT_FALSE(FindNamePhase("CCC", "P"));
1791 EXPECT_FALSE(FindNamePhase("DDD", "P"));
1792
1793 Clear();
1794 }
1795
1740 class MyData : public base::debug::ConvertableToTraceFormat { 1796 class MyData : public base::debug::ConvertableToTraceFormat {
1741 public: 1797 public:
1742 MyData() {} 1798 MyData() {}
1743 virtual ~MyData() {} 1799 virtual ~MyData() {}
1744 1800
1745 virtual void AppendAsTraceFormat(std::string* out) const OVERRIDE { 1801 virtual void AppendAsTraceFormat(std::string* out) const OVERRIDE {
1746 out->append("{\"foo\":1}"); 1802 out->append("{\"foo\":1}");
1747 } 1803 }
1748 1804
1749 private: 1805 private:
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
2015 EXPECT_TRUE(CategoryFilter::IsEmptyOrContainsLeadingOrTrailingWhitespace( 2071 EXPECT_TRUE(CategoryFilter::IsEmptyOrContainsLeadingOrTrailingWhitespace(
2016 " bad_category ")); 2072 " bad_category "));
2017 EXPECT_TRUE(CategoryFilter::IsEmptyOrContainsLeadingOrTrailingWhitespace( 2073 EXPECT_TRUE(CategoryFilter::IsEmptyOrContainsLeadingOrTrailingWhitespace(
2018 "")); 2074 ""));
2019 EXPECT_FALSE(CategoryFilter::IsEmptyOrContainsLeadingOrTrailingWhitespace( 2075 EXPECT_FALSE(CategoryFilter::IsEmptyOrContainsLeadingOrTrailingWhitespace(
2020 "good_category")); 2076 "good_category"));
2021 } 2077 }
2022 2078
2023 } // namespace debug 2079 } // namespace debug
2024 } // namespace base 2080 } // namespace base
OLDNEW
« no previous file with comments | « base/debug/trace_event_impl.cc ('k') | components/tracing/child_trace_message_filter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698