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

Side by Side Diff: webrtc/call/rtc_event_log_helper_thread.h

Issue 2035483003: Hibernate the thread if there are no events in the queue. Wake it up when an event is added to the … (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Rename SignalStopFile() -> WaitForFileFinished() Created 4 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
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2016 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
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 lhs.file.swap(rhs.file); 60 lhs.file.swap(rhs.file);
61 swap(lhs.max_size_bytes, rhs.max_size_bytes); 61 swap(lhs.max_size_bytes, rhs.max_size_bytes);
62 swap(lhs.start_time, rhs.start_time); 62 swap(lhs.start_time, rhs.start_time);
63 swap(lhs.stop_time, rhs.stop_time); 63 swap(lhs.stop_time, rhs.stop_time);
64 } 64 }
65 }; 65 };
66 66
67 RtcEventLogHelperThread( 67 RtcEventLogHelperThread(
68 SwapQueue<ControlMessage>* message_queue, 68 SwapQueue<ControlMessage>* message_queue,
69 SwapQueue<std::unique_ptr<rtclog::Event>>* event_queue, 69 SwapQueue<std::unique_ptr<rtclog::Event>>* event_queue,
70 rtc::Event* wake_up,
71 rtc::Event* file_finished,
72 const Clock* const clock); 70 const Clock* const clock);
73 ~RtcEventLogHelperThread(); 71 ~RtcEventLogHelperThread();
74 72
73 // This function MUST be called once a STOP_FILE message is added to the
74 // signalling queue. The function will make sure that the output thread
75 // wakes up to read the message, and it blocks until the output thread has
76 // finished writing to the file.
77 void WaitForFileFinished();
78
79 // This fuction MUST be called once an event is added to the event queue.
80 void SignalNewEvent();
81
75 private: 82 private:
76 static bool ThreadOutputFunction(void* obj); 83 static bool ThreadOutputFunction(void* obj);
77 84
78 void TerminateThread();
79 bool AppendEventToString(rtclog::Event* event); 85 bool AppendEventToString(rtclog::Event* event);
80 void AppendEventToHistory(const rtclog::Event& event); 86 bool LogToMemory();
81 void LogToMemory();
82 void StartLogFile(); 87 void StartLogFile();
83 void LogToFile(); 88 bool LogToFile();
84 void StopLogFile(); 89 void StopLogFile();
85 void WriteLog(); 90 void ProcessEvents();
86 91
87 // Message queues for passing events to the logging thread. 92 // Message queues for passing events to the logging thread.
88 SwapQueue<ControlMessage>* message_queue_; 93 SwapQueue<ControlMessage>* message_queue_;
89 SwapQueue<std::unique_ptr<rtclog::Event>>* event_queue_; 94 SwapQueue<std::unique_ptr<rtclog::Event>>* event_queue_;
90 95
91 // History containing the most recent events (~ 10 s). 96 // History containing the most recent events (~ 10 s).
92 RingBuffer<std::unique_ptr<rtclog::Event>> history_; 97 RingBuffer<std::unique_ptr<rtclog::Event>> history_;
93 98
94 // History containing all past configuration events. 99 // History containing all past configuration events.
95 std::vector<std::unique_ptr<rtclog::Event>> config_history_; 100 std::vector<std::unique_ptr<rtclog::Event>> config_history_;
96 101
97 std::unique_ptr<FileWrapper> file_; 102 std::unique_ptr<FileWrapper> file_;
98 rtc::PlatformThread thread_; 103 rtc::PlatformThread thread_;
99 104
100 int64_t max_size_bytes_; 105 int64_t max_size_bytes_;
101 int64_t written_bytes_; 106 int64_t written_bytes_;
102 int64_t start_time_; 107 int64_t start_time_;
103 int64_t stop_time_; 108 int64_t stop_time_;
104 109
105 bool has_recent_event_; 110 bool has_recent_event_;
106 std::unique_ptr<rtclog::Event> most_recent_event_; 111 std::unique_ptr<rtclog::Event> most_recent_event_;
107 112
108 // Temporary space for serializing profobuf data. 113 // Temporary space for serializing profobuf data.
109 std::string output_string_; 114 std::string output_string_;
110 115
111 rtc::Event* wake_up_; 116 rtc::Event wake_periodically_;
112 rtc::Event* stopped_; 117 rtc::Event wake_from_hibernation_;
118 rtc::Event file_finished_;
113 119
114 const Clock* const clock_; 120 const Clock* const clock_;
115 121
116 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(RtcEventLogHelperThread); 122 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(RtcEventLogHelperThread);
117 }; 123 };
118 124
119 } // namespace webrtc 125 } // namespace webrtc
120 126
121 #endif // ENABLE_RTC_EVENT_LOG 127 #endif // ENABLE_RTC_EVENT_LOG
122 128
123 #endif // WEBRTC_CALL_RTC_EVENT_LOG_HELPER_THREAD_H_ 129 #endif // WEBRTC_CALL_RTC_EVENT_LOG_HELPER_THREAD_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698