summaryrefslogtreecommitdiffstats
path: root/net/base
diff options
context:
space:
mode:
authoreroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-10 23:13:56 +0000
committereroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-10 23:13:56 +0000
commit6e76d8d105739f3b40274dd0247a75ea44e46a89 (patch)
treed3b8ba9605783f4ef28cfe2726b9c38b0e57eb23 /net/base
parent02e7a01ff83e7e6aa637809ca43cff5da5dbe1c0 (diff)
downloadchromium_src-6e76d8d105739f3b40274dd0247a75ea44e46a89.zip
chromium_src-6e76d8d105739f3b40274dd0247a75ea44e46a89.tar.gz
chromium_src-6e76d8d105739f3b40274dd0247a75ea44e46a89.tar.bz2
Replace about:net-internals with the javascript-based frontend.
(DNS request tracing is the only feature lost in this transition; it needs to be added back under the new framework). BUG=37421 Review URL: http://codereview.chromium.org/2008007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@46868 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base')
-rw-r--r--net/base/host_resolver_impl.cc170
-rw-r--r--net/base/host_resolver_impl.h14
-rw-r--r--net/base/net_log.h4
-rw-r--r--net/base/net_log_util.cc235
-rw-r--r--net/base/net_log_util.h76
-rw-r--r--net/base/net_log_util_unittest.cc132
6 files changed, 3 insertions, 628 deletions
diff --git a/net/base/host_resolver_impl.cc b/net/base/host_resolver_impl.cc
index 1b5eb78..ffaada3 100644
--- a/net/base/host_resolver_impl.cc
+++ b/net/base/host_resolver_impl.cc
@@ -155,70 +155,24 @@ class HostResolverImpl::Request {
//-----------------------------------------------------------------------------
-// Threadsafe log.
-class HostResolverImpl::RequestsTrace
- : public base::RefCountedThreadSafe<HostResolverImpl::RequestsTrace> {
- public:
- RequestsTrace() {}
-
- void Add(const std::string& msg) {
- CapturingNetLog::Entry entry(NetLog::TYPE_TODO_STRING,
- base::TimeTicks::Now(),
- NetLog::Source(),
- NetLog::PHASE_NONE,
- new NetLogStringParameter("todo", msg));
- AutoLock l(lock_);
- entries_.push_back(entry);
- }
-
- void Get(CapturingNetLog::EntryList* entries) {
- AutoLock l(lock_);
- *entries = entries_;
- }
-
- void Clear() {
- AutoLock l(lock_);
- entries_.clear();
- }
-
- private:
- Lock lock_;
- CapturingNetLog::EntryList entries_;
-};
-
-//-----------------------------------------------------------------------------
-
// This class represents a request to the worker pool for a "getaddrinfo()"
// call.
class HostResolverImpl::Job
: public base::RefCountedThreadSafe<HostResolverImpl::Job> {
public:
- Job(int id, HostResolverImpl* resolver, const Key& key,
- RequestsTrace* requests_trace)
+ Job(int id, HostResolverImpl* resolver, const Key& key)
: id_(id),
key_(key),
resolver_(resolver),
origin_loop_(MessageLoop::current()),
resolver_proc_(resolver->effective_resolver_proc()),
- requests_trace_(requests_trace),
error_(OK),
had_non_speculative_request_(false) {
- if (requests_trace_) {
- requests_trace_->Add(StringPrintf(
- "Created job j%d for {hostname='%s', address_family=%d}",
- id_, key.hostname.c_str(),
- static_cast<int>(key.address_family)));
- }
}
// Attaches a request to this job. The job takes ownership of |req| and will
// take care to delete it.
void AddRequest(Request* req) {
- if (requests_trace_) {
- requests_trace_->Add(StringPrintf(
- "Attached request r%d to job j%d", req->id(), id_));
- }
-
req->set_job(this);
requests_.push_back(req);
@@ -228,9 +182,6 @@ class HostResolverImpl::Job
// Called from origin loop.
void Start() {
- if (requests_trace_)
- requests_trace_->Add(StringPrintf("Starting job j%d", id_));
-
start_time_ = base::TimeTicks::Now();
// Dispatch the job to a worker thread.
@@ -252,9 +203,6 @@ class HostResolverImpl::Job
HostResolver* resolver = resolver_;
resolver_ = NULL;
- if (requests_trace_)
- requests_trace_->Add(StringPrintf("Cancelled job j%d", id_));
-
// Mark the job as cancelled, so when worker thread completes it will
// not try to post completion to origin loop.
{
@@ -320,11 +268,6 @@ class HostResolverImpl::Job
// objects (like MessageLoops, Singletons, etc). During shutdown these objects
// may no longer exist.
void DoLookup() {
- if (requests_trace_) {
- requests_trace_->Add(StringPrintf(
- "[resolver thread] Running job j%d", id_));
- }
-
// Running on the worker thread
error_ = ResolveAddrInfo(resolver_proc_,
key_.hostname,
@@ -332,11 +275,6 @@ class HostResolverImpl::Job
key_.host_resolver_flags,
&results_);
- if (requests_trace_) {
- requests_trace_->Add(StringPrintf(
- "[resolver thread] Completed job j%d", id_));
- }
-
// The origin loop could go away while we are trying to post to it, so we
// need to call its PostTask method inside a lock. See ~HostResolver.
{
@@ -358,13 +296,6 @@ class HostResolverImpl::Job
base::TimeDelta job_duration = base::TimeTicks::Now() - start_time_;
- if (requests_trace_) {
- requests_trace_->Add(StringPrintf(
- "Completing job j%d (took %d milliseconds)",
- id_,
- static_cast<int>(job_duration.InMilliseconds())));
- }
-
if (had_non_speculative_request_) {
// TODO(eroman): Add histogram for job times of non-speculative
// requests.
@@ -403,9 +334,6 @@ class HostResolverImpl::Job
// reference ensures that it remains valid until we are done.
scoped_refptr<HostResolverProc> resolver_proc_;
- // Thread safe log to write details into, or NULL.
- scoped_refptr<RequestsTrace> requests_trace_;
-
// Assigned on the worker thread, read on the origin thread.
int error_;
@@ -868,72 +796,6 @@ void HostResolverImpl::Shutdown() {
DiscardIPv6ProbeJob();
}
-void HostResolverImpl::ClearRequestsTrace() {
- if (requests_trace_)
- requests_trace_->Clear();
-}
-
-void HostResolverImpl::EnableRequestsTracing(bool enable) {
- requests_trace_ = enable ? new RequestsTrace : NULL;
- if (enable) {
- // Print the state of the world when logging was started.
- requests_trace_->Add("Enabled tracing");
- requests_trace_->Add(StringPrintf(
- "Current num outstanding jobs: %d",
- static_cast<int>(jobs_.size())));
-
- // Dump all of the outstanding jobs.
- if (!jobs_.empty()) {
- for (JobMap::iterator job_it = jobs_.begin();
- job_it != jobs_.end(); ++job_it) {
- Job* job = job_it->second;
-
- requests_trace_->Add(StringPrintf(
- "Outstanding job j%d for {host='%s', address_family=%d}, "
- "which was started at t=%d",
- job->id(),
- job->key().hostname.c_str(),
- static_cast<int>(job->key().address_family),
- static_cast<int>((job->start_time() - base::TimeTicks())
- .InMilliseconds())));
-
- // Dump all of the requests attached to this job.
- for (RequestsList::const_iterator req_it = job->requests().begin();
- req_it != job->requests().end(); ++req_it) {
- Request* req = *req_it;
- requests_trace_->Add(StringPrintf(
- " %sOutstanding request r%d is attached to job j%d "
- "{priority=%d, speculative=%d, referrer='%s'}",
- req->was_cancelled() ? "[CANCELLED] " : "",
- req->id(),
- job->id(),
- static_cast<int>(req->info().priority()),
- static_cast<int>(req->info().is_speculative()),
- req->info().referrer().spec().c_str()));
- }
- }
- }
-
- size_t total = 0u;
- for (size_t i = 0; i < arraysize(job_pools_); ++i)
- total += job_pools_[i]->GetNumPendingRequests();
-
- requests_trace_->Add(StringPrintf(
- "Number of queued requests: %d", static_cast<int>(total)));
- }
-}
-
-bool HostResolverImpl::IsRequestsTracingEnabled() const {
- return !!requests_trace_; // Cast to bool.
-}
-
-bool HostResolverImpl::GetRequestsTrace(CapturingNetLog::EntryList* entries) {
- if (!requests_trace_)
- return false;
- requests_trace_->Get(entries);
- return true;
-}
-
void HostResolverImpl::SetPoolConstraints(JobPoolIndex pool_index,
size_t max_outstanding_jobs,
size_t max_pending_requests) {
@@ -1014,20 +876,6 @@ void HostResolverImpl::OnStartRequest(const BoundNetLog& net_log,
const RequestInfo& info) {
net_log.BeginEvent(NetLog::TYPE_HOST_RESOLVER_IMPL, NULL);
- if (requests_trace_) {
- requests_trace_->Add(StringPrintf(
- "Received request r%d for {hostname='%s', port=%d, priority=%d, "
- "speculative=%d, address_family=%d, allow_cached=%d, referrer='%s'}",
- request_id,
- info.hostname().c_str(),
- info.port(),
- static_cast<int>(info.priority()),
- static_cast<int>(info.is_speculative()),
- static_cast<int>(info.address_family()),
- static_cast<int>(info.allow_cached_response()),
- info.referrer().spec().c_str()));
- }
-
// Notify the observers of the start.
if (!observers_.empty()) {
net_log.BeginEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONSTART, NULL);
@@ -1045,11 +893,6 @@ void HostResolverImpl::OnFinishRequest(const BoundNetLog& net_log,
int request_id,
const RequestInfo& info,
int error) {
- if (requests_trace_) {
- requests_trace_->Add(StringPrintf(
- "Finished request r%d with error=%d", request_id, error));
- }
-
// Notify the observers of the completion.
if (!observers_.empty()) {
net_log.BeginEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONFINISH, NULL);
@@ -1071,9 +914,6 @@ void HostResolverImpl::OnCancelRequest(const BoundNetLog& net_log,
const RequestInfo& info) {
net_log.AddEvent(NetLog::TYPE_CANCELLED, NULL);
- if (requests_trace_)
- requests_trace_->Add(StringPrintf("Cancelled request r%d", request_id));
-
// Notify the observers of the cancellation.
if (!observers_.empty()) {
net_log.BeginEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONCANCEL, NULL);
@@ -1176,7 +1016,7 @@ HostResolverImpl::Key HostResolverImpl::GetEffectiveKeyForRequest(
HostResolverImpl::Job* HostResolverImpl::CreateAndStartJob(Request* req) {
DCHECK(CanCreateJobForPool(*GetPoolForRequest(req)));
Key key = GetEffectiveKeyForRequest(req->info());
- scoped_refptr<Job> job = new Job(next_job_id_++, this, key, requests_trace_);
+ scoped_refptr<Job> job = new Job(next_job_id_++, this, key);
job->AddRequest(req);
AddOutstandingJob(job);
job->Start();
@@ -1184,9 +1024,6 @@ HostResolverImpl::Job* HostResolverImpl::CreateAndStartJob(Request* req) {
}
int HostResolverImpl::EnqueueRequest(JobPool* pool, Request* req) {
- if (requests_trace_)
- requests_trace_->Add(StringPrintf("Queued request r%d", req->id()));
-
scoped_ptr<Request> req_evicted_from_queue(
pool->InsertPendingRequest(req));
@@ -1195,9 +1032,6 @@ int HostResolverImpl::EnqueueRequest(JobPool* pool, Request* req) {
Request* r = req_evicted_from_queue.get();
int error = ERR_HOST_RESOLVER_QUEUE_TOO_LARGE;
- if (requests_trace_)
- requests_trace_->Add(StringPrintf("Evicted request r%d", r->id()));
-
OnFinishRequest(r->net_log(), r->id(), r->info(), error);
if (r == req)
diff --git a/net/base/host_resolver_impl.h b/net/base/host_resolver_impl.h
index 80ca2ca..938e52f 100644
--- a/net/base/host_resolver_impl.h
+++ b/net/base/host_resolver_impl.h
@@ -105,17 +105,6 @@ class HostResolverImpl : public HostResolver,
// Returns the cache this resolver uses, or NULL if caching is disabled.
HostCache* cache() { return cache_.get(); }
- // Clears the request trace log.
- void ClearRequestsTrace();
-
- // Starts/ends capturing requests to a trace log.
- void EnableRequestsTracing(bool enable);
-
- bool IsRequestsTracingEnabled() const;
-
- // Gets a copy of the requests trace log.
- bool GetRequestsTrace(CapturingNetLog::EntryList* entries);
-
// Applies a set of constraints for requests that belong to the specified
// pool. NOTE: Don't call this after requests have been already been started.
//
@@ -136,7 +125,6 @@ class HostResolverImpl : public HostResolver,
class JobPool;
class IPv6ProbeJob;
class Request;
- class RequestsTrace;
typedef std::vector<Request*> RequestsList;
typedef HostCache::Key Key;
typedef std::map<Key, scoped_refptr<Job> > JobMap;
@@ -256,8 +244,6 @@ class HostResolverImpl : public HostResolver,
NetworkChangeNotifier* const network_change_notifier_;
- scoped_refptr<RequestsTrace> requests_trace_;
-
// Indicate if probing is done after each network change event to set address
// family.
// When false, explicit setting of address family is used.
diff --git a/net/base/net_log.h b/net/base/net_log.h
index ba271c5..69676b7 100644
--- a/net/base/net_log.h
+++ b/net/base/net_log.h
@@ -31,9 +31,7 @@ namespace net {
// ******** The NetLog (and associated logging) is a work in progress ********
//
// TODO(eroman): Remove the 'const' qualitifer from the BoundNetLog methods.
-// TODO(eroman): Remove NetLogUtil. Pretty printing should only be done from
-// javascript, and should be very context-aware.
-// TODO(eroman): Make the DNS jobs emit directly into the NetLog.
+// TODO(eroman): Make the DNS jobs emit into the NetLog.
// TODO(eroman): Start a new Source each time URLRequest redirects
// (simpler to reason about each as a separate entity).
// TODO(eroman): Add the URLRequest load flags to the start entry.
diff --git a/net/base/net_log_util.cc b/net/base/net_log_util.cc
deleted file mode 100644
index b5339b9..0000000
--- a/net/base/net_log_util.cc
+++ /dev/null
@@ -1,235 +0,0 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "net/base/net_log_util.h"
-
-#include "base/format_macros.h"
-#include "base/json/json_writer.h"
-#include "base/string_util.h"
-#include "base/values.h"
-#include "net/base/net_errors.h"
-
-namespace net {
-namespace {
-
-class FormatHelper {
- public:
- std::string ToString(const std::vector<CapturingNetLog::Entry>& entries,
- size_t num_entries_truncated) {
- entries_.clear();
-
- // Pass 1: Match the start/end of indentation blocks. Fills |entries_|
- // with the results.
- PopulateEntries(entries);
-
- // Pass 2: Figure out the maximum width of each column. This allows us
- // to right-justify text within each column.
- size_t max_time_width, max_indentation, max_type_width, max_dt_width;
- GetMaxExtent(
- &max_time_width, &max_indentation, &max_type_width, &max_dt_width);
-
- // Pass 3: Assemble the string.
- std::string result;
-
- const int kSpacesPerIndentation = 2;
-
- for (size_t i = 0; i < entries_.size(); ++i) {
- if (num_entries_truncated > 0 && i + 1 == entries_.size()) {
- StringAppendF(&result, " ... Truncated %" PRIuS " entries ...\n",
- num_entries_truncated);
- }
-
- if (entries_[i].block_index != -1 &&
- static_cast<size_t>(entries_[i].block_index + 1) == i) {
- // If there were no entries in between the START/END block then don't
- // bother printing a line for END (it just adds noise, and we already
- // show the time delta besides START anyway).
- continue;
- }
-
- int indentation_spaces = entries_[i].indentation * kSpacesPerIndentation;
- std::string entry_str = GetEntryString(i);
-
- StringAppendF(&result, "t=%s: %s%s",
- PadStringLeft(GetTimeString(i), max_time_width).c_str(),
- PadStringLeft("", indentation_spaces).c_str(),
- entry_str.c_str());
-
- if (entries_[i].IsBeginEvent()) {
- // Summarize how long this block lasted.
- int padding = ((max_indentation - entries_[i].indentation) *
- kSpacesPerIndentation) + (max_type_width - entry_str.size());
- StringAppendF(&result, "%s [dt=%s]",
- PadStringLeft("", padding).c_str(),
- PadStringLeft(GetBlockDtString(i), max_dt_width).c_str());
- }
-
- // Append any custom parameters.
- NetLog::EventParameters* extra_params =
- entries_[i].log_entry->extra_parameters;
-
- if (extra_params) {
- std::string extra_details;
- scoped_ptr<Value> extra_details_value(extra_params->ToValue());
- base::JSONWriter::Write(extra_details_value.get(), true,
- &extra_details);
- // JSON writer uses CR LF in its pretty-printer. Normalize to newlines.
- ReplaceSubstringsAfterOffset(&extra_details, 0, "\r\n", "\n");
- result.append("\n");
- result.append(extra_details);
- }
-
- if (!extra_params && i + 1 != entries_.size())
- result += "\n";
- }
-
- return result;
- }
-
- private:
- struct Entry {
- explicit Entry(const CapturingNetLog::Entry* log_entry)
- : log_entry(log_entry), indentation(0), block_index(-1) {}
-
- bool IsBeginEvent() const {
- return log_entry->phase == NetLog::PHASE_BEGIN;
- }
-
- bool IsEndEvent() const {
- return log_entry->phase == NetLog::PHASE_END;
- }
-
- const CapturingNetLog::Entry* log_entry;
- size_t indentation;
- int block_index; // The index of the matching start / end of block.
- };
-
- void PopulateEntries(const std::vector<CapturingNetLog::Entry>& entries) {
- int current_indentation = 0;
-
- for (size_t i = 0; i < entries.size(); ++i) {
- Entry entry(&entries[i]);
-
- entry.indentation = current_indentation;
-
- if (entry.IsBeginEvent()) {
- // Indent everything contained in this block.
- current_indentation++;
- }
-
- if (entry.IsEndEvent()) {
- int start_index = FindStartOfBlockIndex(entry);
- if (start_index != -1) {
- // Point the start / end of block at each other.
- entry.block_index = start_index;
- entries_[start_index].block_index = i;
-
- // Restore the indentation prior to the block.
- // (Could be more than 1 level if close of blocks are missing).
- current_indentation = entries_[start_index].indentation;
- entry.indentation = current_indentation;
- }
- }
-
- entries_.push_back(entry);
- }
- }
-
- int FindStartOfBlockIndex(const Entry& entry) {
- DCHECK(entry.IsEndEvent());
-
- // Find the matching start of block by scanning backwards.
- for (int i = entries_.size() - 1; i >= 0; --i) {
- if (entries_[i].IsBeginEvent() &&
- entries_[i].log_entry->type == entry.log_entry->type) {
- return i;
- }
- }
- return -1; // Start not found.
- }
-
- void GetMaxExtent(size_t* max_time_width,
- size_t* max_indentation,
- size_t* max_type_width,
- size_t* max_dt_width) {
- *max_time_width = *max_indentation = *max_type_width = *max_dt_width = 0;
- for (size_t i = 0; i < entries_.size(); ++i) {
- *max_time_width = std::max(*max_time_width, GetTimeString(i).size());
- if (entries_[i].log_entry->phase != NetLog::PHASE_NONE)
- *max_type_width = std::max(*max_type_width, GetEntryString(i).size());
- *max_indentation = std::max(*max_indentation, entries_[i].indentation);
-
- if (entries_[i].IsBeginEvent())
- *max_dt_width = std::max(*max_dt_width, GetBlockDtString(i).size());
- }
- }
-
- std::string GetBlockDtString(size_t start_index) {
- int end_index = entries_[start_index].block_index;
- if (end_index == -1) {
- // Block is not closed, implicitly close it at EOF.
- end_index = entries_.size() - 1;
- }
- int64 dt_ms = (entries_[end_index].log_entry->time -
- entries_[start_index].log_entry->time).InMilliseconds();
-
- return Int64ToString(dt_ms);
- }
-
- std::string GetTimeString(size_t index) {
- int64 t_ms = (entries_[index].log_entry->time -
- base::TimeTicks()).InMilliseconds();
- return Int64ToString(t_ms);
- }
-
- std::string GetEntryString(size_t index) {
- const CapturingNetLog::Entry* entry = entries_[index].log_entry;
-
- std::string entry_str;
- NetLog::EventPhase phase = entry->phase;
-
- entry_str = NetLog::EventTypeToString(entry->type);
-
- if (phase == NetLog::PHASE_BEGIN &&
- index + 1 < entries_.size() &&
- static_cast<size_t>(entries_[index + 1].block_index) == index) {
- // If this starts an empty block, we will pretend it is a PHASE_NONE
- // so we don't print the "+" prefix.
- phase = NetLog::PHASE_NONE;
- }
-
- switch (phase) {
- case NetLog::PHASE_BEGIN:
- return std::string("+") + entry_str;
- case NetLog::PHASE_END:
- return std::string("-") + entry_str;
- case NetLog::PHASE_NONE:
- return std::string(" ") + entry_str;
- default:
- NOTREACHED();
- return std::string();
- }
- }
-
- static std::string PadStringLeft(const std::string& str, size_t width) {
- DCHECK_LE(str.size(), width);
- std::string padding;
- padding.resize(width - str.size(), ' ');
- return padding + str;
- }
-
- std::vector<Entry> entries_;
-};
-
-} // namespace
-
-// static
-std::string NetLogUtil::PrettyPrintAsEventTree(
- const std::vector<CapturingNetLog::Entry>& entries,
- size_t num_entries_truncated) {
- FormatHelper helper;
- return helper.ToString(entries, num_entries_truncated);
-}
-
-} // namespace net
diff --git a/net/base/net_log_util.h b/net/base/net_log_util.h
deleted file mode 100644
index 0d603e8..0000000
--- a/net/base/net_log_util.h
+++ /dev/null
@@ -1,76 +0,0 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef NET_BASE_NET_LOG_UTIL_H_
-#define NET_BASE_NET_LOG_UTIL_H_
-
-#include <string>
-#include <vector>
-
-#include "base/basictypes.h"
-#include "net/base/capturing_net_log.h"
-
-namespace net {
-
-// The NetLogUtil utility class contains methods to analyze and visualize
-// NetLog entries.
-
-class NetLogUtil {
- public:
- struct EventDuration {
- NetLog::EventType event;
- base::TimeDelta duration;
- };
- typedef std::vector<EventDuration> EventDurationList;
-
- // Builds a pretty printed ASCII tree showing the chronological order
- // of events.
- //
- // The indentation reflects hiearchy, with the duration of each indented
- // block noted on the right. The timestamp (tick count in milliseconds)
- // is noted in the left column.
- //
- // This detailed view of what went into servicing a request can be used
- // in logs, and is copy-pastable by users, for attaching to bug reports.
- //
- // Example A:
- //
- // t=0: +Event1 [dt = 8]
- // t=1: +Event2 [dt = 0]
- // t=1: EventX
- // t=1: -Event2
- // t=4: +Event3 [dt = 2]
- // t=6: -Event3
- // t=6: +Event2 [dt = 1]
- // t=7: -Event2
- // t=8: EventY
- // t=8: -Event1
- //
- // Here we can see that:
- // - Event1 started at t=0 and ended at t=8; the duration was 8 time units.
- // - Event2 took place while Event1 was in progress, and was repeated
- // at t=1 and t=6.
- // - EventX took place while (the first) Event2 was in progress.
- // - Event3 started and ended at the same time, taking 0 time.
- // - EventY took place right before Event1 finished, at t=8
- //
- // In general the rules are:
- // - Log entries added by BeginEvent() are prefixed with a '+' and
- // start an indentation block.
- // - Log entries added by EndEvent() are prefixed with a '-' and
- // finish an indentation block.
- // - Log entries added by AddEvent() have no prefix.
- // - Time units are given as milliseconds.
- //
- static std::string PrettyPrintAsEventTree(
- const std::vector<CapturingNetLog::Entry>& entries,
- size_t num_entries_truncated);
-
- private:
- DISALLOW_IMPLICIT_CONSTRUCTORS(NetLogUtil);
-};
-
-} // namespace net
-
-#endif // NET_BASE_NET_LOG_UTIL_H_
diff --git a/net/base/net_log_util_unittest.cc b/net/base/net_log_util_unittest.cc
deleted file mode 100644
index 98de4bc..0000000
--- a/net/base/net_log_util_unittest.cc
+++ /dev/null
@@ -1,132 +0,0 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "net/base/net_log_unittest.h"
-#include "net/base/net_log_util.h"
-#include "net/base/net_errors.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace net {
-namespace {
-
-CapturingNetLog::Entry MakeEventEntry(int t,
- NetLog::EventType event_type,
- NetLog::EventPhase event_phase) {
- return CapturingNetLog::Entry(event_type,
- MakeTime(t),
- NetLog::Source(),
- event_phase,
- NULL);
-}
-
-TEST(NetLogUtilTest, Basic) {
- CapturingNetLog::EntryList log;
-
- log.push_back(MakeEventEntry(1, NetLog::TYPE_HOST_RESOLVER_IMPL,
- NetLog::PHASE_BEGIN));
- log.push_back(
- MakeEventEntry(5, NetLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONSTART,
- NetLog::PHASE_BEGIN));
- log.push_back(
- MakeEventEntry(8, NetLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONSTART,
- NetLog::PHASE_END));
-
- log.push_back(MakeEventEntry(12, NetLog::TYPE_CANCELLED,
- NetLog::PHASE_NONE));
-
- log.push_back(MakeEventEntry(131, NetLog::TYPE_HOST_RESOLVER_IMPL,
- NetLog::PHASE_END));
-
- EXPECT_EQ(
- "t= 1: +HOST_RESOLVER_IMPL [dt=130]\n"
- "t= 5: HOST_RESOLVER_IMPL_OBSERVER_ONSTART [dt= 3]\n"
- "t= 12: CANCELLED\n"
- "t=131: -HOST_RESOLVER_IMPL",
- NetLogUtil::PrettyPrintAsEventTree(log, 0));
-}
-
-TEST(NetLogUtilTest, Basic2) {
- CapturingNetLog::EntryList log;
-
- log.push_back(MakeEventEntry(1, NetLog::TYPE_HOST_RESOLVER_IMPL,
- NetLog::PHASE_BEGIN));
-
- // Attach a string parameter to a CANCELLED event.
- CapturingNetLog::Entry e =
- MakeEventEntry(12, NetLog::TYPE_CANCELLED, NetLog::PHASE_NONE);
- e.extra_parameters =
- new NetLogStringParameter("string_name", "string_value");
- log.push_back(e);
-
- log.push_back(MakeEventEntry(131, NetLog::TYPE_HOST_RESOLVER_IMPL,
- NetLog::PHASE_END));
-
- EXPECT_EQ(
- "t= 1: +HOST_RESOLVER_IMPL [dt=130]\n"
- "t= 12: CANCELLED\n"
- "{\n"
- " \"string_name\": \"string_value\"\n"
- "}\n"
- "t=131: -HOST_RESOLVER_IMPL",
- NetLogUtil::PrettyPrintAsEventTree(log, 0));
-}
-
-TEST(NetLogUtilTest, UnmatchedOpen) {
- CapturingNetLog::EntryList log;
-
- log.push_back(MakeEventEntry(3, NetLog::TYPE_HOST_RESOLVER_IMPL,
- NetLog::PHASE_BEGIN));
- // Note that there is no matching call to PHASE_END for all of the following.
- log.push_back(
- MakeEventEntry(
- 6, NetLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONSTART,
- NetLog::PHASE_BEGIN));
- log.push_back(
- MakeEventEntry(7, NetLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONSTART,
- NetLog::PHASE_BEGIN));
- log.push_back(
- MakeEventEntry(8, NetLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONSTART,
- NetLog::PHASE_BEGIN));
- log.push_back(MakeEventEntry(10, NetLog::TYPE_CANCELLED,
- NetLog::PHASE_NONE));
- log.push_back(MakeEventEntry(16, NetLog::TYPE_HOST_RESOLVER_IMPL,
- NetLog::PHASE_END));
-
- EXPECT_EQ(
- "t= 3: +HOST_RESOLVER_IMPL [dt=13]\n"
- "t= 6: +HOST_RESOLVER_IMPL_OBSERVER_ONSTART [dt=10]\n"
- "t= 7: +HOST_RESOLVER_IMPL_OBSERVER_ONSTART [dt= 9]\n"
- "t= 8: +HOST_RESOLVER_IMPL_OBSERVER_ONSTART [dt= 8]\n"
- "t=10: CANCELLED\n"
- "t=16: -HOST_RESOLVER_IMPL",
- NetLogUtil::PrettyPrintAsEventTree(log, 0));
-}
-
-TEST(NetLogUtilTest, DisplayOfTruncated) {
- CapturingNetLog::EntryList log;
-
- log.push_back(MakeEventEntry(0,
- NetLog::TYPE_TCP_CONNECT,
- NetLog::PHASE_BEGIN));
- for (size_t i = 1; i <= 3; ++i) {
- log.push_back(MakeEventEntry(i,
- NetLog::TYPE_CANCELLED,
- NetLog::PHASE_NONE));
- }
- log.push_back(MakeEventEntry(9,
- NetLog::TYPE_TCP_CONNECT,
- NetLog::PHASE_END));
-
- EXPECT_EQ(
- "t=0: +TCP_CONNECT [dt=9]\n"
- "t=1: CANCELLED\n"
- "t=2: CANCELLED\n"
- "t=3: CANCELLED\n"
- " ... Truncated 4 entries ...\n"
- "t=9: -TCP_CONNECT",
- NetLogUtil::PrettyPrintAsEventTree(log, 4));
-}
-
-} // namespace
-} // namespace net