| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 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 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 if (currently_logging_) { | 345 if (currently_logging_) { |
| 346 currently_logging_ = false; | 346 currently_logging_ = false; |
| 347 // Create a LogEnd debug event | 347 // Create a LogEnd debug event |
| 348 rtclog::Event event; | 348 rtclog::Event event; |
| 349 int64_t timestamp = clock_->TimeInMicroseconds(); | 349 int64_t timestamp = clock_->TimeInMicroseconds(); |
| 350 event.set_timestamp_us(timestamp); | 350 event.set_timestamp_us(timestamp); |
| 351 event.set_type(rtclog::Event::DEBUG_EVENT); | 351 event.set_type(rtclog::Event::DEBUG_EVENT); |
| 352 auto debug_event = event.mutable_debug_event(); | 352 auto debug_event = event.mutable_debug_event(); |
| 353 debug_event->set_type(ConvertDebugEvent(DebugEvent::kLogEnd)); | 353 debug_event->set_type(ConvertDebugEvent(DebugEvent::kLogEnd)); |
| 354 // Store the event and close the file | 354 // Store the event and close the file |
| 355 DCHECK(file_->Open()); | 355 RTC_DCHECK(file_->Open()); |
| 356 StoreToFile(&event); | 356 StoreToFile(&event); |
| 357 file_->CloseFile(); | 357 file_->CloseFile(); |
| 358 } | 358 } |
| 359 DCHECK(!file_->Open()); | 359 RTC_DCHECK(!file_->Open()); |
| 360 stream_.Clear(); | 360 stream_.Clear(); |
| 361 } | 361 } |
| 362 | 362 |
| 363 void RtcEventLogImpl::HandleEvent(rtclog::Event* event) { | 363 void RtcEventLogImpl::HandleEvent(rtclog::Event* event) { |
| 364 if (currently_logging_) { | 364 if (currently_logging_) { |
| 365 if (clock_->TimeInMicroseconds() < start_time_us_ + duration_us_) { | 365 if (clock_->TimeInMicroseconds() < start_time_us_ + duration_us_) { |
| 366 StoreToFile(event); | 366 StoreToFile(event); |
| 367 return; | 367 return; |
| 368 } | 368 } |
| 369 StopLoggingLocked(); | 369 StopLoggingLocked(); |
| 370 } | 370 } |
| 371 AddRecentEvent(*event); | 371 AddRecentEvent(*event); |
| 372 } | 372 } |
| 373 | 373 |
| 374 void RtcEventLogImpl::StoreToFile(rtclog::Event* event) { | 374 void RtcEventLogImpl::StoreToFile(rtclog::Event* event) { |
| 375 // Reuse the same object at every log event. | 375 // Reuse the same object at every log event. |
| 376 if (stream_.stream_size() < 1) { | 376 if (stream_.stream_size() < 1) { |
| 377 stream_.add_stream(); | 377 stream_.add_stream(); |
| 378 } | 378 } |
| 379 DCHECK_EQ(stream_.stream_size(), 1); | 379 RTC_DCHECK_EQ(stream_.stream_size(), 1); |
| 380 stream_.mutable_stream(0)->Swap(event); | 380 stream_.mutable_stream(0)->Swap(event); |
| 381 // TODO(terelius): Doesn't this create a new EventStream per event? | 381 // TODO(terelius): Doesn't this create a new EventStream per event? |
| 382 // Is this guaranteed to work e.g. in future versions of protobuf? | 382 // Is this guaranteed to work e.g. in future versions of protobuf? |
| 383 std::string dump_buffer; | 383 std::string dump_buffer; |
| 384 stream_.SerializeToString(&dump_buffer); | 384 stream_.SerializeToString(&dump_buffer); |
| 385 file_->Write(dump_buffer.data(), dump_buffer.size()); | 385 file_->Write(dump_buffer.data(), dump_buffer.size()); |
| 386 } | 386 } |
| 387 | 387 |
| 388 void RtcEventLogImpl::AddRecentEvent(const rtclog::Event& event) { | 388 void RtcEventLogImpl::AddRecentEvent(const rtclog::Event& event) { |
| 389 recent_log_events_.push_back(event); | 389 recent_log_events_.push_back(event); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 409 return result->ParseFromString(dump_buffer); | 409 return result->ParseFromString(dump_buffer); |
| 410 } | 410 } |
| 411 | 411 |
| 412 #endif // ENABLE_RTC_EVENT_LOG | 412 #endif // ENABLE_RTC_EVENT_LOG |
| 413 | 413 |
| 414 // RtcEventLog member functions. | 414 // RtcEventLog member functions. |
| 415 rtc::scoped_ptr<RtcEventLog> RtcEventLog::Create() { | 415 rtc::scoped_ptr<RtcEventLog> RtcEventLog::Create() { |
| 416 return rtc::scoped_ptr<RtcEventLog>(new RtcEventLogImpl()); | 416 return rtc::scoped_ptr<RtcEventLog>(new RtcEventLogImpl()); |
| 417 } | 417 } |
| 418 } // namespace webrtc | 418 } // namespace webrtc |
| OLD | NEW |