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

Unified Diff: chrome/browser/media/webrtc_logging_handler_host.cc

Issue 218403004: Fix the timestamp generation for webrtc native log. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/media/webrtc_logging_handler_host.cc
diff --git a/chrome/browser/media/webrtc_logging_handler_host.cc b/chrome/browser/media/webrtc_logging_handler_host.cc
index e1919d2670c2bb17bd436916f522fb9ab448de55..83278e28a47872afa723c2eae76358b18e7d66d1 100644
--- a/chrome/browser/media/webrtc_logging_handler_host.cc
+++ b/chrome/browser/media/webrtc_logging_handler_host.cc
@@ -4,6 +4,8 @@
#include "chrome/browser/media/webrtc_logging_handler_host.h"
+#include <iomanip>
+#include <sstream>
#include <string>
#include "base/bind.h"
@@ -21,7 +23,6 @@
#include "chrome/browser/media/webrtc_log_uploader.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/chrome_switches.h"
-#include "chrome/common/media/webrtc_logging_messages.h"
#include "chrome/common/partial_circular_buffer.h"
#include "chrome/common/pref_names.h"
#include "chromeos/settings/cros_settings_names.h"
@@ -114,7 +115,8 @@ WebRtcLoggingHandlerHost::WebRtcLoggingHandlerHost(Profile* profile)
: BrowserMessageFilter(WebRtcLoggingMsgStart),
profile_(profile),
logging_state_(CLOSED),
- upload_log_on_render_close_(false) {
+ upload_log_on_render_close_(false),
+ logging_started_time_ms_(0) {
DCHECK(profile_);
}
@@ -219,7 +221,11 @@ void WebRtcLoggingHandlerHost::LogMessage(const std::string& message) {
BrowserThread::IO,
FROM_HERE,
base::Bind(
- &WebRtcLoggingHandlerHost::AddLogMessageFromBrowser, this, message));
+ &WebRtcLoggingHandlerHost::AddLogMessageFromBrowser,
+ this,
+ base::Time::Now().ToInternalValue() /
dcheng 2014/04/01 23:35:19 1) Shouldn't we be using base::TimeTicks? base::Ti
jiayl 2014/04/01 23:50:06 We do want to use base::Time::Now(), because 1. we
jiayl 2014/04/02 00:38:06 uint64 changed to base::Time.
+ base::Time::kMicrosecondsPerMillisecond,
+ message));
}
void WebRtcLoggingHandlerHost::OnChannelClosing() {
@@ -227,6 +233,7 @@ void WebRtcLoggingHandlerHost::OnChannelClosing() {
if (logging_state_ == STARTED || logging_state_ == STOPPED) {
if (upload_log_on_render_close_) {
logging_state_ = STOPPED;
+ logging_started_time_ms_ = 0;
content::BrowserThread::PostTaskAndReplyWithResult(
content::BrowserThread::FILE,
FROM_HERE,
@@ -249,7 +256,7 @@ bool WebRtcLoggingHandlerHost::OnMessageReceived(const IPC::Message& message,
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
bool handled = true;
IPC_BEGIN_MESSAGE_MAP_EX(WebRtcLoggingHandlerHost, message, *message_was_ok)
- IPC_MESSAGE_HANDLER(WebRtcLoggingMsg_AddLogMessage, OnAddLogMessage)
+ IPC_MESSAGE_HANDLER(WebRtcLoggingMsg_AddLogMessages, OnAddLogMessages)
IPC_MESSAGE_HANDLER(WebRtcLoggingMsg_LoggingStopped,
OnLoggingStoppedInRenderer)
IPC_MESSAGE_UNHANDLED(handled = false)
@@ -259,16 +266,22 @@ bool WebRtcLoggingHandlerHost::OnMessageReceived(const IPC::Message& message,
}
void WebRtcLoggingHandlerHost::AddLogMessageFromBrowser(
- const std::string& message) {
+ uint64 timestamp_ms, const std::string& message) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
if (logging_state_ == STARTED)
- LogToCircularBuffer(message);
+ LogToCircularBuffer(FormatMessageWithTimestamp(timestamp_ms, message));
}
-void WebRtcLoggingHandlerHost::OnAddLogMessage(const std::string& message) {
+void WebRtcLoggingHandlerHost::OnAddLogMessages(
+ const std::vector<WebRtcLoggingMessage>& messages) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- if (logging_state_ == STARTED || logging_state_ == STOPPING)
- LogToCircularBuffer(message);
+ if (logging_state_ == STARTED || logging_state_ == STOPPING) {
+ for (size_t i = 0; i < messages.size(); ++i) {
+ LogToCircularBuffer(
+ FormatMessageWithTimestamp(messages[i].timestamp_ms,
+ messages[i].message));
+ }
+ }
}
void WebRtcLoggingHandlerHost::OnLoggingStoppedInRenderer() {
@@ -281,6 +294,7 @@ void WebRtcLoggingHandlerHost::OnLoggingStoppedInRenderer() {
BadMessageReceived();
return;
}
+ logging_started_time_ms_ = 0;
logging_state_ = STOPPED;
FireGenericDoneCallback(&stop_callback_, true, "");
}
@@ -398,6 +412,8 @@ void WebRtcLoggingHandlerHost::LogInitialInfoOnIOThread(
void WebRtcLoggingHandlerHost::NotifyLoggingStarted() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
Send(new WebRtcLoggingMsg_StartLogging());
+ logging_started_time_ms_ = base::Time::Now().ToInternalValue() /
+ base::Time::kMicrosecondsPerMillisecond;;
logging_state_ = STARTED;
FireGenericDoneCallback(&start_callback_, true, "");
}
@@ -457,3 +473,15 @@ void WebRtcLoggingHandlerHost::FireGenericDoneCallback(
error_message));
(*callback).Reset();
}
+
+std::string WebRtcLoggingHandlerHost::FormatMessageWithTimestamp(
+ uint64 msg_created_time_ms, const std::string& message) {
+ uint64 interval_ms = msg_created_time_ms - logging_started_time_ms_;
+
+ std::ostringstream oss;
dcheng 2014/04/01 23:35:19 We don't generally use streams except for logging.
jiayl 2014/04/02 00:38:06 Done.
+ oss << "[" << std::setfill('0') << std::setw(3)
+ << (interval_ms / 1000) << ":" << std::setw(3)
+ << (interval_ms % 1000) << std::setfill(' ') << "] "
+ << message;
+ return oss.str();
+}

Powered by Google App Engine
This is Rietveld 408576698