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

Side by Side Diff: webrtc/logging/rtc_event_log/rtc_event_log_helper_thread.h

Issue 3007193002: Revert of Make RtcEventLogImpl to use a TaskQueue instead of a helper-thread (Closed)
Patch Set: Created 3 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
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2016 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_LOGGING_RTC_EVENT_LOG_RTC_EVENT_LOG_HELPER_THREAD_H_
12 #define WEBRTC_LOGGING_RTC_EVENT_LOG_RTC_EVENT_LOG_HELPER_THREAD_H_
13
14 #include <deque>
15 #include <limits>
16 #include <memory>
17 #include <utility>
18 #include <vector>
19
20 #include "webrtc/rtc_base/constructormagic.h"
21 #include "webrtc/rtc_base/event.h"
22 #include "webrtc/rtc_base/ignore_wundef.h"
23 #include "webrtc/rtc_base/platform_thread.h"
24 #include "webrtc/rtc_base/protobuf_utils.h"
25 #include "webrtc/rtc_base/swap_queue.h"
26 #include "webrtc/system_wrappers/include/file_wrapper.h"
27
28 #ifdef ENABLE_RTC_EVENT_LOG
29 // *.ph.h files are generated at build-time by the protobuf compiler.
30 RTC_PUSH_IGNORING_WUNDEF()
31 #ifdef WEBRTC_ANDROID_PLATFORM_BUILD
32 #include "external/webrtc/webrtc/logging/rtc_event_log/rtc_event_log.pb.h"
33 #else
34 #include "webrtc/logging/rtc_event_log/rtc_event_log.pb.h"
35 #endif
36 RTC_POP_IGNORING_WUNDEF()
37 #endif
38
39 #ifdef ENABLE_RTC_EVENT_LOG
40
41 namespace webrtc {
42
43 class RtcEventLogHelperThread final {
44 public:
45 struct ControlMessage {
46 ControlMessage()
47 : message_type(STOP_FILE),
48 file(nullptr),
49 max_size_bytes(0),
50 start_time(0),
51 stop_time(0) {}
52 enum { START_FILE, STOP_FILE, TERMINATE_THREAD } message_type;
53
54 std::unique_ptr<FileWrapper> file; // Only used with START_FILE.
55 int64_t max_size_bytes; // Only used with START_FILE.
56 int64_t start_time; // Only used with START_FILE.
57 int64_t stop_time; // Used with all 3 message types.
58
59 friend void swap(ControlMessage& lhs, ControlMessage& rhs) {
60 using std::swap;
61 swap(lhs.message_type, rhs.message_type);
62 lhs.file.swap(rhs.file);
63 swap(lhs.max_size_bytes, rhs.max_size_bytes);
64 swap(lhs.start_time, rhs.start_time);
65 swap(lhs.stop_time, rhs.stop_time);
66 }
67 };
68
69 RtcEventLogHelperThread(
70 SwapQueue<ControlMessage>* message_queue,
71 SwapQueue<std::unique_ptr<rtclog::Event>>* event_queue);
72 ~RtcEventLogHelperThread();
73
74 // This function MUST be called once a STOP_FILE message is added to the
75 // signalling queue. The function will make sure that the output thread
76 // wakes up to read the message, and it blocks until the output thread has
77 // finished writing to the file.
78 void WaitForFileFinished();
79
80 // This fuction MUST be called once an event is added to the event queue.
81 void SignalNewEvent();
82
83 private:
84 static void ThreadOutputFunction(void* obj);
85
86 bool AppendEventToString(rtclog::Event* event);
87 bool LogToMemory();
88 void StartLogFile();
89 bool LogToFile();
90 void StopLogFile();
91 void ProcessEvents();
92
93 // Message queues for passing events to the logging thread.
94 SwapQueue<ControlMessage>* message_queue_;
95 SwapQueue<std::unique_ptr<rtclog::Event>>* event_queue_;
96
97 // History containing the most recent events (~ 10 s).
98 std::deque<std::unique_ptr<rtclog::Event>> history_;
99
100 // History containing all past configuration events.
101 std::vector<std::unique_ptr<rtclog::Event>> config_history_;
102
103 std::unique_ptr<FileWrapper> file_;
104 rtc::PlatformThread thread_;
105
106 int64_t max_size_bytes_;
107 int64_t written_bytes_;
108 int64_t start_time_;
109 int64_t stop_time_;
110
111 bool has_recent_event_;
112 std::unique_ptr<rtclog::Event> most_recent_event_;
113
114 // Temporary space for serializing profobuf data.
115 ProtoString output_string_;
116
117 rtc::Event wake_periodically_;
118 rtc::Event wake_from_hibernation_;
119 rtc::Event file_finished_;
120
121 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(RtcEventLogHelperThread);
122 };
123
124 } // namespace webrtc
125
126 #endif // ENABLE_RTC_EVENT_LOG
127
128 #endif // WEBRTC_LOGGING_RTC_EVENT_LOG_RTC_EVENT_LOG_HELPER_THREAD_H_
OLDNEW
« no previous file with comments | « webrtc/logging/rtc_event_log/rtc_event_log.cc ('k') | webrtc/logging/rtc_event_log/rtc_event_log_helper_thread.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698