andrew@webrtc.org | b87cc85 | 2013-03-25 16:23:37 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | #ifndef WEBRTC_TEST_TEST_SUPPORT_TRACE_TO_STDERR_H_ |
| 12 | #define WEBRTC_TEST_TEST_SUPPORT_TRACE_TO_STDERR_H_ |
| 13 | |
Henrik Kjellander | 98f5351 | 2015-10-28 18:17:40 +0100 | [diff] [blame] | 14 | #include "webrtc/system_wrappers/include/trace.h" |
andrew@webrtc.org | b87cc85 | 2013-03-25 16:23:37 +0000 | [diff] [blame] | 15 | |
| 16 | namespace webrtc { |
| 17 | namespace test { |
| 18 | |
| 19 | // Upon constructing an instance of this class, all traces will be redirected |
| 20 | // to stderr. At destruction, redirection is halted. |
| 21 | class TraceToStderr : public TraceCallback { |
| 22 | public: |
| 23 | TraceToStderr(); |
andrew@webrtc.org | 59aaebc | 2013-05-05 19:44:19 +0000 | [diff] [blame] | 24 | // Set |override_time| to true to control the time printed with each trace |
| 25 | // through SetTimeSeconds(). Otherwise, the trace's usual wallclock time is |
| 26 | // used. |
| 27 | // |
| 28 | // This is useful for offline test tools, where the file time is much more |
| 29 | // informative than the real time. |
| 30 | explicit TraceToStderr(bool override_time); |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 31 | ~TraceToStderr() override; |
andrew@webrtc.org | b87cc85 | 2013-03-25 16:23:37 +0000 | [diff] [blame] | 32 | |
andrew@webrtc.org | 59aaebc | 2013-05-05 19:44:19 +0000 | [diff] [blame] | 33 | // Every subsequent trace printout will use |time|. Has no effect if |
| 34 | // |override_time| in the constructor was set to false. |
| 35 | // |
| 36 | // No attempt is made to ensure thread-safety between the trace writing and |
| 37 | // time updating. In tests, since traces will normally be triggered by the |
| 38 | // main thread doing the time updating, this should be of no concern. |
pbos@webrtc.org | e6c3966 | 2013-07-30 13:08:38 +0000 | [diff] [blame] | 39 | virtual void SetTimeSeconds(float time); |
andrew@webrtc.org | 59aaebc | 2013-05-05 19:44:19 +0000 | [diff] [blame] | 40 | |
| 41 | // Implements TraceCallback. |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 42 | void Print(TraceLevel level, const char* msg_array, int length) override; |
andrew@webrtc.org | 59aaebc | 2013-05-05 19:44:19 +0000 | [diff] [blame] | 43 | |
| 44 | private: |
| 45 | bool override_time_; |
| 46 | float time_seconds_; |
andrew@webrtc.org | b87cc85 | 2013-03-25 16:23:37 +0000 | [diff] [blame] | 47 | }; |
| 48 | |
| 49 | } // namespace test |
| 50 | } // namespace webrtc |
| 51 | |
| 52 | #endif // WEBRTC_TEST_TEST_SUPPORT_TRACE_TO_STDERR_H_ |