OLD | NEW |
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/checks.h" |
21 #include "webrtc/base/format_macros.h" | 22 #include "webrtc/base/format_macros.h" |
22 #include "webrtc/base/platform_thread.h" | 23 #include "webrtc/base/platform_thread.h" |
23 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" | 24 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" |
24 | 25 |
25 namespace webrtc { | 26 namespace webrtc { |
26 namespace testing { | 27 namespace testing { |
27 namespace bwe { | 28 namespace bwe { |
28 | 29 |
29 Logging Logging::g_Logging; | 30 Logging Logging::g_Logging; |
30 | 31 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 } | 73 } |
73 | 74 |
74 void Logging::SetGlobalEnable(bool enabled) { | 75 void Logging::SetGlobalEnable(bool enabled) { |
75 CriticalSectionScoped cs(crit_sect_.get()); | 76 CriticalSectionScoped cs(crit_sect_.get()); |
76 thread_map_[rtc::CurrentThreadId()].global_state.enabled = enabled; | 77 thread_map_[rtc::CurrentThreadId()].global_state.enabled = enabled; |
77 } | 78 } |
78 | 79 |
79 void Logging::Log(const char format[], ...) { | 80 void Logging::Log(const char format[], ...) { |
80 CriticalSectionScoped cs(crit_sect_.get()); | 81 CriticalSectionScoped cs(crit_sect_.get()); |
81 ThreadMap::iterator it = thread_map_.find(rtc::CurrentThreadId()); | 82 ThreadMap::iterator it = thread_map_.find(rtc::CurrentThreadId()); |
82 assert(it != thread_map_.end()); | 83 RTC_DCHECK(it != thread_map_.end()); |
83 const State& state = it->second.stack.top(); | 84 const State& state = it->second.stack.top(); |
84 if (state.enabled) { | 85 if (state.enabled) { |
85 printf("%s\t", state.tag.c_str()); | 86 printf("%s\t", state.tag.c_str()); |
86 va_list args; | 87 va_list args; |
87 va_start(args, format); | 88 va_start(args, format); |
88 vprintf(format, args); | 89 vprintf(format, args); |
89 va_end(args); | 90 va_end(args); |
90 printf("\n"); | 91 printf("\n"); |
91 } | 92 } |
92 } | 93 } |
(...skipping 16 matching lines...) Expand all Loading... |
109 Plot(figure, name, value, 0, alg_name); | 110 Plot(figure, name, value, 0, alg_name); |
110 } | 111 } |
111 | 112 |
112 void Logging::Plot(int figure, | 113 void Logging::Plot(int figure, |
113 const std::string& name, | 114 const std::string& name, |
114 double value, | 115 double value, |
115 uint32_t ssrc, | 116 uint32_t ssrc, |
116 const std::string& alg_name) { | 117 const std::string& alg_name) { |
117 CriticalSectionScoped cs(crit_sect_.get()); | 118 CriticalSectionScoped cs(crit_sect_.get()); |
118 ThreadMap::iterator it = thread_map_.find(rtc::CurrentThreadId()); | 119 ThreadMap::iterator it = thread_map_.find(rtc::CurrentThreadId()); |
119 assert(it != thread_map_.end()); | 120 RTC_DCHECK(it != thread_map_.end()); |
120 const State& state = it->second.stack.top(); | 121 const State& state = it->second.stack.top(); |
121 if (state.enabled) { | 122 if (state.enabled) { |
122 printf("PLOT\t%d\t%s:%" PRIu32 "@%s\t%f\t%f\n", figure, name.c_str(), ssrc, | 123 printf("PLOT\t%d\t%s:%" PRIu32 "@%s\t%f\t%f\n", figure, name.c_str(), ssrc, |
123 alg_name.c_str(), state.timestamp_ms * 0.001, value); | 124 alg_name.c_str(), state.timestamp_ms * 0.001, value); |
124 } | 125 } |
125 } | 126 } |
126 | 127 |
127 void Logging::PlotBar(int figure, | 128 void Logging::PlotBar(int figure, |
128 const std::string& name, | 129 const std::string& name, |
129 double value, | 130 double value, |
130 int flow_id) { | 131 int flow_id) { |
131 CriticalSectionScoped cs(crit_sect_.get()); | 132 CriticalSectionScoped cs(crit_sect_.get()); |
132 ThreadMap::iterator it = thread_map_.find(rtc::CurrentThreadId()); | 133 ThreadMap::iterator it = thread_map_.find(rtc::CurrentThreadId()); |
133 assert(it != thread_map_.end()); | 134 RTC_DCHECK(it != thread_map_.end()); |
134 const State& state = it->second.stack.top(); | 135 const State& state = it->second.stack.top(); |
135 if (state.enabled) { | 136 if (state.enabled) { |
136 printf("BAR\t%d\t%s_%d\t%f\n", figure, name.c_str(), flow_id, value); | 137 printf("BAR\t%d\t%s_%d\t%f\n", figure, name.c_str(), flow_id, value); |
137 } | 138 } |
138 } | 139 } |
139 | 140 |
140 void Logging::PlotBaselineBar(int figure, | 141 void Logging::PlotBaselineBar(int figure, |
141 const std::string& name, | 142 const std::string& name, |
142 double value, | 143 double value, |
143 int flow_id) { | 144 int flow_id) { |
144 CriticalSectionScoped cs(crit_sect_.get()); | 145 CriticalSectionScoped cs(crit_sect_.get()); |
145 ThreadMap::iterator it = thread_map_.find(rtc::CurrentThreadId()); | 146 ThreadMap::iterator it = thread_map_.find(rtc::CurrentThreadId()); |
146 assert(it != thread_map_.end()); | 147 RTC_DCHECK(it != thread_map_.end()); |
147 const State& state = it->second.stack.top(); | 148 const State& state = it->second.stack.top(); |
148 if (state.enabled) { | 149 if (state.enabled) { |
149 printf("BASELINE\t%d\t%s_%d\t%f\n", figure, name.c_str(), flow_id, value); | 150 printf("BASELINE\t%d\t%s_%d\t%f\n", figure, name.c_str(), flow_id, value); |
150 } | 151 } |
151 } | 152 } |
152 | 153 |
153 void Logging::PlotErrorBar(int figure, | 154 void Logging::PlotErrorBar(int figure, |
154 const std::string& name, | 155 const std::string& name, |
155 double value, | 156 double value, |
156 double ylow, | 157 double ylow, |
157 double yhigh, | 158 double yhigh, |
158 const std::string& error_title, | 159 const std::string& error_title, |
159 int flow_id) { | 160 int flow_id) { |
160 CriticalSectionScoped cs(crit_sect_.get()); | 161 CriticalSectionScoped cs(crit_sect_.get()); |
161 ThreadMap::iterator it = thread_map_.find(rtc::CurrentThreadId()); | 162 ThreadMap::iterator it = thread_map_.find(rtc::CurrentThreadId()); |
162 assert(it != thread_map_.end()); | 163 RTC_DCHECK(it != thread_map_.end()); |
163 const State& state = it->second.stack.top(); | 164 const State& state = it->second.stack.top(); |
164 if (state.enabled) { | 165 if (state.enabled) { |
165 printf("ERRORBAR\t%d\t%s_%d\t%f\t%f\t%f\t%s\n", figure, name.c_str(), | 166 printf("ERRORBAR\t%d\t%s_%d\t%f\t%f\t%f\t%s\n", figure, name.c_str(), |
166 flow_id, value, ylow, yhigh, error_title.c_str()); | 167 flow_id, value, ylow, yhigh, error_title.c_str()); |
167 } | 168 } |
168 } | 169 } |
169 | 170 |
170 void Logging::PlotLimitErrorBar(int figure, | 171 void Logging::PlotLimitErrorBar(int figure, |
171 const std::string& name, | 172 const std::string& name, |
172 double value, | 173 double value, |
173 double ylow, | 174 double ylow, |
174 double yhigh, | 175 double yhigh, |
175 const std::string& error_title, | 176 const std::string& error_title, |
176 double ymax, | 177 double ymax, |
177 const std::string& limit_title, | 178 const std::string& limit_title, |
178 int flow_id) { | 179 int flow_id) { |
179 CriticalSectionScoped cs(crit_sect_.get()); | 180 CriticalSectionScoped cs(crit_sect_.get()); |
180 ThreadMap::iterator it = thread_map_.find(rtc::CurrentThreadId()); | 181 ThreadMap::iterator it = thread_map_.find(rtc::CurrentThreadId()); |
181 assert(it != thread_map_.end()); | 182 RTC_DCHECK(it != thread_map_.end()); |
182 const State& state = it->second.stack.top(); | 183 const State& state = it->second.stack.top(); |
183 if (state.enabled) { | 184 if (state.enabled) { |
184 printf("LIMITERRORBAR\t%d\t%s_%d\t%f\t%f\t%f\t%s\t%f\t%s\n", figure, | 185 printf("LIMITERRORBAR\t%d\t%s_%d\t%f\t%f\t%f\t%s\t%f\t%s\n", figure, |
185 name.c_str(), flow_id, value, ylow, yhigh, error_title.c_str(), ymax, | 186 name.c_str(), flow_id, value, ylow, yhigh, error_title.c_str(), ymax, |
186 limit_title.c_str()); | 187 limit_title.c_str()); |
187 } | 188 } |
188 } | 189 } |
189 | 190 |
190 void Logging::PlotLabel(int figure, | 191 void Logging::PlotLabel(int figure, |
191 const std::string& title, | 192 const std::string& title, |
192 const std::string& y_label, | 193 const std::string& y_label, |
193 int num_flows) { | 194 int num_flows) { |
194 CriticalSectionScoped cs(crit_sect_.get()); | 195 CriticalSectionScoped cs(crit_sect_.get()); |
195 ThreadMap::iterator it = thread_map_.find(rtc::CurrentThreadId()); | 196 ThreadMap::iterator it = thread_map_.find(rtc::CurrentThreadId()); |
196 assert(it != thread_map_.end()); | 197 RTC_DCHECK(it != thread_map_.end()); |
197 const State& state = it->second.stack.top(); | 198 const State& state = it->second.stack.top(); |
198 if (state.enabled) { | 199 if (state.enabled) { |
199 printf("LABEL\t%d\t%s\t%s\t%d\n", figure, title.c_str(), y_label.c_str(), | 200 printf("LABEL\t%d\t%s\t%s\t%d\n", figure, title.c_str(), y_label.c_str(), |
200 num_flows); | 201 num_flows); |
201 } | 202 } |
202 } | 203 } |
203 | 204 |
204 Logging::Logging() | 205 Logging::Logging() |
205 : crit_sect_(CriticalSectionWrapper::CreateCriticalSection()), | 206 : crit_sect_(CriticalSectionWrapper::CreateCriticalSection()), |
206 thread_map_() { | 207 thread_map_() { |
(...skipping 28 matching lines...) Expand all Loading... |
235 new_state.MergePrevious(thread_state->global_state); | 236 new_state.MergePrevious(thread_state->global_state); |
236 } else { | 237 } else { |
237 new_state.MergePrevious(stack->top()); | 238 new_state.MergePrevious(stack->top()); |
238 } | 239 } |
239 stack->push(new_state); | 240 stack->push(new_state); |
240 } | 241 } |
241 | 242 |
242 void Logging::PopState() { | 243 void Logging::PopState() { |
243 CriticalSectionScoped cs(crit_sect_.get()); | 244 CriticalSectionScoped cs(crit_sect_.get()); |
244 ThreadMap::iterator it = thread_map_.find(rtc::CurrentThreadId()); | 245 ThreadMap::iterator it = thread_map_.find(rtc::CurrentThreadId()); |
245 assert(it != thread_map_.end()); | 246 RTC_DCHECK(it != thread_map_.end()); |
246 std::stack<State>* stack = &it->second.stack; | 247 std::stack<State>* stack = &it->second.stack; |
247 int64_t newest_timestamp_ms = stack->top().timestamp_ms; | 248 int64_t newest_timestamp_ms = stack->top().timestamp_ms; |
248 stack->pop(); | 249 stack->pop(); |
249 if (!stack->empty()) { | 250 if (!stack->empty()) { |
250 State* state = &stack->top(); | 251 State* state = &stack->top(); |
251 // Update time so that next log/plot will use the latest time seen so far | 252 // Update time so that next log/plot will use the latest time seen so far |
252 // in this call tree. | 253 // in this call tree. |
253 state->timestamp_ms = std::max(state->timestamp_ms, newest_timestamp_ms); | 254 state->timestamp_ms = std::max(state->timestamp_ms, newest_timestamp_ms); |
254 } | 255 } |
255 } | 256 } |
256 } // namespace bwe | 257 } // namespace bwe |
257 } // namespace testing | 258 } // namespace testing |
258 } // namespace webrtc | 259 } // namespace webrtc |
259 | 260 |
260 #endif // BWE_TEST_LOGGING_COMPILE_TIME_ENABLE | 261 #endif // BWE_TEST_LOGGING_COMPILE_TIME_ENABLE |
OLD | NEW |