Commit c2fadc96 authored by Eric Roman's avatar Eric Roman Committed by Commit Bot

Enable bounded mode logging on chrome://net-export.

There is an option to configure the maximum size of the NetLog. The
default is 100MiB.

Bug: 679030
Change-Id: I9260d7ee895d589c4789a350ca4fe1dfc8617b65
Reviewed-on: https://chromium-review.googlesource.com/571514
Commit-Queue: Eric Roman <eroman@chromium.org>
Reviewed-by: default avatarHelen Li <xunjieli@chromium.org>
Cr-Commit-Position: refs/heads/master@{#487602}
parent ba577b05
...@@ -149,10 +149,12 @@ class NetExportMessageHandler ...@@ -149,10 +149,12 @@ class NetExportMessageHandler
net_log::NetExportFileWriter::StateObserver> net_log::NetExportFileWriter::StateObserver>
state_observer_manager_; state_observer_manager_;
// The capture mode the user chose in the UI when logging started is cached // The capture mode and file size bound that the user chose in the UI when
// here and is read after a file path is chosen in the save dialog. // logging started is cached here and is read after a file path is chosen in
// Its value is only valid while the save dialog is open on the desktop UI. // the save dialog. Their values are only valid while the save dialog is open
// on the desktop UI.
net::NetLogCaptureMode capture_mode_; net::NetLogCaptureMode capture_mode_;
size_t max_log_file_size_;
scoped_refptr<ui::SelectFileDialog> select_file_dialog_; scoped_refptr<ui::SelectFileDialog> select_file_dialog_;
...@@ -217,12 +219,21 @@ void NetExportMessageHandler::OnEnableNotifyUIWithState( ...@@ -217,12 +219,21 @@ void NetExportMessageHandler::OnEnableNotifyUIWithState(
void NetExportMessageHandler::OnStartNetLog(const base::ListValue* list) { void NetExportMessageHandler::OnStartNetLog(const base::ListValue* list) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
std::string capture_mode_string;
bool result = list->GetString(0, &capture_mode_string);
DCHECK(result);
capture_mode_ = const base::Value::ListStorage& params = list->GetList();
net_log::NetExportFileWriter::CaptureModeFromString(capture_mode_string);
// Determine the capture mode.
capture_mode_ = net::NetLogCaptureMode::Default();
if (params.size() > 0 && params[0].is_string()) {
capture_mode_ = net_log::NetExportFileWriter::CaptureModeFromString(
params[0].GetString());
}
// Determine the max file size.
max_log_file_size_ = net_log::NetExportFileWriter::kNoLimit;
if (params.size() > 1 && params[1].is_int() && params[1].GetInt() > 0) {
max_log_file_size_ = params[1].GetInt();
}
if (UsingMobileUI()) { if (UsingMobileUI()) {
StartNetLog(base::FilePath()); StartNetLog(base::FilePath());
...@@ -321,7 +332,7 @@ void NetExportMessageHandler::StartNetLog(const base::FilePath& path) { ...@@ -321,7 +332,7 @@ void NetExportMessageHandler::StartNetLog(const base::FilePath& path) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
file_writer_->StartNetLog( file_writer_->StartNetLog(
path, capture_mode_, path, capture_mode_, max_log_file_size_,
base::CommandLine::ForCurrentProcess()->GetCommandLineString(), base::CommandLine::ForCurrentProcess()->GetCommandLineString(),
chrome::GetChannelString(), GetURLRequestContexts()); chrome::GetChannelString(), GetURLRequestContexts());
} }
......
...@@ -101,6 +101,8 @@ base::FilePath GetPathWithAllPermissions(const base::FilePath& path) { ...@@ -101,6 +101,8 @@ base::FilePath GetPathWithAllPermissions(const base::FilePath& path) {
} // namespace } // namespace
const size_t NetExportFileWriter::kNoLimit = net::FileNetLogObserver::kNoLimit;
NetExportFileWriter::NetExportFileWriter(ChromeNetLog* chrome_net_log) NetExportFileWriter::NetExportFileWriter(ChromeNetLog* chrome_net_log)
: state_(STATE_UNINITIALIZED), : state_(STATE_UNINITIALIZED),
log_exists_(false), log_exists_(false),
...@@ -156,6 +158,7 @@ void NetExportFileWriter::Initialize( ...@@ -156,6 +158,7 @@ void NetExportFileWriter::Initialize(
void NetExportFileWriter::StartNetLog( void NetExportFileWriter::StartNetLog(
const base::FilePath& log_path, const base::FilePath& log_path,
net::NetLogCaptureMode capture_mode, net::NetLogCaptureMode capture_mode,
size_t max_file_size,
const base::CommandLine::StringType& command_line_string, const base::CommandLine::StringType& command_line_string,
const std::string& channel_string, const std::string& channel_string,
const URLRequestContextGetterList& context_getters) { const URLRequestContextGetterList& context_getters) {
...@@ -177,8 +180,8 @@ void NetExportFileWriter::StartNetLog( ...@@ -177,8 +180,8 @@ void NetExportFileWriter::StartNetLog(
std::unique_ptr<base::Value> constants( std::unique_ptr<base::Value> constants(
ChromeNetLog::GetConstants(command_line_string, channel_string)); ChromeNetLog::GetConstants(command_line_string, channel_string));
file_net_log_observer_ = file_net_log_observer_ = net::FileNetLogObserver::CreateBounded(
net::FileNetLogObserver::CreateUnbounded(log_path_, std::move(constants)); log_path_, max_file_size, std::move(constants));
net_task_runner_->PostTaskAndReply( net_task_runner_->PostTaskAndReply(
FROM_HERE, FROM_HERE,
......
...@@ -55,6 +55,9 @@ class ChromeNetLog; ...@@ -55,6 +55,9 @@ class ChromeNetLog;
// code on the |file_task_runner_| and |net_task_runner_|. // code on the |file_task_runner_| and |net_task_runner_|.
class NetExportFileWriter { class NetExportFileWriter {
public: public:
// Special value meaning "can use an unlimited number of bytes".
static const size_t kNoLimit;
// The observer interface to be implemented by code that wishes to be notified // The observer interface to be implemented by code that wishes to be notified
// of NetExportFileWriter's state changes. // of NetExportFileWriter's state changes.
class StateObserver { class StateObserver {
...@@ -99,12 +102,16 @@ class NetExportFileWriter { ...@@ -99,12 +102,16 @@ class NetExportFileWriter {
// empty, the default log path is used. If NetExportFileWriter is already // empty, the default log path is used. If NetExportFileWriter is already
// logging, this is a no-op and |capture_mode| is ignored. // logging, this is a no-op and |capture_mode| is ignored.
// //
// |max_file_size| places a bound on how large the log file can grow. To make
// it grow unboundedly pass kNoLimit.
//
// |context_getters| is an optional list of URLRequestContextGetters used only // |context_getters| is an optional list of URLRequestContextGetters used only
// to add log entries for ongoing events when logging starts. They are not // to add log entries for ongoing events when logging starts. They are not
// used for retrieving polled data. All the contexts must be bound to the same // used for retrieving polled data. All the contexts must be bound to the same
// thread. // thread.
void StartNetLog(const base::FilePath& log_path, void StartNetLog(const base::FilePath& log_path,
net::NetLogCaptureMode capture_mode, net::NetLogCaptureMode capture_mode,
size_t max_file_size,
const base::CommandLine::StringType& command_line_string, const base::CommandLine::StringType& command_line_string,
const std::string& channel_string, const std::string& channel_string,
const URLRequestContextGetterList& context_getters); const URLRequestContextGetterList& context_getters);
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
namespace { namespace {
const char kChannelString[] = "SomeChannel"; const char kChannelString[] = "SomeChannel";
const size_t kMaxLogSizeBytes = 100 * 1024 * 1024; // 100MiB
// Keep this in sync with kLogRelativePath defined in net_export_file_writer.cc. // Keep this in sync with kLogRelativePath defined in net_export_file_writer.cc.
base::FilePath::CharType kLogRelativePath[] = base::FilePath::CharType kLogRelativePath[] =
...@@ -329,7 +330,7 @@ class NetExportFileWriterTest : public ::testing::Test { ...@@ -329,7 +330,7 @@ class NetExportFileWriterTest : public ::testing::Test {
net::NetLogCaptureMode capture_mode, net::NetLogCaptureMode capture_mode,
const std::string& expected_capture_mode_string, const std::string& expected_capture_mode_string,
const URLRequestContextGetterList& context_getters) { const URLRequestContextGetterList& context_getters) {
file_writer_.StartNetLog(custom_log_path, capture_mode, file_writer_.StartNetLog(custom_log_path, capture_mode, kMaxLogSizeBytes,
base::CommandLine::StringType(), kChannelString, base::CommandLine::StringType(), kChannelString,
context_getters); context_getters);
std::unique_ptr<base::DictionaryValue> state = std::unique_ptr<base::DictionaryValue> state =
...@@ -498,14 +499,14 @@ TEST_F(NetExportFileWriterTest, StartAndStopWithAllCaptureModes) { ...@@ -498,14 +499,14 @@ TEST_F(NetExportFileWriterTest, StartAndStopWithAllCaptureModes) {
// with various capture modes; they should all be ignored and result in no // with various capture modes; they should all be ignored and result in no
// state change. // state change.
file_writer_.StartNetLog(base::FilePath(), capture_modes[i], file_writer_.StartNetLog(base::FilePath(), capture_modes[i],
base::CommandLine::StringType(), kChannelString, kMaxLogSizeBytes, base::CommandLine::StringType(),
URLRequestContextGetterList()); kChannelString, URLRequestContextGetterList());
file_writer_.StartNetLog(base::FilePath(), capture_modes[(i + 1) % 3], file_writer_.StartNetLog(base::FilePath(), capture_modes[(i + 1) % 3],
base::CommandLine::StringType(), kChannelString, kMaxLogSizeBytes, base::CommandLine::StringType(),
URLRequestContextGetterList()); kChannelString, URLRequestContextGetterList());
file_writer_.StartNetLog(base::FilePath(), capture_modes[(i + 2) % 3], file_writer_.StartNetLog(base::FilePath(), capture_modes[(i + 2) % 3],
base::CommandLine::StringType(), kChannelString, kMaxLogSizeBytes, base::CommandLine::StringType(),
URLRequestContextGetterList()); kChannelString, URLRequestContextGetterList());
// StopNetLog(), should result in state change. The capture mode should // StopNetLog(), should result in state change. The capture mode should
// match that of the first StartNetLog() call (called by // match that of the first StartNetLog() call (called by
...@@ -745,8 +746,8 @@ TEST_F(NetExportFileWriterTest, ReceiveStartWhileInitializing) { ...@@ -745,8 +746,8 @@ TEST_F(NetExportFileWriterTest, ReceiveStartWhileInitializing) {
// before |file_writer_| finishes initialization, which means this // before |file_writer_| finishes initialization, which means this
// should be a no-op. // should be a no-op.
file_writer_.StartNetLog(base::FilePath(), net::NetLogCaptureMode::Default(), file_writer_.StartNetLog(base::FilePath(), net::NetLogCaptureMode::Default(),
base::CommandLine::StringType(), kChannelString, kMaxLogSizeBytes, base::CommandLine::StringType(),
URLRequestContextGetterList()); kChannelString, URLRequestContextGetterList());
// Now run the main message loop. Make sure StartNetLog() was ignored by // Now run the main message loop. Make sure StartNetLog() was ignored by
// checking that the next two states are "initializing" followed by // checking that the next two states are "initializing" followed by
...@@ -776,8 +777,8 @@ TEST_F(NetExportFileWriterTest, ReceiveStartWhileStoppingLog) { ...@@ -776,8 +777,8 @@ TEST_F(NetExportFileWriterTest, ReceiveStartWhileStoppingLog) {
// |file_writer_| finishes stopping, which means this should be a // |file_writer_| finishes stopping, which means this should be a
// no-op. // no-op.
file_writer_.StartNetLog(base::FilePath(), net::NetLogCaptureMode::Default(), file_writer_.StartNetLog(base::FilePath(), net::NetLogCaptureMode::Default(),
base::CommandLine::StringType(), kChannelString, kMaxLogSizeBytes, base::CommandLine::StringType(),
URLRequestContextGetterList()); kChannelString, URLRequestContextGetterList());
// Now run the main message loop. Make sure the last StartNetLog() was // Now run the main message loop. Make sure the last StartNetLog() was
// ignored by checking that the next two states are "stopping-log" followed by // ignored by checking that the next two states are "stopping-log" followed by
......
...@@ -20,7 +20,7 @@ button { ...@@ -20,7 +20,7 @@ button {
font-weight: bold; font-weight: bold;
margin: 10px auto; margin: 10px auto;
padding: 1em; padding: 1em;
width: 14em; width: 15em;
} }
h2 { h2 {
......
...@@ -70,6 +70,13 @@ ...@@ -70,6 +70,13 @@
Include raw bytes (will include cookies and credentials) Include raw bytes (will include cookies and credentials)
</label> </label>
</div> </div>
<div>
<label>
Maximum log size (megabytes):
<input id='log-max-filesize' value="100" size="4" />
(Blank means unlimited).
</label>
</div>
</div> </div>
</div> </div>
...@@ -136,9 +143,12 @@ ...@@ -136,9 +143,12 @@
<div id="toobig-read-more"> <div id="toobig-read-more">
<ul> <ul>
<li>Compressing the log file before attaching is a good idea.</li> <li>The maximum log size can be specified when starting
<li>If the log file is still too big, you can try capturing again, logging.</li>
but over a shorter period of time</li> <li>Compressing the log file before attaching is a good
idea.</li>
<li>Capture logs over a shorter period of time; stop
logging once the issue has reproduced.</li>
<li>Existing log files can be shrunk using <li>Existing log files can be shrunk using
<a <a
href="https://chromium.googlesource.com/chromium/src/+/master/net/tools/truncate_net_log.py" href="https://chromium.googlesource.com/chromium/src/+/master/net/tools/truncate_net_log.py"
......
...@@ -37,6 +37,7 @@ var NetExportView = (function() { ...@@ -37,6 +37,7 @@ var NetExportView = (function() {
var kIdPrivacyReadMoreDiv = 'privacy-read-more' var kIdPrivacyReadMoreDiv = 'privacy-read-more'
var kIdTooBigReadMoreLink = 'toobig-read-more-link'; var kIdTooBigReadMoreLink = 'toobig-read-more-link';
var kIdTooBigReadMoreDiv = 'toobig-read-more' var kIdTooBigReadMoreDiv = 'toobig-read-more'
var kIdLogMaxFileSizeInput = 'log-max-filesize'
/** /**
* @constructor * @constructor
...@@ -56,9 +57,21 @@ var NetExportView = (function() { ...@@ -56,9 +57,21 @@ var NetExportView = (function() {
* Starts saving NetLog data to a file. * Starts saving NetLog data to a file.
*/ */
onStartLogging_: function() { onStartLogging_: function() {
// Determine the capture mode to use.
var logMode = var logMode =
document.querySelector('input[name="log-mode"]:checked').value; document.querySelector('input[name="log-mode"]:checked').value;
chrome.send('startNetLog', [logMode]);
// Determine the maximum file size, as the number of bytes (or -1 to mean
// no limit)
var maxLogFileSizeBytes = -1;
var fileSizeString = $(kIdLogMaxFileSizeInput).value;
var numMegabytes = parseFloat(fileSizeString);
if (!isNaN(numMegabytes)) {
// Convert to an integral number of bytes.
maxLogFileSizeBytes = Math.round(numMegabytes * 1024 * 1024);
}
chrome.send('startNetLog', [logMode, maxLogFileSizeBytes]);
}, },
/** /**
......
...@@ -135,14 +135,24 @@ void NetExportMessageHandler::OnEnableNotifyUIWithState( ...@@ -135,14 +135,24 @@ void NetExportMessageHandler::OnEnableNotifyUIWithState(
void NetExportMessageHandler::OnStartNetLog(const base::ListValue* list) { void NetExportMessageHandler::OnStartNetLog(const base::ListValue* list) {
DCHECK_CURRENTLY_ON(web::WebThread::UI); DCHECK_CURRENTLY_ON(web::WebThread::UI);
std::string capture_mode_string;
bool result = list->GetString(0, &capture_mode_string);
DCHECK(result);
net::NetLogCaptureMode capture_mode = const base::Value::ListStorage& params = list->GetList();
net_log::NetExportFileWriter::CaptureModeFromString(capture_mode_string);
// Determine the capture mode.
net::NetLogCaptureMode capture_mode = net::NetLogCaptureMode::Default();
if (params.size() > 0 && params[0].is_string()) {
capture_mode = net_log::NetExportFileWriter::CaptureModeFromString(
params[0].GetString());
}
// Determine the max file size.
size_t max_log_file_size = net_log::NetExportFileWriter::kNoLimit;
if (params.size() > 1 && params[1].is_int() && params[1].GetInt() > 0) {
max_log_file_size = params[1].GetInt();
}
file_writer_->StartNetLog( file_writer_->StartNetLog(
base::FilePath(), capture_mode, base::FilePath(), capture_mode, max_log_file_size,
base::CommandLine::ForCurrentProcess()->GetCommandLineString(), base::CommandLine::ForCurrentProcess()->GetCommandLineString(),
GetChannelString(), GetChannelString(),
{GetApplicationContext()->GetSystemURLRequestContext()}); {GetApplicationContext()->GetSystemURLRequestContext()});
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment