Skip to content

Commit

Permalink
NetworkEventLog: add option for detailed timestamps
Browse files Browse the repository at this point in the history
* Adds microseconds to default 'timestamp' property of log events
* Adds a shortened 'timestampshort' property with just HH:MM:SS
* Adds UI to chrome://network to toggle between the two

BUG=345127
For c/b/resources/chromeos
TBR=xiyuan@chromium.org

Review URL: https://codereview.chromium.org/174373002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@253461 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
stevenjb@chromium.org committed Feb 26, 2014
1 parent 4aed9b6 commit 654e02e
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 3 deletions.
5 changes: 4 additions & 1 deletion chrome/app/chromeos_strings.grdp
Original file line number Diff line number Diff line change
Expand Up @@ -5186,9 +5186,12 @@ All users must sign out to continue.
<message name="IDS_NETWORK_LOG_LEVEL_DEBUG" desc="Debug logging level checkbox">
Debug
</message>
<message name="IDS_NETWORK_LOG_LEVEL_FILEINFO" desc="Debug logging level checkbox">
<message name="IDS_NETWORK_LOG_LEVEL_FILEINFO" desc="File info checkbox in network event log">
File Info
</message>
<message name="IDS_NETWORK_LOG_LEVEL_TIME_DETAIL" desc="Detailed timestamps checkbox in network event log">
Detailed Timestamps
</message>
<message name="IDS_NETWORK_LOG_ENTRY" desc="The log entry displayed in network event log table.">
[<ph name="TIMESTAMP">$1<ex>Timestamp</ex></ph>]
<ph name="FILE_INFO">$2<ex>file:123</ex></ph>
Expand Down
2 changes: 2 additions & 0 deletions chrome/browser/resources/chromeos/network.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ <h3>Event Log (Newest first):</h3>
<label for="log-debug" i18n-content="logLevelDebugText"></label>
<input id="log-fileinfo" type="checkbox">
<label for="log-fileinfo" i18n-content="logLevelFileinfoText"></label>
<input id="log-timedetail" type="checkbox">
<label for="log-timedetail" i18n-content="logLevelTimeDetailText"></label>
</div>
<div id="network-log-container">
</div>
Expand Down
9 changes: 8 additions & 1 deletion chrome/browser/resources/chromeos/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,14 @@ var NetworkUI = function() {
var fileinfo = '';
if ($('log-fileinfo').checked)
fileinfo = logEntry['file'];
var timestamp = '';
if ($('log-timedetail').checked)
timestamp = logEntry['timestamp'];
else
timestamp = logEntry['timestampshort'];
textWrapper.textContent = loadTimeData.getStringF(
'logEntryFormat',
logEntry['timestamp'],
timestamp,
fileinfo,
logEntry['event'],
logEntry['description']);
Expand Down Expand Up @@ -170,6 +175,8 @@ var NetworkUI = function() {
$('log-debug').onclick = sendRefresh;
$('log-fileinfo').checked = false;
$('log-fileinfo').onclick = sendRefresh;
$('log-timedetail').checked = false;
$('log-timedetail').onclick = sendRefresh;
setRefresh();
sendRefresh();
});
Expand Down
2 changes: 2 additions & 0 deletions chrome/browser/ui/webui/chromeos/network_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ NetworkUI::NetworkUI(content::WebUI* web_ui)
html->AddLocalizedString("logLevelDebugText", IDS_NETWORK_LOG_LEVEL_DEBUG);
html->AddLocalizedString("logLevelFileinfoText",
IDS_NETWORK_LOG_LEVEL_FILEINFO);
html->AddLocalizedString("logLevelTimeDetailText",
IDS_NETWORK_LOG_LEVEL_TIME_DETAIL);
html->AddLocalizedString("logEntryFormat", IDS_NETWORK_LOG_ENTRY);
html->SetJsonPath(kStringsJsFile);

Expand Down
1 change: 1 addition & 0 deletions chromeos/chromeos.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
'../build/linux/system.gyp:ssl',
'../dbus/dbus.gyp:dbus',
'../net/net.gyp:net',
'../third_party/icu/icu.gyp:icui18n',
'../third_party/libxml/libxml.gyp:libxml',
'../ui/display/display.gyp:display',
'../url/url.gyp:url_lib',
Expand Down
37 changes: 36 additions & 1 deletion chromeos/network/network_event_log.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "chromeos/network/network_event_log.h"

#include <cmath>
#include <list>

#include "base/files/file_path.h"
Expand All @@ -17,12 +18,45 @@
#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
#include "net/base/escape.h"
#include "third_party/icu/source/i18n/unicode/datefmt.h"
#include "third_party/icu/source/i18n/unicode/dtptngen.h"
#include "third_party/icu/source/i18n/unicode/smpdtfmt.h"

namespace chromeos {
namespace network_event_log {

namespace {

std::string IcuFormattedString(const base::Time& time,
const std::string& format) {
UErrorCode status = U_ZERO_ERROR;
scoped_ptr<icu::DateTimePatternGenerator> generator(
icu::DateTimePatternGenerator::createInstance(status));
DCHECK(U_SUCCESS(status));
icu::UnicodeString generated_pattern =
generator->getBestPattern(icu::UnicodeString(format.c_str()), status);
DCHECK(U_SUCCESS(status));
icu::SimpleDateFormat formatter(generated_pattern, status);
DCHECK(U_SUCCESS(status));
icu::UnicodeString formatted;
formatter.format(static_cast<UDate>(time.ToDoubleT() * 1000), formatted);
base::string16 formatted16(formatted.getBuffer(),
static_cast<size_t>(formatted.length()));
return base::UTF16ToUTF8(formatted16);
}

std::string DateAndTimeWithMicroseconds(const base::Time& time) {
std::string formatted = IcuFormattedString(time, "yyMMddHHmmss");
// icu only supports milliseconds, but sometimes we need microseconds, so
// append '.' + usecs to the end of the formatted string.
int usecs = static_cast<int>(fmod(time.ToDoubleT() * 1000000, 1000000));
return base::StringPrintf("%s.%06d", formatted.c_str(), usecs);
}

std::string TimeWithSeconds(const base::Time& time) {
return IcuFormattedString(time, "HHmmss");
}

class NetworkEventLog;
NetworkEventLog* g_network_event_log = NULL;
size_t g_max_network_event_log_entries = 4000;
Expand Down Expand Up @@ -89,7 +123,8 @@ std::string LogEntry::ToString(bool show_time,
}

void LogEntry::ToDictionary(base::DictionaryValue* output) const {
output->SetString("timestamp", base::TimeFormatShortDateAndTime(time));
output->SetString("timestamp", DateAndTimeWithMicroseconds(time));
output->SetString("timestampshort", TimeWithSeconds(time));
output->SetString("level", kLogLevelName[log_level]);
output->SetString("file",
base::StringPrintf("%s:%d ", file.c_str(), file_line));
Expand Down

0 comments on commit 654e02e

Please sign in to comment.