Skip to content

Commit

Permalink
Disable timing from chrome://profiler on Android.
Browse files Browse the repository at this point in the history
On Android, on a arm CPU, TimeTicks::Now() is taking 900ns (20 times
what it takes on a desktop x86 CPU). The bigger user of TimeTicks::Now()
is tracked_objects::TrackedTime, and this impacts the overall
performance of Chrome on this platform.

This CL adds compile line flags that allows to disable
tracked_objects::TrackedTime. It also disable
tracked_objects::TrackedTime by default on Android.

BUG=315070

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@240092 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
qsr@chromium.org committed Dec 11, 2013
1 parent b7b044b commit 915b344
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 2 deletions.
8 changes: 8 additions & 0 deletions base/base_switches.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ const char kWaitForDebugger[] = "wait-for-debugger";
// Sends a pretty-printed version of tracing info to the console.
const char kTraceToConsole[] = "trace-to-console";

// Configure whether chrome://profiler will contain timing information. This
// option is enabled by default. A value of "0" will disable profiler timing,
// while all other values will enable it.
const char kProfilerTiming[] = "profiler-timing";
// Value of the --profiler-timing flag that will disable timing information for
// chrome://profiler.
const char kProfilerTimingDisabledValue[] = "0";

#if defined(OS_POSIX)
// Used for turning on Breakpad crash reporting in a debug environment where
// crash reporting is typically compiled but disabled.
Expand Down
4 changes: 3 additions & 1 deletion base/base_switches.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ extern const char kEnableCrashReporter[];
extern const char kEnableDCHECK[];
extern const char kFullMemoryCrashReport[];
extern const char kNoErrorDialogs[];
extern const char kProfilerTiming[];
extern const char kProfilerTimingDisabledValue[];
extern const char kTestChildProcess[];
extern const char kTraceToConsole[];
extern const char kV[];
extern const char kVModule[];
extern const char kWaitForDebugger[];
extern const char kTraceToConsole[];

#if defined(OS_POSIX)
extern const char kEnableCrashReporterForTesting[];
Expand Down
26 changes: 25 additions & 1 deletion base/tracked_objects.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include <limits.h>
#include <stdlib.h>

#include "base/base_switches.h"
#include "base/command_line.h"
#include "base/compiler_specific.h"
#include "base/debug/leak_annotations.h"
#include "base/logging.h"
Expand Down Expand Up @@ -51,6 +53,28 @@ const ThreadData::Status kInitialStartupState =
// problem with its presence).
static const bool kAllowAlternateTimeSourceHandling = true;

inline bool IsProfilerTimingEnabled() {
static enum {
UNDEFINED_TIMING,
ENABLED_TIMING,
DISABLED_TIMING,
} timing_enabled = UNDEFINED_TIMING;
// This initialization is not thread-safe, so the value of |timing_enabled|
// can be computed multiple times. This is not an issue, as the computed value
// will always be the same, and is side-effect free, while needing to use a
// lock or a memory barrier would be more costly.
if (timing_enabled == UNDEFINED_TIMING) {
if (!CommandLine::InitializedForCurrentProcess())
return true;
timing_enabled = (CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
switches::kProfilerTiming) ==
switches::kProfilerTimingDisabledValue)
? DISABLED_TIMING
: ENABLED_TIMING;
}
return timing_enabled == ENABLED_TIMING;
}

} // namespace

//------------------------------------------------------------------------------
Expand Down Expand Up @@ -754,7 +778,7 @@ void ThreadData::SetAlternateTimeSource(NowFunction* now_function) {
TrackedTime ThreadData::Now() {
if (kAllowAlternateTimeSourceHandling && now_function_)
return TrackedTime::FromMilliseconds((*now_function_)());
if (kTrackAllTaskObjects && TrackingStatus())
if (kTrackAllTaskObjects && IsProfilerTimingEnabled() && TrackingStatus())
return TrackedTime::Now();
return TrackedTime(); // Super fast when disabled, or not compiled.
}
Expand Down
7 changes: 7 additions & 0 deletions content/browser/android/content_startup_flags.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "content/browser/android/content_startup_flags.h"

#include "base/base_switches.h"
#include "base/command_line.h"
#include "base/logging.h"
#include "base/strings/string_number_conversions.h"
Expand Down Expand Up @@ -89,6 +90,12 @@ void SetContentCommandLineFlags(int max_render_process_count,
parsed_command_line->AppendSwitchNative(
switches::kRegisterPepperPlugins, plugin_descriptor);
}

// Disable profiler timing by default.
if (!parsed_command_line->HasSwitch(switches::kProfilerTiming)) {
parsed_command_line->AppendSwitchASCII(
switches::kProfilerTiming, switches::kProfilerTimingDisabledValue);
}
}

} // namespace content
1 change: 1 addition & 0 deletions content/browser/renderer_host/render_process_host_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1037,6 +1037,7 @@ void RenderProcessHostImpl::PropagateBrowserCommandLineToRenderer(
switches::kNoReferrers,
switches::kNoSandbox,
switches::kPpapiInProcess,
switches::kProfilerTiming,
switches::kRegisterPepperPlugins,
switches::kRendererAssertTest,
switches::kRendererStartupDialog,
Expand Down

0 comments on commit 915b344

Please sign in to comment.