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

Side by Side Diff: webrtc/modules/remote_bitrate_estimator/test/bwe_test_logging.cc

Issue 1469013002: Move ThreadWrapper to ProcessThread in base. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: remove duplicate win ThreadChecker Created 5 years, 1 month 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
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include "webrtc/modules/remote_bitrate_estimator/test/bwe_test_logging.h" 11 #include "webrtc/modules/remote_bitrate_estimator/test/bwe_test_logging.h"
12 12
13 #if BWE_TEST_LOGGING_COMPILE_TIME_ENABLE 13 #if BWE_TEST_LOGGING_COMPILE_TIME_ENABLE
14 14
15 #include <stdarg.h> 15 #include <stdarg.h>
16 #include <stdio.h> 16 #include <stdio.h>
17 17
18 #include <algorithm> 18 #include <algorithm>
19 #include <sstream> 19 #include <sstream>
20 20
21 #include "webrtc/base/platform_thread.h"
21 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" 22 #include "webrtc/system_wrappers/include/critical_section_wrapper.h"
22 #include "webrtc/system_wrappers/include/thread_wrapper.h"
23 23
24 namespace webrtc { 24 namespace webrtc {
25 namespace testing { 25 namespace testing {
26 namespace bwe { 26 namespace bwe {
27 27
28 Logging Logging::g_Logging; 28 Logging Logging::g_Logging;
29 29
30 static std::string ToString(uint32_t v) { 30 static std::string ToString(uint32_t v) {
31 std::stringstream ss; 31 std::stringstream ss;
32 ss << v; 32 ss << v;
(...skipping 17 matching lines...) Expand all
50 Logging::Context::~Context() { 50 Logging::Context::~Context() {
51 Logging::GetInstance()->PopState(); 51 Logging::GetInstance()->PopState();
52 } 52 }
53 53
54 Logging* Logging::GetInstance() { 54 Logging* Logging::GetInstance() {
55 return &g_Logging; 55 return &g_Logging;
56 } 56 }
57 57
58 void Logging::SetGlobalContext(uint32_t name) { 58 void Logging::SetGlobalContext(uint32_t name) {
59 CriticalSectionScoped cs(crit_sect_.get()); 59 CriticalSectionScoped cs(crit_sect_.get());
60 thread_map_[ThreadWrapper::GetThreadId()].global_state.tag = ToString(name); 60 thread_map_[PlatformThread::GetThreadId()].global_state.tag = ToString(name);
61 } 61 }
62 62
63 void Logging::SetGlobalContext(const std::string& name) { 63 void Logging::SetGlobalContext(const std::string& name) {
64 CriticalSectionScoped cs(crit_sect_.get()); 64 CriticalSectionScoped cs(crit_sect_.get());
65 thread_map_[ThreadWrapper::GetThreadId()].global_state.tag = name; 65 thread_map_[PlatformThread::GetThreadId()].global_state.tag = name;
66 } 66 }
67 67
68 void Logging::SetGlobalContext(const char* name) { 68 void Logging::SetGlobalContext(const char* name) {
69 CriticalSectionScoped cs(crit_sect_.get()); 69 CriticalSectionScoped cs(crit_sect_.get());
70 thread_map_[ThreadWrapper::GetThreadId()].global_state.tag = name; 70 thread_map_[PlatformThread::GetThreadId()].global_state.tag = name;
71 } 71 }
72 72
73 void Logging::SetGlobalEnable(bool enabled) { 73 void Logging::SetGlobalEnable(bool enabled) {
74 CriticalSectionScoped cs(crit_sect_.get()); 74 CriticalSectionScoped cs(crit_sect_.get());
75 thread_map_[ThreadWrapper::GetThreadId()].global_state.enabled = enabled; 75 thread_map_[PlatformThread::GetThreadId()].global_state.enabled = enabled;
76 } 76 }
77 77
78 void Logging::Log(const char format[], ...) { 78 void Logging::Log(const char format[], ...) {
79 CriticalSectionScoped cs(crit_sect_.get()); 79 CriticalSectionScoped cs(crit_sect_.get());
80 ThreadMap::iterator it = thread_map_.find(ThreadWrapper::GetThreadId()); 80 ThreadMap::iterator it = thread_map_.find(PlatformThread::GetThreadId());
81 assert(it != thread_map_.end()); 81 assert(it != thread_map_.end());
82 const State& state = it->second.stack.top(); 82 const State& state = it->second.stack.top();
83 if (state.enabled) { 83 if (state.enabled) {
84 printf("%s\t", state.tag.c_str()); 84 printf("%s\t", state.tag.c_str());
85 va_list args; 85 va_list args;
86 va_start(args, format); 86 va_start(args, format);
87 vprintf(format, args); 87 vprintf(format, args);
88 va_end(args); 88 va_end(args);
89 printf("\n"); 89 printf("\n");
90 } 90 }
91 } 91 }
92 92
93 void Logging::Plot(int figure, double value) { 93 void Logging::Plot(int figure, double value) {
94 Plot(figure, value, "-"); 94 Plot(figure, value, "-");
95 } 95 }
96 96
97 void Logging::Plot(int figure, double value, const std::string& alg_name) { 97 void Logging::Plot(int figure, double value, const std::string& alg_name) {
98 CriticalSectionScoped cs(crit_sect_.get()); 98 CriticalSectionScoped cs(crit_sect_.get());
99 ThreadMap::iterator it = thread_map_.find(ThreadWrapper::GetThreadId()); 99 ThreadMap::iterator it = thread_map_.find(PlatformThread::GetThreadId());
100 assert(it != thread_map_.end()); 100 assert(it != thread_map_.end());
101 const State& state = it->second.stack.top(); 101 const State& state = it->second.stack.top();
102 std::string label = state.tag + '@' + alg_name; 102 std::string label = state.tag + '@' + alg_name;
103 std::string prefix("Available"); 103 std::string prefix("Available");
104 if (alg_name.compare(0, prefix.length(), prefix) == 0) { 104 if (alg_name.compare(0, prefix.length(), prefix) == 0) {
105 std::string receiver("Receiver"); 105 std::string receiver("Receiver");
106 size_t start_pos = label.find(receiver); 106 size_t start_pos = label.find(receiver);
107 if (start_pos != std::string::npos) { 107 if (start_pos != std::string::npos) {
108 label.replace(start_pos, receiver.length(), "Sender"); 108 label.replace(start_pos, receiver.length(), "Sender");
109 } 109 }
110 } 110 }
111 if (state.enabled) { 111 if (state.enabled) {
112 printf("PLOT\t%d\t%s\t%f\t%f\n", figure, label.c_str(), 112 printf("PLOT\t%d\t%s\t%f\t%f\n", figure, label.c_str(),
113 state.timestamp_ms * 0.001, value); 113 state.timestamp_ms * 0.001, value);
114 } 114 }
115 } 115 }
116 116
117 void Logging::PlotBar(int figure, 117 void Logging::PlotBar(int figure,
118 const std::string& name, 118 const std::string& name,
119 double value, 119 double value,
120 int flow_id) { 120 int flow_id) {
121 CriticalSectionScoped cs(crit_sect_.get()); 121 CriticalSectionScoped cs(crit_sect_.get());
122 ThreadMap::iterator it = thread_map_.find(ThreadWrapper::GetThreadId()); 122 ThreadMap::iterator it = thread_map_.find(PlatformThread::GetThreadId());
123 assert(it != thread_map_.end()); 123 assert(it != thread_map_.end());
124 const State& state = it->second.stack.top(); 124 const State& state = it->second.stack.top();
125 if (state.enabled) { 125 if (state.enabled) {
126 printf("BAR\t%d\t%s_%d\t%f\n", figure, name.c_str(), flow_id, value); 126 printf("BAR\t%d\t%s_%d\t%f\n", figure, name.c_str(), flow_id, value);
127 } 127 }
128 } 128 }
129 129
130 void Logging::PlotBaselineBar(int figure, 130 void Logging::PlotBaselineBar(int figure,
131 const std::string& name, 131 const std::string& name,
132 double value, 132 double value,
133 int flow_id) { 133 int flow_id) {
134 CriticalSectionScoped cs(crit_sect_.get()); 134 CriticalSectionScoped cs(crit_sect_.get());
135 ThreadMap::iterator it = thread_map_.find(ThreadWrapper::GetThreadId()); 135 ThreadMap::iterator it = thread_map_.find(PlatformThread::GetThreadId());
136 assert(it != thread_map_.end()); 136 assert(it != thread_map_.end());
137 const State& state = it->second.stack.top(); 137 const State& state = it->second.stack.top();
138 if (state.enabled) { 138 if (state.enabled) {
139 printf("BASELINE\t%d\t%s_%d\t%f\n", figure, name.c_str(), flow_id, value); 139 printf("BASELINE\t%d\t%s_%d\t%f\n", figure, name.c_str(), flow_id, value);
140 } 140 }
141 } 141 }
142 142
143 void Logging::PlotErrorBar(int figure, 143 void Logging::PlotErrorBar(int figure,
144 const std::string& name, 144 const std::string& name,
145 double value, 145 double value,
146 double ylow, 146 double ylow,
147 double yhigh, 147 double yhigh,
148 const std::string& error_title, 148 const std::string& error_title,
149 int flow_id) { 149 int flow_id) {
150 CriticalSectionScoped cs(crit_sect_.get()); 150 CriticalSectionScoped cs(crit_sect_.get());
151 ThreadMap::iterator it = thread_map_.find(ThreadWrapper::GetThreadId()); 151 ThreadMap::iterator it = thread_map_.find(PlatformThread::GetThreadId());
152 assert(it != thread_map_.end()); 152 assert(it != thread_map_.end());
153 const State& state = it->second.stack.top(); 153 const State& state = it->second.stack.top();
154 if (state.enabled) { 154 if (state.enabled) {
155 printf("ERRORBAR\t%d\t%s_%d\t%f\t%f\t%f\t%s\n", figure, name.c_str(), 155 printf("ERRORBAR\t%d\t%s_%d\t%f\t%f\t%f\t%s\n", figure, name.c_str(),
156 flow_id, value, ylow, yhigh, error_title.c_str()); 156 flow_id, value, ylow, yhigh, error_title.c_str());
157 } 157 }
158 } 158 }
159 159
160 void Logging::PlotLimitErrorBar(int figure, 160 void Logging::PlotLimitErrorBar(int figure,
161 const std::string& name, 161 const std::string& name,
162 double value, 162 double value,
163 double ylow, 163 double ylow,
164 double yhigh, 164 double yhigh,
165 const std::string& error_title, 165 const std::string& error_title,
166 double ymax, 166 double ymax,
167 const std::string& limit_title, 167 const std::string& limit_title,
168 int flow_id) { 168 int flow_id) {
169 CriticalSectionScoped cs(crit_sect_.get()); 169 CriticalSectionScoped cs(crit_sect_.get());
170 ThreadMap::iterator it = thread_map_.find(ThreadWrapper::GetThreadId()); 170 ThreadMap::iterator it = thread_map_.find(PlatformThread::GetThreadId());
171 assert(it != thread_map_.end()); 171 assert(it != thread_map_.end());
172 const State& state = it->second.stack.top(); 172 const State& state = it->second.stack.top();
173 if (state.enabled) { 173 if (state.enabled) {
174 printf("LIMITERRORBAR\t%d\t%s_%d\t%f\t%f\t%f\t%s\t%f\t%s\n", figure, 174 printf("LIMITERRORBAR\t%d\t%s_%d\t%f\t%f\t%f\t%s\t%f\t%s\n", figure,
175 name.c_str(), flow_id, value, ylow, yhigh, error_title.c_str(), ymax, 175 name.c_str(), flow_id, value, ylow, yhigh, error_title.c_str(), ymax,
176 limit_title.c_str()); 176 limit_title.c_str());
177 } 177 }
178 } 178 }
179 179
180 void Logging::PlotLabel(int figure, 180 void Logging::PlotLabel(int figure,
181 const std::string& title, 181 const std::string& title,
182 const std::string& y_label, 182 const std::string& y_label,
183 int num_flows) { 183 int num_flows) {
184 CriticalSectionScoped cs(crit_sect_.get()); 184 CriticalSectionScoped cs(crit_sect_.get());
185 ThreadMap::iterator it = thread_map_.find(ThreadWrapper::GetThreadId()); 185 ThreadMap::iterator it = thread_map_.find(PlatformThread::GetThreadId());
186 assert(it != thread_map_.end()); 186 assert(it != thread_map_.end());
187 const State& state = it->second.stack.top(); 187 const State& state = it->second.stack.top();
188 if (state.enabled) { 188 if (state.enabled) {
189 printf("LABEL\t%d\t%s\t%s\t%d\n", figure, title.c_str(), y_label.c_str(), 189 printf("LABEL\t%d\t%s\t%s\t%d\n", figure, title.c_str(), y_label.c_str(),
190 num_flows); 190 num_flows);
191 } 191 }
192 } 192 }
193 193
194 Logging::Logging() 194 Logging::Logging()
195 : crit_sect_(CriticalSectionWrapper::CreateCriticalSection()), 195 : crit_sect_(CriticalSectionWrapper::CreateCriticalSection()),
(...skipping 16 matching lines...) Expand all
212 tag = previous.tag + "_" + tag; 212 tag = previous.tag + "_" + tag;
213 } 213 }
214 timestamp_ms = std::max(previous.timestamp_ms, timestamp_ms); 214 timestamp_ms = std::max(previous.timestamp_ms, timestamp_ms);
215 enabled = previous.enabled && enabled; 215 enabled = previous.enabled && enabled;
216 } 216 }
217 217
218 void Logging::PushState(const std::string& append_to_tag, int64_t timestamp_ms, 218 void Logging::PushState(const std::string& append_to_tag, int64_t timestamp_ms,
219 bool enabled) { 219 bool enabled) {
220 CriticalSectionScoped cs(crit_sect_.get()); 220 CriticalSectionScoped cs(crit_sect_.get());
221 State new_state(append_to_tag, timestamp_ms, enabled); 221 State new_state(append_to_tag, timestamp_ms, enabled);
222 ThreadState* thread_state = &thread_map_[ThreadWrapper::GetThreadId()]; 222 ThreadState* thread_state = &thread_map_[PlatformThread::GetThreadId()];
223 std::stack<State>* stack = &thread_state->stack; 223 std::stack<State>* stack = &thread_state->stack;
224 if (stack->empty()) { 224 if (stack->empty()) {
225 new_state.MergePrevious(thread_state->global_state); 225 new_state.MergePrevious(thread_state->global_state);
226 } else { 226 } else {
227 new_state.MergePrevious(stack->top()); 227 new_state.MergePrevious(stack->top());
228 } 228 }
229 stack->push(new_state); 229 stack->push(new_state);
230 } 230 }
231 231
232 void Logging::PopState() { 232 void Logging::PopState() {
233 CriticalSectionScoped cs(crit_sect_.get()); 233 CriticalSectionScoped cs(crit_sect_.get());
234 ThreadMap::iterator it = thread_map_.find(ThreadWrapper::GetThreadId()); 234 ThreadMap::iterator it = thread_map_.find(PlatformThread::GetThreadId());
235 assert(it != thread_map_.end()); 235 assert(it != thread_map_.end());
236 std::stack<State>* stack = &it->second.stack; 236 std::stack<State>* stack = &it->second.stack;
237 int64_t newest_timestamp_ms = stack->top().timestamp_ms; 237 int64_t newest_timestamp_ms = stack->top().timestamp_ms;
238 stack->pop(); 238 stack->pop();
239 if (!stack->empty()) { 239 if (!stack->empty()) {
240 State* state = &stack->top(); 240 State* state = &stack->top();
241 // Update time so that next log/plot will use the latest time seen so far 241 // Update time so that next log/plot will use the latest time seen so far
242 // in this call tree. 242 // in this call tree.
243 state->timestamp_ms = std::max(state->timestamp_ms, newest_timestamp_ms); 243 state->timestamp_ms = std::max(state->timestamp_ms, newest_timestamp_ms);
244 } 244 }
245 } 245 }
246 } // namespace bwe 246 } // namespace bwe
247 } // namespace testing 247 } // namespace testing
248 } // namespace webrtc 248 } // namespace webrtc
249 249
250 #endif // BWE_TEST_LOGGING_COMPILE_TIME_ENABLE 250 #endif // BWE_TEST_LOGGING_COMPILE_TIME_ENABLE
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698