Commit 3f095c0a authored by joth@chromium.org's avatar joth@chromium.org

Revert 107895 - Fully enable about:tracking by default

This is a re-land of:
http://codereview.chromium.org/8391019/
Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=107793

Original landing had trouble with message_loop_x.h, due to header
include ordering.  I pulled out the structure that was really needed by
tracked_objects.h into a new file tracked_info.*.  This allows tracked_objects
to inlude this tracked_info, but not have to include the message_loop.h
totality.  I also removed a DCHECK that that was triggering on a test,
and added yet one more file (browser_main.cc) where I removed a #ifdef
for TRACKING_ALL_OBJECTS.  The changes were minor, and I'm hoping to get
clear perf runs with tihs landing, so I'm going to TBR it and reland
early in the morning.



Comments from original landing:

Support is now controlled by the flag:
--enable-tracking
and the default is always on. To turn it off, use:
--enable-tracking=0

All profiler code is compiled now in release and official
builds (in addition to debug, where it was already active),
but most entry points can be disabled (turned into no-ops) 
by a single const bool setting atop tracked_objects.cc (in 
case folks want to revert the perf-impact of this change).

Transition to faster Now() service on Windows for the 
profiler use only.
The TimeTicks::Now() function on Window uses locking
to get a 64 bit time value. This CL transitions 
times used for profiling to more directly use a
32 bit Time interface, which is actually what drives the
64 bit TimeTicks. By using the smaller value, we avoid 
the need for locks, or even atomic operations for the most
part in the tracking system. On linux, we just down-sample
the standard TimeTicks to 32 bits for consistency (clean
ability to snapshot asyncronously without atomics...
but I should verify that such is helpful to performance).

I've also put in yet more cleanup and refactoring.

tbr=rtenneti
bug=101856
Review URL: http://codereview.chromium.org/8414036

TBR=jar@chromium.org
Review URL: http://codereview.chromium.org/8430004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@107961 0039d316-1c4b-4281-b951-d872f2087c98
parent a0645703
......@@ -336,8 +336,6 @@
'timer.h',
'tracked_objects.cc',
'tracked_objects.h',
'tracking_info.cc',
'tracking_info.h',
'tuple.h',
'utf_offset_string_conversions.cc',
'utf_offset_string_conversions.h',
......
......@@ -10,6 +10,12 @@
#include "base/base_export.h"
#include "base/values.h"
#ifndef NDEBUG
#ifndef TRACK_ALL_TASK_OBJECTS
#define TRACK_ALL_TASK_OBJECTS
#endif // TRACK_ALL_TASK_OBJECTS
#endif // NDEBUG
namespace tracked_objects {
// Location provides basic info where of an object was constructed, or was
......
......@@ -486,16 +486,20 @@ void MessageLoop::RunTask(const PendingTask& pending_task) {
HistogramEvent(kTaskRunEvent);
tracked_objects::TrackedTime start_time = tracked_objects::ThreadData::Now();
#if defined(TRACK_ALL_TASK_OBJECTS)
TimeTicks start_of_run = tracked_objects::ThreadData::Now();
#endif // defined(TRACK_ALL_TASK_OBJECTS)
FOR_EACH_OBSERVER(TaskObserver, task_observers_,
WillProcessTask(pending_task.time_posted));
pending_task.task.Run();
FOR_EACH_OBSERVER(TaskObserver, task_observers_,
DidProcessTask(pending_task.time_posted));
tracked_objects::ThreadData::TallyRunOnNamedThreadIfTracking(pending_task,
start_time, tracked_objects::ThreadData::Now());
#if defined(TRACK_ALL_TASK_OBJECTS)
tracked_objects::ThreadData::TallyADeathIfActive(pending_task.post_births,
pending_task.time_posted, pending_task.delayed_run_time, start_of_run,
tracked_objects::ThreadData::Now());
#endif // defined(TRACK_ALL_TASK_OBJECTS)
nestable_tasks_allowed_ = true;
}
......@@ -775,11 +779,15 @@ MessageLoop::PendingTask::PendingTask(
const tracked_objects::Location& posted_from,
TimeTicks delayed_run_time,
bool nestable)
: base::TrackingInfo(posted_from, delayed_run_time),
task(task),
: task(task),
time_posted(TimeTicks::Now()),
delayed_run_time(delayed_run_time),
posted_from(posted_from),
sequence_num(0),
nestable(nestable) {
#if defined(TRACK_ALL_TASK_OBJECTS)
post_births = tracked_objects::ThreadData::TallyABirthIfActive(posted_from);
#endif // defined(TRACK_ALL_TASK_OBJECTS)
}
MessageLoop::PendingTask::~PendingTask() {
......
......@@ -19,7 +19,6 @@
#include "base/observer_list.h"
#include "base/synchronization/lock.h"
#include "base/task.h"
#include "base/tracking_info.h"
#include "base/time.h"
#if defined(OS_WIN)
......@@ -45,9 +44,11 @@ namespace base {
class Histogram;
}
#if defined(TRACK_ALL_TASK_OBJECTS)
namespace tracked_objects {
class Births;
}
#endif // defined(TRACK_ALL_TASK_OBJECTS)
// A MessageLoop is used to process events for a particular thread. There is
// at most one MessageLoop instance per thread.
......@@ -409,7 +410,7 @@ class BASE_EXPORT MessageLoop : public base::MessagePump::Delegate {
#endif
// This structure is copied around by value.
struct PendingTask : public base::TrackingInfo {
struct PendingTask {
PendingTask(const base::Closure& task,
const tracked_objects::Location& posted_from,
base::TimeTicks delayed_run_time,
......@@ -422,6 +423,17 @@ class BASE_EXPORT MessageLoop : public base::MessagePump::Delegate {
// The task to run.
base::Closure task;
#if defined(TRACK_ALL_TASK_OBJECTS)
// Counter for location where the Closure was posted from.
tracked_objects::Births* post_births;
#endif // defined(TRACK_ALL_TASK_OBJECTS)
// Time this PendingTask was posted.
base::TimeTicks time_posted;
// The time when the task should be run.
base::TimeTicks delayed_run_time;
// The site this PendingTask was posted from.
tracked_objects::Location posted_from;
......
......@@ -152,7 +152,9 @@ void Thread::ThreadMain() {
ANNOTATE_THREAD_NAME(name_.c_str()); // Tell the name to race detector.
message_loop.set_thread_name(name_);
message_loop_ = &message_loop;
#if defined(TRACK_ALL_TASK_OBJECTS)
tracked_objects::ThreadData::InitializeThreadContext(name_);
#endif // TRACK_ALL_TASK_OBJECTS
// Let the thread do extra initialization.
// Let's do this before signaling we are started.
......
......@@ -88,14 +88,15 @@ void WorkerThread::ThreadMain() {
"src_file", pending_task.posted_from.file_name(),
"src_func", pending_task.posted_from.function_name());
tracked_objects::TrackedTime start_time =
tracked_objects::ThreadData::Now();
#if defined(TRACK_ALL_TASK_OBJECTS)
TimeTicks start_of_run = tracked_objects::ThreadData::Now();
#endif // defined(TRACK_ALL_TASK_OBJECTS)
pending_task.task.Run();
tracked_objects::ThreadData::TallyRunOnWorkerThreadIfTracking(
pending_task.birth_tally, pending_task.time_posted,
start_time, tracked_objects::ThreadData::Now());
#if defined(TRACK_ALL_TASK_OBJECTS)
tracked_objects::ThreadData::TallyADeathIfActive(pending_task.post_births,
pending_task.time_posted, TimeTicks(), start_of_run,
tracked_objects::ThreadData::Now());
#endif // defined(TRACK_ALL_TASK_OBJECTS)
}
// The WorkerThread is non-joinable, so it deletes itself.
......@@ -121,8 +122,10 @@ PosixDynamicThreadPool::PendingTask::PendingTask(
const base::Closure& task)
: posted_from(posted_from),
task(task) {
birth_tally = tracked_objects::ThreadData::TallyABirthIfActive(posted_from);
#if defined(TRACK_ALL_TASK_OBJECTS)
post_births = tracked_objects::ThreadData::TallyABirthIfActive(posted_from);
time_posted = tracked_objects::ThreadData::Now();
#endif // defined(TRACK_ALL_TASK_OBJECTS)
}
PosixDynamicThreadPool::PendingTask::~PendingTask() {
......
......@@ -53,11 +53,13 @@ class BASE_EXPORT PosixDynamicThreadPool
const base::Closure& task);
~PendingTask();
#if defined(TRACK_ALL_TASK_OBJECTS)
// Counter for location where the Closure was posted from.
tracked_objects::Births* birth_tally;
tracked_objects::Births* post_births;
// Time the task was posted.
tracked_objects::TrackedTime time_posted;
TimeTicks time_posted;
#endif // defined(TRACK_ALL_TASK_OBJECTS)
const tracked_objects::Location posted_from;
......
......@@ -20,15 +20,19 @@ struct PendingTask {
const base::Closure& task)
: posted_from(posted_from),
task(task) {
birth_tally = tracked_objects::ThreadData::TallyABirthIfActive(posted_from);
#if defined(TRACK_ALL_TASK_OBJECTS)
post_births = tracked_objects::ThreadData::TallyABirthIfActive(posted_from);
time_posted = tracked_objects::ThreadData::Now();
#endif // defined(TRACK_ALL_TASK_OBJECTS)
}
#if defined(TRACK_ALL_TASK_OBJECTS)
// Counter for location where the Closure was posted from.
tracked_objects::Births* birth_tally;
tracked_objects::Births* post_births;
// Time the task was posted.
tracked_objects::TrackedTime time_posted;
TimeTicks time_posted;
#endif // defined(TRACK_ALL_TASK_OBJECTS)
// The site this PendingTask was posted from.
tracked_objects::Location posted_from;
......@@ -43,13 +47,15 @@ DWORD CALLBACK WorkItemCallback(void* param) {
"src_file", pending_task->posted_from.file_name(),
"src_func", pending_task->posted_from.function_name());
tracked_objects::TrackedTime start_time = tracked_objects::ThreadData::Now();
#if defined(TRACK_ALL_TASK_OBJECTS)
TimeTicks start_of_run = tracked_objects::ThreadData::Now();
#endif // defined(TRACK_ALL_TASK_OBJECTS)
pending_task->task.Run();
tracked_objects::ThreadData::TallyRunOnWorkerThreadIfTracking(
pending_task->birth_tally, pending_task->time_posted,
start_time, tracked_objects::ThreadData::Now());
#if defined(TRACK_ALL_TASK_OBJECTS)
tracked_objects::ThreadData::TallyADeathIfActive(pending_task->post_births,
pending_task->time_posted, TimeTicks::TimeTicks(), start_of_run,
tracked_objects::ThreadData::Now());
#endif // defined(TRACK_ALL_TASK_OBJECTS)
delete pending_task;
return 0;
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
// Copyright (c) 2011 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 "base/tracking_info.h"
#include "base/tracked_objects.h"
namespace base {
TrackingInfo::TrackingInfo(
const tracked_objects::Location& posted_from,
base::TimeTicks delayed_run_time)
: birth_tally(
tracked_objects::ThreadData::TallyABirthIfActive(posted_from)),
time_posted(TimeTicks::Now()),
delayed_run_time(delayed_run_time) {
}
TrackingInfo::~TrackingInfo() {}
} // namespace base
// Copyright (c) 2011 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.
// This is a simple struct with tracking information that is stored
// with a PendingTask (when message_loop is handling the task).
// Only the information that is shared with the profiler in tracked_objects
// are included in this structure.
#ifndef BASE_TRACKING_INFO_H_
#define BASE_TRACKING_INFO_H_
#include "base/time.h"
namespace tracked_objects {
class Location;
class Births;
}
namespace base {
// This structure is copied around by value.
struct BASE_EXPORT TrackingInfo {
TrackingInfo(const tracked_objects::Location& posted_from,
base::TimeTicks delayed_run_time);
~TrackingInfo();
// Record of location and thread that the task came from.
tracked_objects::Births* birth_tally;
// Time when the related task was posted.
base::TimeTicks time_posted;
// The time when the task should be run.
base::TimeTicks delayed_run_time;
};
} // namespace base
#endif // BASE_TRACKING_INFO_H_
......@@ -145,9 +145,11 @@ const char* const kChromePaths[] = {
chrome::kChromeUITCMallocHost,
chrome::kChromeUITermsHost,
chrome::kChromeUITracingHost,
chrome::kChromeUITrackingHost,
chrome::kChromeUIVersionHost,
chrome::kChromeUIWorkersHost,
#if defined(TRACK_ALL_TASK_OBJECTS)
chrome::kChromeUITrackingHost,
#endif
#if defined(OS_WIN)
chrome::kChromeUIConflictsHost,
#endif
......@@ -182,8 +184,10 @@ const char* const kAboutSourceNames[] = {
chrome::kChromeUIStatsHost,
chrome::kChromeUITaskManagerHost,
chrome::kChromeUITermsHost,
chrome::kChromeUITrackingHost,
chrome::kChromeUIVersionHost,
#if defined(TRACK_ALL_TASK_OBJECTS)
chrome::kChromeUITrackingHost,
#endif
#if defined(USE_TCMALLOC)
chrome::kChromeUITCMallocHost,
#endif
......@@ -885,6 +889,7 @@ void AboutMemory(const std::string& path, AboutSource* source, int request_id) {
}
}
#if defined(TRACK_ALL_TASK_OBJECTS)
static std::string AboutTracking(const std::string& query) {
std::string unescaped_title("About Tracking");
if (!query.empty()) {
......@@ -898,6 +903,7 @@ static std::string AboutTracking(const std::string& query) {
AppendFooter(&data);
return data;
}
#endif // TRACK_ALL_TASK_OBJECTS
// Handler for filling in the "about:stats" page, as called by the browser's
// About handler processing.
......@@ -1468,8 +1474,10 @@ void AboutSource::StartDataRequest(const std::string& path,
#endif
} else if (host == chrome::kChromeUIStatsHost) {
response = AboutStats(path);
#if defined(TRACK_ALL_TASK_OBJECTS)
} else if (host == chrome::kChromeUITrackingHost) {
response = AboutTracking(path);
#endif
#if defined(USE_TCMALLOC)
} else if (host == chrome::kChromeUITCMallocHost) {
response = AboutTcmalloc();
......
......@@ -1217,13 +1217,6 @@ int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() {
browser_process_.reset(new BrowserProcessImpl(parsed_command_line()));
}
if (parsed_command_line().HasSwitch(switches::kEnableTracking)) {
std::string flag =
parsed_command_line().GetSwitchValueASCII(switches::kEnableTracking);
if (flag.compare("0") == 0)
tracked_objects::ThreadData::InitializeAndSetTrackingStatus(false);
}
// This forces the TabCloseableStateWatcher to be created and, on chromeos,
// register for the notifications it needs to track the closeable state of
// tabs.
......
......@@ -118,10 +118,12 @@ class ChromeBrowserMainParts : public content::BrowserMainParts {
// it is destroyed last.
scoped_ptr<ShutdownWatcherHelper> shutdown_watcher_;
#if defined(TRACK_ALL_TASK_OBJECTS)
// Creating this object starts tracking the creation and deletion of Task
// instance. This MUST be done before main_message_loop, so that it is
// destroyed after the main_message_loop.
tracked_objects::AutoTracking tracking_objects_;
#endif
// Statistical testing infrastructure for the entire browser. NULL until
// SetupMetricsAndFieldTrials is called.
......
......@@ -519,12 +519,6 @@ const char kDisablePanels[] = "disable-panels";
// Enables speculative TCP/IP preconnection.
const char kEnablePreconnect[] = "enable-preconnect";
// Controls the support for SDCH filtering (dictionary based expansion of
// content). By default SDCH filtering is enabled. To disable SDCH filtering,
// use "--enable-sdch=0" as command line argument. SDCH is currently only
// supported server-side for searches on google.com.
const char kEnableSdch[] = "enable-sdch";
// Enables the IsSearchProviderInstalled and InstallSearchProvider with an
// extra parameter to indicate if the provider should be the default.
const char kEnableSearchProviderApiV2[] = "enable-search-provider-api-v2";
......@@ -545,28 +539,21 @@ const char kEnableSyncOAuth[] = "enable-sync-oauth";
const char kEnableSyncSearchEngines[] = "enable-sync-search-engines";
// Enables syncing browser sessions.
const char kEnableSyncTabs[] = "enable-sync-tabs";
const char kEnableSyncTabs[] = "enable-sync-tabs";
// Enables syncing browser sessions for other synced clients.
const char kEnableSyncTabsForOtherClients[] =
"enable-sync-tabs-for-other-clients";
// Enable syncing app notifications.
const char kEnableSyncAppNotifications[] = "enable-sync-app-notifications";
const char kEnableSyncAppNotifications[] = "enable-sync-app-notifications";
// Enables context menu for selecting groups of tabs.
const char kEnableTabGroupsContextMenu[] = "enable-tab-groups-context-menu";
const char kEnableTabGroupsContextMenu[] = "enable-tab-groups-context-menu";
// Enables the "synced bookmarks" folder.
const char kEnableSyncedBookmarksFolder[] = "enable-synced-bookmarks-folder";
// Enables tracking of tasks in profiler for viewing via about:tracking.
// To predominantly disable tracking (profiling), use the command line switch:
// --enable-tracking=0
// Some tracking will still take place at startup, but it will be turned off
// during chrome_browser_main.
const char kEnableTracking[] = "enable-tracking";
// Spawns threads to watch for excessive delays in specified message loops.
// User should set breakpoints on Alarm() to examine problematic thread.
//
......@@ -976,6 +963,12 @@ const char kSbDisableAutoUpdate[] = "safebrowsing-disable-auto-update";
const char kSbDisableDownloadProtection[] =
"safebrowsing-disable-download-protection";
// Controls the support for SDCH filtering (dictionary based expansion of
// content). By default SDCH filtering is enabled. To disable SDCH filtering,
// use "--enable-sdch=0" as command line argument. SDCH is currently only
// supported server-side for searches on google.com.
const char kEnableSdch[] = "enable-sdch";
// Enables the showing of an info-bar instructing user they can search directly
// from the omnibox.
const char kSearchInOmniboxHint[] = "search-in-omnibox-hint";
......
......@@ -148,7 +148,6 @@ extern const char kEnableNTPBookmarkFeatures[];
extern const char kDisablePanels[];
extern const char kEnablePreconnect[];
extern const char kEnableResourceContentSettings[];
extern const char kEnableSdch[];
extern const char kEnableSearchProviderApiV2[];
extern const char kEnableShortcutsProvider[];
extern const char kEnableSmoothScrolling[];
......@@ -161,7 +160,6 @@ extern const char kEnableSyncTabs[];
extern const char kEnableSyncTabsForOtherClients[];
extern const char kEnableSyncAppNotifications[];
extern const char kEnableSyncedBookmarksFolder[];
extern const char kEnableTracking[];
extern const char kEnableTabGroupsContextMenu[];
extern const char kEnableTopSites[];
extern const char kEnableWatchdog[];
......@@ -264,6 +262,7 @@ extern const char kSbInfoURLPrefix[];
extern const char kSbMacKeyURLPrefix[];
extern const char kSbDisableAutoUpdate[];
extern const char kSbDisableDownloadProtection[];
extern const char kEnableSdch[];
extern const char kSearchInOmniboxHint[];
extern const char kServiceAccountLsid[];
extern const char kShowAutofillTypePredictions[];
......
......@@ -292,7 +292,10 @@ void BrowserMainLoop::InitializeMainThread() {
const char* kThreadName = "CrBrowserMain";
base::PlatformThread::SetName(kThreadName);
main_message_loop_->set_thread_name(kThreadName);
#if defined(TRACK_ALL_TASK_OBJECTS)
tracked_objects::ThreadData::InitializeThreadContext(kThreadName);
#endif // TRACK_ALL_TASK_OBJECTS
// Register the main thread by instantiating it, but don't call any methods.
main_thread_.reset(new BrowserThreadImpl(BrowserThread::UI,
......
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