| OLD | NEW |
| 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 Loading... |
| 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 if (!file_->Write(output_string_.data(), output_string_.size())) { |
| 147 LOG(LS_ERROR) << "FileWrapper failed to write WebRtcEventLog file."; |
| 148 // The current FileWrapper implementation closes the file on error. |
| 149 RTC_DCHECK(!file_->Open()); |
| 150 return; |
| 151 } |
| 147 written_bytes_ += output_string_.size(); | 152 written_bytes_ += output_string_.size(); |
| 148 | 153 |
| 149 // Free the allocated memory since we probably won't need this amount of | 154 // Free the allocated memory since we probably won't need this amount of |
| 150 // space again. | 155 // space again. |
| 151 output_string_.clear(); | 156 output_string_.clear(); |
| 152 output_string_.shrink_to_fit(); | 157 output_string_.shrink_to_fit(); |
| 153 | 158 |
| 154 if (stop) { | 159 if (stop) { |
| 155 RTC_DCHECK(file_->Open()); | 160 RTC_DCHECK(file_->Open()); |
| 156 StopLogFile(); | 161 StopLogFile(); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 174 stop = AppendEventToString(most_recent_event_.get()); | 179 stop = AppendEventToString(most_recent_event_.get()); |
| 175 if (!stop) { | 180 if (!stop) { |
| 176 if (IsConfigEvent(*most_recent_event_)) { | 181 if (IsConfigEvent(*most_recent_event_)) { |
| 177 config_history_.push_back(std::move(most_recent_event_)); | 182 config_history_.push_back(std::move(most_recent_event_)); |
| 178 } | 183 } |
| 179 has_recent_event_ = event_queue_->Remove(&most_recent_event_); | 184 has_recent_event_ = event_queue_->Remove(&most_recent_event_); |
| 180 } | 185 } |
| 181 } | 186 } |
| 182 | 187 |
| 183 // Write string to file. | 188 // Write string to file. |
| 184 file_->Write(output_string_.data(), output_string_.size()); | 189 if (!file_->Write(output_string_.data(), output_string_.size())) { |
| 190 LOG(LS_ERROR) << "FileWrapper failed to write WebRtcEventLog file."; |
| 191 // The current FileWrapper implementation closes the file on error. |
| 192 RTC_DCHECK(!file_->Open()); |
| 193 return; |
| 194 } |
| 185 written_bytes_ += output_string_.size(); | 195 written_bytes_ += output_string_.size(); |
| 186 | 196 |
| 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 | 197 // 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 | 198 // 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 | 199 // time limit, or in other words if we have terminated the loop despite |
| 194 // having more events in the queue. | 200 // having more events in the queue. |
| 195 if ((has_recent_event_ && most_recent_event_->timestamp_us() > stop_time_) || | 201 if ((has_recent_event_ && most_recent_event_->timestamp_us() > stop_time_) || |
| 196 stop) { | 202 stop) { |
| 197 RTC_DCHECK(file_->Open()); | 203 RTC_DCHECK(file_->Open()); |
| 198 StopLogFile(); | 204 StopLogFile(); |
| 199 } | 205 } |
| 200 } | 206 } |
| 201 | 207 |
| 202 void RtcEventLogHelperThread::StopLogFile() { | 208 void RtcEventLogHelperThread::StopLogFile() { |
| 203 RTC_DCHECK(file_->Open()); | 209 RTC_DCHECK(file_->Open()); |
| 204 output_string_.clear(); | 210 output_string_.clear(); |
| 205 | 211 |
| 206 rtclog::Event end_event; | 212 rtclog::Event end_event; |
| 207 end_event.set_timestamp_us(stop_time_); | 213 end_event.set_timestamp_us(stop_time_); |
| 208 end_event.set_type(rtclog::Event::LOG_END); | 214 end_event.set_type(rtclog::Event::LOG_END); |
| 209 AppendEventToString(&end_event); | 215 AppendEventToString(&end_event); |
| 210 | 216 |
| 211 if (written_bytes_ + static_cast<int64_t>(output_string_.size()) <= | 217 if (written_bytes_ + static_cast<int64_t>(output_string_.size()) <= |
| 212 max_size_bytes_) { | 218 max_size_bytes_) { |
| 213 file_->Write(output_string_.data(), output_string_.size()); | 219 if (!file_->Write(output_string_.data(), output_string_.size())) { |
| 220 LOG(LS_ERROR) << "FileWrapper failed to write WebRtcEventLog file."; |
| 221 // The current FileWrapper implementation closes the file on error. |
| 222 RTC_DCHECK(!file_->Open()); |
| 223 } |
| 214 written_bytes_ += output_string_.size(); | 224 written_bytes_ += output_string_.size(); |
| 215 } | 225 } |
| 216 | 226 |
| 217 max_size_bytes_ = std::numeric_limits<int64_t>::max(); | 227 max_size_bytes_ = std::numeric_limits<int64_t>::max(); |
| 218 written_bytes_ = 0; | 228 written_bytes_ = 0; |
| 219 start_time_ = 0; | 229 start_time_ = 0; |
| 220 stop_time_ = std::numeric_limits<int64_t>::max(); | 230 stop_time_ = std::numeric_limits<int64_t>::max(); |
| 221 output_string_.clear(); | 231 output_string_.clear(); |
| 222 file_->CloseFile(); | 232 file_->CloseFile(); |
| 223 RTC_DCHECK(!file_->Open()); | 233 RTC_DCHECK(!file_->Open()); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 | 286 |
| 277 bool RtcEventLogHelperThread::ThreadOutputFunction(void* obj) { | 287 bool RtcEventLogHelperThread::ThreadOutputFunction(void* obj) { |
| 278 RtcEventLogHelperThread* helper = static_cast<RtcEventLogHelperThread*>(obj); | 288 RtcEventLogHelperThread* helper = static_cast<RtcEventLogHelperThread*>(obj); |
| 279 helper->WriteLog(); | 289 helper->WriteLog(); |
| 280 return false; | 290 return false; |
| 281 } | 291 } |
| 282 | 292 |
| 283 } // namespace webrtc | 293 } // namespace webrtc |
| 284 | 294 |
| 285 #endif // ENABLE_RTC_EVENT_LOG | 295 #endif // ENABLE_RTC_EVENT_LOG |
| OLD | NEW |