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

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

Issue 1997393002: Improved error checking for file errors in RtcEventLog. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 7 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 136
137 // Serialize the events in the event queue. 137 // Serialize the events in the event queue.
138 while (!history_.empty() && !stop) { 138 while (!history_.empty() && !stop) {
139 stop = AppendEventToString(history_.front().get()); 139 stop = AppendEventToString(history_.front().get());
140 if (!stop) { 140 if (!stop) {
141 history_.pop_front(); 141 history_.pop_front();
142 } 142 }
143 } 143 }
144 144
145 // Write to file. 145 // Write to file.
146 file_->Write(output_string_.data(), output_string_.size()); 146 bool success = file_->Write(output_string_.data(), output_string_.size());
147 if (!success) {
148 LOG(LS_WARNING) << "FileWrapper failed to write WebRtcEventLog file.";
pbos-webrtc 2016/05/23 11:59:11 LS_ERROR
149 // The current FileWrapper implementation closes the file on error.
150 RTC_DCHECK(!file_->Open());
151 return;
152 }
147 written_bytes_ += output_string_.size(); 153 written_bytes_ += output_string_.size();
148 154
149 // Free the allocated memory since we probably won't need this amount of 155 // Free the allocated memory since we probably won't need this amount of
150 // space again. 156 // space again.
151 output_string_.clear(); 157 output_string_.clear();
152 output_string_.shrink_to_fit(); 158 output_string_.shrink_to_fit();
153 159
154 if (stop) { 160 if (stop) {
155 RTC_DCHECK(file_->Open()); 161 RTC_DCHECK(file_->Open());
156 StopLogFile(); 162 StopLogFile();
(...skipping 17 matching lines...) Expand all
174 stop = AppendEventToString(most_recent_event_.get()); 180 stop = AppendEventToString(most_recent_event_.get());
175 if (!stop) { 181 if (!stop) {
176 if (IsConfigEvent(*most_recent_event_)) { 182 if (IsConfigEvent(*most_recent_event_)) {
177 config_history_.push_back(std::move(most_recent_event_)); 183 config_history_.push_back(std::move(most_recent_event_));
178 } 184 }
179 has_recent_event_ = event_queue_->Remove(&most_recent_event_); 185 has_recent_event_ = event_queue_->Remove(&most_recent_event_);
180 } 186 }
181 } 187 }
182 188
183 // Write string to file. 189 // Write string to file.
184 file_->Write(output_string_.data(), output_string_.size()); 190 bool success = file_->Write(output_string_.data(), output_string_.size());
pbos-webrtc 2016/05/23 11:59:11 remove temporary bool
191 if (!success) {
192 LOG(LS_WARNING) << "FileWrapper failed to write WebRtcEventLog file.";
pbos-webrtc 2016/05/23 11:59:11 LS_ERROR
193 // The current FileWrapper implementation closes the file on error.
194 RTC_DCHECK(!file_->Open());
195 return;
196 }
185 written_bytes_ += output_string_.size(); 197 written_bytes_ += output_string_.size();
186 198
187 if (!file_->Open()) {
188 LOG(LS_WARNING) << "WebRTC event log file closed by FileWrapper.";
189 }
190
191 // We want to stop logging if we have reached the file size limit. We also 199 // We want to stop logging if we have reached the file size limit. We also
192 // want to stop logging if the remaining events are more recent than the 200 // want to stop logging if the remaining events are more recent than the
193 // time limit, or in other words if we have terminated the loop despite 201 // time limit, or in other words if we have terminated the loop despite
194 // having more events in the queue. 202 // having more events in the queue.
195 if ((has_recent_event_ && most_recent_event_->timestamp_us() > stop_time_) || 203 if ((has_recent_event_ && most_recent_event_->timestamp_us() > stop_time_) ||
196 stop) { 204 stop) {
197 RTC_DCHECK(file_->Open()); 205 RTC_DCHECK(file_->Open());
198 StopLogFile(); 206 StopLogFile();
199 } 207 }
200 } 208 }
201 209
202 void RtcEventLogHelperThread::StopLogFile() { 210 void RtcEventLogHelperThread::StopLogFile() {
203 RTC_DCHECK(file_->Open()); 211 RTC_DCHECK(file_->Open());
204 output_string_.clear(); 212 output_string_.clear();
205 213
206 rtclog::Event end_event; 214 rtclog::Event end_event;
207 end_event.set_timestamp_us(stop_time_); 215 end_event.set_timestamp_us(stop_time_);
208 end_event.set_type(rtclog::Event::LOG_END); 216 end_event.set_type(rtclog::Event::LOG_END);
209 AppendEventToString(&end_event); 217 AppendEventToString(&end_event);
210 218
211 if (written_bytes_ + static_cast<int64_t>(output_string_.size()) <= 219 if (written_bytes_ + static_cast<int64_t>(output_string_.size()) <=
212 max_size_bytes_) { 220 max_size_bytes_) {
213 file_->Write(output_string_.data(), output_string_.size()); 221 bool success = file_->Write(output_string_.data(), output_string_.size());
pbos-webrtc 2016/05/23 11:59:11 remove bool here and everywhere it's not used afte
222 if (!success) {
223 LOG(LS_WARNING) << "FileWrapper failed to write WebRtcEventLog file.";
pbos-webrtc 2016/05/23 11:59:11 LS_ERROR
224 // The current FileWrapper implementation closes the file on error.
225 RTC_DCHECK(!file_->Open());
226 }
214 written_bytes_ += output_string_.size(); 227 written_bytes_ += output_string_.size();
215 } 228 }
216 229
217 max_size_bytes_ = std::numeric_limits<int64_t>::max(); 230 max_size_bytes_ = std::numeric_limits<int64_t>::max();
218 written_bytes_ = 0; 231 written_bytes_ = 0;
219 start_time_ = 0; 232 start_time_ = 0;
220 stop_time_ = std::numeric_limits<int64_t>::max(); 233 stop_time_ = std::numeric_limits<int64_t>::max();
221 output_string_.clear(); 234 output_string_.clear();
222 file_->CloseFile(); 235 file_->CloseFile();
223 RTC_DCHECK(!file_->Open()); 236 RTC_DCHECK(!file_->Open());
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 289
277 bool RtcEventLogHelperThread::ThreadOutputFunction(void* obj) { 290 bool RtcEventLogHelperThread::ThreadOutputFunction(void* obj) {
278 RtcEventLogHelperThread* helper = static_cast<RtcEventLogHelperThread*>(obj); 291 RtcEventLogHelperThread* helper = static_cast<RtcEventLogHelperThread*>(obj);
279 helper->WriteLog(); 292 helper->WriteLog();
280 return false; 293 return false;
281 } 294 }
282 295
283 } // namespace webrtc 296 } // namespace webrtc
284 297
285 #endif // ENABLE_RTC_EVENT_LOG 298 #endif // ENABLE_RTC_EVENT_LOG
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698