diff options
author | stevenjb@chromium.org <stevenjb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-26 15:14:47 +0000 |
---|---|---|
committer | stevenjb@chromium.org <stevenjb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-26 15:14:47 +0000 |
commit | 654e02e245b33fa2807432fe6d2c01f64c216cfb (patch) | |
tree | c30c11a15f05e2c0d3e5ba4f7afc138b544f0456 | |
parent | 4aed9b632b41c44e6a3cbed2ad2fc2a3d54f585d (diff) | |
download | chromium_src-654e02e245b33fa2807432fe6d2c01f64c216cfb.zip chromium_src-654e02e245b33fa2807432fe6d2c01f64c216cfb.tar.gz chromium_src-654e02e245b33fa2807432fe6d2c01f64c216cfb.tar.bz2 |
NetworkEventLog: add option for detailed timestamps
* 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
-rw-r--r-- | chrome/app/chromeos_strings.grdp | 5 | ||||
-rw-r--r-- | chrome/browser/resources/chromeos/network.html | 2 | ||||
-rw-r--r-- | chrome/browser/resources/chromeos/network.js | 9 | ||||
-rw-r--r-- | chrome/browser/ui/webui/chromeos/network_ui.cc | 2 | ||||
-rw-r--r-- | chromeos/chromeos.gyp | 1 | ||||
-rw-r--r-- | chromeos/network/network_event_log.cc | 37 |
6 files changed, 53 insertions, 3 deletions
diff --git a/chrome/app/chromeos_strings.grdp b/chrome/app/chromeos_strings.grdp index a2b7938..64fb744 100644 --- a/chrome/app/chromeos_strings.grdp +++ b/chrome/app/chromeos_strings.grdp @@ -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> diff --git a/chrome/browser/resources/chromeos/network.html b/chrome/browser/resources/chromeos/network.html index 1e9b11b..32ec98d 100644 --- a/chrome/browser/resources/chromeos/network.html +++ b/chrome/browser/resources/chromeos/network.html @@ -25,6 +25,8 @@ <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> diff --git a/chrome/browser/resources/chromeos/network.js b/chrome/browser/resources/chromeos/network.js index 49abd050..ded56bd 100644 --- a/chrome/browser/resources/chromeos/network.js +++ b/chrome/browser/resources/chromeos/network.js @@ -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']); @@ -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(); }); diff --git a/chrome/browser/ui/webui/chromeos/network_ui.cc b/chrome/browser/ui/webui/chromeos/network_ui.cc index 42c391f..206331d 100644 --- a/chrome/browser/ui/webui/chromeos/network_ui.cc +++ b/chrome/browser/ui/webui/chromeos/network_ui.cc @@ -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); diff --git a/chromeos/chromeos.gyp b/chromeos/chromeos.gyp index 3f5d97d..b7daed7 100644 --- a/chromeos/chromeos.gyp +++ b/chromeos/chromeos.gyp @@ -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', diff --git a/chromeos/network/network_event_log.cc b/chromeos/network/network_event_log.cc index 9c87235..7e5db47 100644 --- a/chromeos/network/network_event_log.cc +++ b/chromeos/network/network_event_log.cc @@ -4,6 +4,7 @@ #include "chromeos/network/network_event_log.h" +#include <cmath> #include <list> #include "base/files/file_path.h" @@ -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; @@ -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)); |