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

Side by Side Diff: base/threading/thread_perftest.cc

Issue 1122153002: Fixit: Fork base::TimeTicks --> TimeTicks + ThreadTicks + TraceTicks (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@FIXIT_timeclasses_1of2
Patch Set: REBASE after it passed CQ but did not commit to tree Created 5 years, 6 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/message_loop/message_pump_perftest.cc ('k') | base/time/time.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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/base_switches.h" 5 #include "base/base_switches.h"
6 #include "base/bind.h" 6 #include "base/bind.h"
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/memory/scoped_vector.h" 9 #include "base/memory/scoped_vector.h"
10 #include "base/single_thread_task_runner.h" 10 #include "base/single_thread_task_runner.h"
(...skipping 30 matching lines...) Expand all
41 switches::kProfilerTimingDisabledValue); 41 switches::kProfilerTimingDisabledValue);
42 } 42 }
43 43
44 // To be implemented by each test. Subclass must uses threads_ such that 44 // To be implemented by each test. Subclass must uses threads_ such that
45 // their cpu-time can be measured. Test must return from PingPong() _and_ 45 // their cpu-time can be measured. Test must return from PingPong() _and_
46 // call FinishMeasurement from any thread to complete the test. 46 // call FinishMeasurement from any thread to complete the test.
47 virtual void Init() {} 47 virtual void Init() {}
48 virtual void PingPong(int hops) = 0; 48 virtual void PingPong(int hops) = 0;
49 virtual void Reset() {} 49 virtual void Reset() {}
50 50
51 void TimeOnThread(base::TimeTicks* ticks, base::WaitableEvent* done) { 51 void TimeOnThread(base::ThreadTicks* ticks, base::WaitableEvent* done) {
52 *ticks = base::TimeTicks::ThreadNow(); 52 *ticks = base::ThreadTicks::Now();
53 done->Signal(); 53 done->Signal();
54 } 54 }
55 55
56 base::TimeTicks ThreadNow(base::Thread* thread) { 56 base::ThreadTicks ThreadNow(base::Thread* thread) {
57 base::WaitableEvent done(false, false); 57 base::WaitableEvent done(false, false);
58 base::TimeTicks ticks; 58 base::ThreadTicks ticks;
59 thread->task_runner()->PostTask( 59 thread->task_runner()->PostTask(
60 FROM_HERE, base::Bind(&ThreadPerfTest::TimeOnThread, 60 FROM_HERE, base::Bind(&ThreadPerfTest::TimeOnThread,
61 base::Unretained(this), &ticks, &done)); 61 base::Unretained(this), &ticks, &done));
62 done.Wait(); 62 done.Wait();
63 return ticks; 63 return ticks;
64 } 64 }
65 65
66 void RunPingPongTest(const std::string& name, unsigned num_threads) { 66 void RunPingPongTest(const std::string& name, unsigned num_threads) {
67 // Create threads and collect starting cpu-time for each thread. 67 // Create threads and collect starting cpu-time for each thread.
68 std::vector<base::TimeTicks> thread_starts; 68 std::vector<base::ThreadTicks> thread_starts;
69 while (threads_.size() < num_threads) { 69 while (threads_.size() < num_threads) {
70 threads_.push_back(new base::Thread("PingPonger")); 70 threads_.push_back(new base::Thread("PingPonger"));
71 threads_.back()->Start(); 71 threads_.back()->Start();
72 if (base::TimeTicks::IsThreadNowSupported()) 72 if (base::ThreadTicks::IsSupported())
73 thread_starts.push_back(ThreadNow(threads_.back())); 73 thread_starts.push_back(ThreadNow(threads_.back()));
74 } 74 }
75 75
76 Init(); 76 Init();
77 77
78 base::TimeTicks start = base::TimeTicks::Now(); 78 base::TimeTicks start = base::TimeTicks::Now();
79 PingPong(kNumRuns); 79 PingPong(kNumRuns);
80 done_.Wait(); 80 done_.Wait();
81 base::TimeTicks end = base::TimeTicks::Now(); 81 base::TimeTicks end = base::TimeTicks::Now();
82 82
83 // Gather the cpu-time spent on each thread. This does one extra tasks, 83 // Gather the cpu-time spent on each thread. This does one extra tasks,
84 // but that should be in the noise given enough runs. 84 // but that should be in the noise given enough runs.
85 base::TimeDelta thread_time; 85 base::TimeDelta thread_time;
86 while (threads_.size()) { 86 while (threads_.size()) {
87 if (base::TimeTicks::IsThreadNowSupported()) { 87 if (base::ThreadTicks::IsSupported()) {
88 thread_time += ThreadNow(threads_.back()) - thread_starts.back(); 88 thread_time += ThreadNow(threads_.back()) - thread_starts.back();
89 thread_starts.pop_back(); 89 thread_starts.pop_back();
90 } 90 }
91 threads_.pop_back(); 91 threads_.pop_back();
92 } 92 }
93 93
94 Reset(); 94 Reset();
95 95
96 double num_runs = static_cast<double>(kNumRuns); 96 double num_runs = static_cast<double>(kNumRuns);
97 double us_per_task_clock = (end - start).InMicroseconds() / num_runs; 97 double us_per_task_clock = (end - start).InMicroseconds() / num_runs;
98 double us_per_task_cpu = thread_time.InMicroseconds() / num_runs; 98 double us_per_task_cpu = thread_time.InMicroseconds() / num_runs;
99 99
100 // Clock time per task. 100 // Clock time per task.
101 perf_test::PrintResult( 101 perf_test::PrintResult(
102 "task", "", name + "_time ", us_per_task_clock, "us/hop", true); 102 "task", "", name + "_time ", us_per_task_clock, "us/hop", true);
103 103
104 // Total utilization across threads if available (likely higher). 104 // Total utilization across threads if available (likely higher).
105 if (base::TimeTicks::IsThreadNowSupported()) { 105 if (base::ThreadTicks::IsSupported()) {
106 perf_test::PrintResult( 106 perf_test::PrintResult(
107 "task", "", name + "_cpu ", us_per_task_cpu, "us/hop", true); 107 "task", "", name + "_cpu ", us_per_task_cpu, "us/hop", true);
108 } 108 }
109 } 109 }
110 110
111 protected: 111 protected:
112 void FinishMeasurement() { done_.Signal(); } 112 void FinishMeasurement() { done_.Signal(); }
113 ScopedVector<base::Thread> threads_; 113 ScopedVector<base::Thread> threads_;
114 114
115 private: 115 private:
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 typedef EventPerfTest<PthreadEvent> PthreadEventPerfTest; 299 typedef EventPerfTest<PthreadEvent> PthreadEventPerfTest;
300 TEST_F(PthreadEventPerfTest, EventPingPong) { 300 TEST_F(PthreadEventPerfTest, EventPingPong) {
301 RunPingPongTest("4_PthreadCondVar_Threads", 4); 301 RunPingPongTest("4_PthreadCondVar_Threads", 4);
302 } 302 }
303 303
304 #endif 304 #endif
305 305
306 } // namespace 306 } // namespace
307 307
308 } // namespace base 308 } // namespace base
OLDNEW
« no previous file with comments | « base/message_loop/message_pump_perftest.cc ('k') | base/time/time.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698