Commit 96b0777d authored by Bryce Thomas's avatar Bryce Thomas Committed by Commit Bot

Add support for CPU profiling in headless_shell.

This CL factors CPU profiling code out of chrome/ and into content/ to support
CPU profiling Headless Chromium.  headless_content_main_delegate.cc has been
modified to honor CPU profiling flags à la chrome_main_delegate.cc.

Bug: 890456
Change-Id: I76842c5936de82d6bd42354c461aff9e0d273248
Reviewed-on: https://chromium-review.googlesource.com/c/1312157
Commit-Queue: Bryce Thomas <bryct@amazon.com>
Reviewed-by: default avatarDmitry Gozman <dgozman@chromium.org>
Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatarStefan Zager <szager@chromium.org>
Cr-Commit-Position: refs/heads/master@{#605942}
parent 6188dcc1
...@@ -81,6 +81,11 @@ const char kTraceToFile[] = "trace-to-file"; ...@@ -81,6 +81,11 @@ const char kTraceToFile[] = "trace-to-file";
// go to a default file name. // go to a default file name.
const char kTraceToFileName[] = "trace-to-file-name"; const char kTraceToFileName[] = "trace-to-file-name";
// Starts the sampling based profiler for the browser process at startup. This
// will only work if chrome has been built with the gn arg enable_profiling =
// true. The output will go to the value of kProfilingFile.
const char kProfilingAtStart[] = "profiling-at-start";
// Specifies a location for profiling output. This will only work if chrome has // Specifies a location for profiling output. This will only work if chrome has
// been built with the gyp variable profiling=1 or gn arg enable_profiling=true. // been built with the gyp variable profiling=1 or gn arg enable_profiling=true.
// //
...@@ -91,6 +96,12 @@ const char kTraceToFileName[] = "trace-to-file-name"; ...@@ -91,6 +96,12 @@ const char kTraceToFileName[] = "trace-to-file-name";
// for tests. // for tests.
const char kProfilingFile[] = "profiling-file"; const char kProfilingFile[] = "profiling-file";
// Controls whether profile data is periodically flushed to a file. Normally
// the data gets written on exit but cases exist where chromium doesn't exit
// cleanly (especially when using single-process). A time in seconds can be
// specified.
const char kProfilingFlush[] = "profiling-flush";
#if defined(OS_WIN) #if defined(OS_WIN)
// Disables the USB keyboard detection for blocking the OSK on Win8+. // Disables the USB keyboard detection for blocking the OSK on Win8+.
const char kDisableUsbKeyboardDetect[] = "disable-usb-keyboard-detect"; const char kDisableUsbKeyboardDetect[] = "disable-usb-keyboard-detect";
......
...@@ -21,7 +21,9 @@ extern const char kEnableLowEndDeviceMode[]; ...@@ -21,7 +21,9 @@ extern const char kEnableLowEndDeviceMode[];
extern const char kForceFieldTrials[]; extern const char kForceFieldTrials[];
extern const char kFullMemoryCrashReport[]; extern const char kFullMemoryCrashReport[];
extern const char kNoErrorDialogs[]; extern const char kNoErrorDialogs[];
extern const char kProfilingAtStart[];
extern const char kProfilingFile[]; extern const char kProfilingFile[];
extern const char kProfilingFlush[];
extern const char kTestChildProcess[]; extern const char kTestChildProcess[];
extern const char kTestDoNotInitializeIcu[]; extern const char kTestDoNotInitializeIcu[];
extern const char kTraceToFile[]; extern const char kTraceToFile[];
......
...@@ -36,7 +36,6 @@ ...@@ -36,7 +36,6 @@
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
#include "chrome/common/crash_keys.h" #include "chrome/common/crash_keys.h"
#include "chrome/common/logging_chrome.h" #include "chrome/common/logging_chrome.h"
#include "chrome/common/profiling.h"
#include "chrome/common/trace_event_args_whitelist.h" #include "chrome/common/trace_event_args_whitelist.h"
#include "chrome/common/url_constants.h" #include "chrome/common/url_constants.h"
#include "chrome/gpu/chrome_content_gpu_client.h" #include "chrome/gpu/chrome_content_gpu_client.h"
...@@ -55,6 +54,7 @@ ...@@ -55,6 +54,7 @@
#include "content/public/common/content_client.h" #include "content/public/common/content_client.h"
#include "content/public/common/content_paths.h" #include "content/public/common/content_paths.h"
#include "content/public/common/content_switches.h" #include "content/public/common/content_switches.h"
#include "content/public/common/profiling.h"
#include "content/public/common/service_names.mojom.h" #include "content/public/common/service_names.mojom.h"
#include "extensions/common/constants.h" #include "extensions/common/constants.h"
#include "net/url_request/url_request.h" #include "net/url_request/url_request.h"
...@@ -352,7 +352,7 @@ void HandleHelpSwitches(const base::CommandLine& command_line) { ...@@ -352,7 +352,7 @@ void HandleHelpSwitches(const base::CommandLine& command_line) {
#if !defined(OS_MACOSX) && !defined(OS_ANDROID) #if !defined(OS_MACOSX) && !defined(OS_ANDROID)
void SIGTERMProfilingShutdown(int signal) { void SIGTERMProfilingShutdown(int signal) {
Profiling::Stop(); content::Profiling::Stop();
struct sigaction sigact; struct sigaction sigact;
memset(&sigact, 0, sizeof(sigact)); memset(&sigact, 0, sizeof(sigact));
sigact.sa_handler = SIG_DFL; sigact.sa_handler = SIG_DFL;
...@@ -556,7 +556,7 @@ bool ChromeMainDelegate::BasicStartupComplete(int* exit_code) { ...@@ -556,7 +556,7 @@ bool ChromeMainDelegate::BasicStartupComplete(int* exit_code) {
chrome::common::mac::EnableCFBundleBlocker(); chrome::common::mac::EnableCFBundleBlocker();
#endif #endif
Profiling::ProcessStarted(); content::Profiling::ProcessStarted();
base::trace_event::TraceLog::GetInstance()->SetArgumentFilterPredicate( base::trace_event::TraceLog::GetInstance()->SetArgumentFilterPredicate(
base::Bind(&IsTraceEventArgsWhitelisted)); base::Bind(&IsTraceEventArgsWhitelisted));
...@@ -1055,8 +1055,8 @@ void ChromeMainDelegate::ZygoteStarting( ...@@ -1055,8 +1055,8 @@ void ChromeMainDelegate::ZygoteStarting(
} }
void ChromeMainDelegate::ZygoteForked() { void ChromeMainDelegate::ZygoteForked() {
Profiling::ProcessStarted(); content::Profiling::ProcessStarted();
if (Profiling::BeingProfiled()) { if (content::Profiling::BeingProfiled()) {
base::debug::RestartProfilingAfterFork(); base::debug::RestartProfilingAfterFork();
SetUpProfilingShutdownHandler(); SetUpProfilingShutdownHandler();
} }
......
...@@ -120,7 +120,6 @@ ...@@ -120,7 +120,6 @@
#include "chrome/common/media/media_resource_provider.h" #include "chrome/common/media/media_resource_provider.h"
#include "chrome/common/net/net_resource_provider.h" #include "chrome/common/net/net_resource_provider.h"
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
#include "chrome/common/profiling.h"
#include "chrome/common/stack_sampling_configuration.h" #include "chrome/common/stack_sampling_configuration.h"
#include "chrome/common/thread_profiler.h" #include "chrome/common/thread_profiler.h"
#include "chrome/grit/generated_resources.h" #include "chrome/grit/generated_resources.h"
...@@ -176,6 +175,7 @@ ...@@ -176,6 +175,7 @@
#include "content/public/common/content_features.h" #include "content/public/common/content_features.h"
#include "content/public/common/content_switches.h" #include "content/public/common/content_switches.h"
#include "content/public/common/main_function_params.h" #include "content/public/common/main_function_params.h"
#include "content/public/common/profiling.h"
#include "content/public/common/service_manager_connection.h" #include "content/public/common/service_manager_connection.h"
#include "device/vr/buildflags/buildflags.h" #include "device/vr/buildflags/buildflags.h"
#include "extensions/buildflags/buildflags.h" #include "extensions/buildflags/buildflags.h"
......
...@@ -2114,9 +2114,6 @@ void ChromeContentBrowserClient::AppendExtraCommandLineSwitches( ...@@ -2114,9 +2114,6 @@ void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
switches::kPpapiFlashArgs, switches::kPpapiFlashArgs,
switches::kPpapiFlashPath, switches::kPpapiFlashPath,
switches::kPpapiFlashVersion, switches::kPpapiFlashVersion,
switches::kProfilingAtStart,
switches::kProfilingFile,
switches::kProfilingFlush,
switches::kReaderModeHeuristics, switches::kReaderModeHeuristics,
translate::switches::kTranslateSecurityOrigin, translate::switches::kTranslateSecurityOrigin,
}; };
...@@ -2157,12 +2154,6 @@ void ChromeContentBrowserClient::AppendExtraCommandLineSwitches( ...@@ -2157,12 +2154,6 @@ void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) && if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) &&
!command_line->HasSwitch(switches::kDisableBreakpad)) !command_line->HasSwitch(switches::kDisableBreakpad))
command_line->AppendSwitch(switches::kDisableBreakpad); command_line->AppendSwitch(switches::kDisableBreakpad);
static const char* const kSwitchNames[] = {
switches::kProfilingAtStart, switches::kProfilingFile,
switches::kProfilingFlush,
};
command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
base::size(kSwitchNames));
} }
StackSamplingConfiguration::Get()->AppendCommandLineSwitchForChildProcess( StackSamplingConfiguration::Get()->AppendCommandLineSwitchForChildProcess(
......
...@@ -153,7 +153,6 @@ ...@@ -153,7 +153,6 @@
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
#include "chrome/common/custom_handlers/protocol_handler.h" #include "chrome/common/custom_handlers/protocol_handler.h"
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
#include "chrome/common/profiling.h"
#include "chrome/common/ssl_insecure_content.h" #include "chrome/common/ssl_insecure_content.h"
#include "chrome/common/url_constants.h" #include "chrome/common/url_constants.h"
#include "chrome/grit/chromium_strings.h" #include "chrome/grit/chromium_strings.h"
...@@ -200,6 +199,7 @@ ...@@ -200,6 +199,7 @@
#include "content/public/common/content_constants.h" #include "content/public/common/content_constants.h"
#include "content/public/common/content_switches.h" #include "content/public/common/content_switches.h"
#include "content/public/common/page_zoom.h" #include "content/public/common/page_zoom.h"
#include "content/public/common/profiling.h"
#include "content/public/common/renderer_preferences.h" #include "content/public/common/renderer_preferences.h"
#include "content/public/common/webplugininfo.h" #include "content/public/common/webplugininfo.h"
#include "extensions/browser/extension_prefs.h" #include "extensions/browser/extension_prefs.h"
......
...@@ -44,7 +44,6 @@ ...@@ -44,7 +44,6 @@
#include "chrome/browser/ui/webui/inspect_ui.h" #include "chrome/browser/ui/webui/inspect_ui.h"
#include "chrome/common/content_restriction.h" #include "chrome/common/content_restriction.h"
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
#include "chrome/common/profiling.h"
#include "chrome/common/url_constants.h" #include "chrome/common/url_constants.h"
#include "components/bookmarks/common/bookmark_pref_names.h" #include "components/bookmarks/common/bookmark_pref_names.h"
#include "components/dom_distiller/core/dom_distiller_switches.h" #include "components/dom_distiller/core/dom_distiller_switches.h"
...@@ -58,6 +57,7 @@ ...@@ -58,6 +57,7 @@
#include "content/public/browser/render_frame_host.h" #include "content/public/browser/render_frame_host.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_observer.h" #include "content/public/browser/web_contents_observer.h"
#include "content/public/common/profiling.h"
#include "content/public/common/service_manager_connection.h" #include "content/public/common/service_manager_connection.h"
#include "content/public/common/url_constants.h" #include "content/public/common/url_constants.h"
#include "extensions/browser/extension_system.h" #include "extensions/browser/extension_system.h"
...@@ -608,7 +608,7 @@ bool BrowserCommandController::ExecuteCommandWithDisposition( ...@@ -608,7 +608,7 @@ bool BrowserCommandController::ExecuteCommandWithDisposition(
ToggleBookmarkBar(browser_); ToggleBookmarkBar(browser_);
break; break;
case IDC_PROFILING_ENABLED: case IDC_PROFILING_ENABLED:
Profiling::Toggle(); content::Profiling::Toggle();
break; break;
case IDC_SHOW_BOOKMARK_MANAGER: case IDC_SHOW_BOOKMARK_MANAGER:
......
...@@ -45,7 +45,6 @@ ...@@ -45,7 +45,6 @@
#include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
#include "chrome/common/profiling.h"
#include "chrome/grit/chromium_strings.h" #include "chrome/grit/chromium_strings.h"
#include "chrome/grit/generated_resources.h" #include "chrome/grit/generated_resources.h"
#include "chrome/grit/theme_resources.h" #include "chrome/grit/theme_resources.h"
...@@ -63,6 +62,7 @@ ...@@ -63,6 +62,7 @@
#include "content/public/browser/notification_source.h" #include "content/public/browser/notification_source.h"
#include "content/public/browser/notification_types.h" #include "content/public/browser/notification_types.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "content/public/common/profiling.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/base/layout.h" #include "ui/base/layout.h"
#include "ui/base/models/button_menu_item_model.h" #include "ui/base/models/button_menu_item_model.h"
...@@ -629,7 +629,7 @@ bool AppMenuModel::IsCommandIdChecked(int command_id) const { ...@@ -629,7 +629,7 @@ bool AppMenuModel::IsCommandIdChecked(int command_id) const {
bookmarks::prefs::kShowBookmarkBar); bookmarks::prefs::kShowBookmarkBar);
} }
if (command_id == IDC_PROFILING_ENABLED) if (command_id == IDC_PROFILING_ENABLED)
return Profiling::BeingProfiled(); return content::Profiling::BeingProfiled();
if (command_id == IDC_TOGGLE_REQUEST_TABLET_SITE) if (command_id == IDC_TOGGLE_REQUEST_TABLET_SITE)
return chrome::IsRequestingTabletSite(browser_); return chrome::IsRequestingTabletSite(browser_);
......
...@@ -175,8 +175,6 @@ static_library("common") { ...@@ -175,8 +175,6 @@ static_library("common") {
"prerender_url_loader_throttle.h", "prerender_url_loader_throttle.h",
"prerender_util.cc", "prerender_util.cc",
"prerender_util.h", "prerender_util.h",
"profiling.cc",
"profiling.h",
"ref_counted_util.h", "ref_counted_util.h",
"render_messages.h", "render_messages.h",
"search/instant_types.cc", "search/instant_types.cc",
......
...@@ -550,17 +550,6 @@ const char kProductVersion[] = "product-version"; ...@@ -550,17 +550,6 @@ const char kProductVersion[] = "product-version";
// Selects directory of profile to associate with the first browser launched. // Selects directory of profile to associate with the first browser launched.
const char kProfileDirectory[] = "profile-directory"; const char kProfileDirectory[] = "profile-directory";
// Starts the sampling based profiler for the browser process at startup. This
// will only work if chrome has been built with the gyp variable profiling=1.
// The output will go to the value of kProfilingFile.
const char kProfilingAtStart[] = "profiling-at-start";
// Controls whether profile data is periodically flushed to a file. Normally
// the data gets written on exit but cases exist where chrome doesn't exit
// cleanly (especially when using single-process). A time in seconds can be
// specified.
const char kProfilingFlush[] = "profiling-flush";
// Forces proxy auto-detection. // Forces proxy auto-detection.
const char kProxyAutoDetect[] = "proxy-auto-detect"; const char kProxyAutoDetect[] = "proxy-auto-detect";
......
...@@ -164,8 +164,6 @@ extern const char kPpapiFlashVersion[]; ...@@ -164,8 +164,6 @@ extern const char kPpapiFlashVersion[];
extern const char kPrivetIPv6Only[]; extern const char kPrivetIPv6Only[];
extern const char kProductVersion[]; extern const char kProductVersion[];
extern const char kProfileDirectory[]; extern const char kProfileDirectory[];
extern const char kProfilingAtStart[];
extern const char kProfilingFlush[];
extern const char kProxyAutoDetect[]; extern const char kProxyAutoDetect[];
extern const char kProxyBypassList[]; extern const char kProxyBypassList[];
extern const char kProxyPacUrl[]; extern const char kProxyPacUrl[];
......
...@@ -220,6 +220,9 @@ static const char* const kSwitchNames[] = { ...@@ -220,6 +220,9 @@ static const char* const kSwitchNames[] = {
switches::kLoggingLevel, switches::kLoggingLevel,
switches::kEnableLowEndDeviceMode, switches::kEnableLowEndDeviceMode,
switches::kDisableLowEndDeviceMode, switches::kDisableLowEndDeviceMode,
switches::kProfilingAtStart,
switches::kProfilingFile,
switches::kProfilingFlush,
switches::kRunAllCompositorStagesBeforeDraw, switches::kRunAllCompositorStagesBeforeDraw,
switches::kSkiaFontCacheLimitMb, switches::kSkiaFontCacheLimitMb,
switches::kSkiaResourceCacheLimitMb, switches::kSkiaResourceCacheLimitMb,
......
...@@ -3048,6 +3048,9 @@ void RenderProcessHostImpl::PropagateBrowserCommandLineToRenderer( ...@@ -3048,6 +3048,9 @@ void RenderProcessHostImpl::PropagateBrowserCommandLineToRenderer(
switches::kOverridePluginPowerSaverForTesting, switches::kOverridePluginPowerSaverForTesting,
switches::kPassiveListenersDefault, switches::kPassiveListenersDefault,
switches::kPpapiInProcess, switches::kPpapiInProcess,
switches::kProfilingAtStart,
switches::kProfilingFile,
switches::kProfilingFlush,
switches::kReducedReferrerGranularity, switches::kReducedReferrerGranularity,
switches::kRegisterPepperPlugins, switches::kRegisterPepperPlugins,
switches::kRendererStartupDialog, switches::kRendererStartupDialog,
......
...@@ -182,6 +182,8 @@ jumbo_source_set("common_sources") { ...@@ -182,6 +182,8 @@ jumbo_source_set("common_sources") {
"persistent_notification_status.h", "persistent_notification_status.h",
"previews_state.h", "previews_state.h",
"process_type.h", "process_type.h",
"profiling.cc",
"profiling.h",
"push_subscription_options.h", "push_subscription_options.h",
"referrer.cc", "referrer.cc",
"referrer.h", "referrer.h",
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "chrome/common/profiling.h" #include "content/public/common/profiling.h"
#include "base/at_exit.h" #include "base/at_exit.h"
#include "base/base_switches.h" #include "base/base_switches.h"
...@@ -16,9 +16,10 @@ ...@@ -16,9 +16,10 @@
#include "base/single_thread_task_runner.h" #include "base/single_thread_task_runner.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/threading/thread.h" #include "base/threading/thread.h"
#include "chrome/common/chrome_switches.h"
#include "content/public/common/content_switches.h" #include "content/public/common/content_switches.h"
namespace content {
namespace { namespace {
std::string GetProfileName() { std::string GetProfileName() {
...@@ -33,8 +34,8 @@ std::string GetProfileName() { ...@@ -33,8 +34,8 @@ std::string GetProfileName() {
profile_name = std::string("chrome-profile-{type}-{pid}"); profile_name = std::string("chrome-profile-{type}-{pid}");
std::string process_type = std::string process_type =
command_line.GetSwitchValueASCII(switches::kProcessType); command_line.GetSwitchValueASCII(switches::kProcessType);
std::string type = process_type.empty() ? std::string type = process_type.empty() ? std::string("browser")
std::string("browser") : std::string(process_type); : std::string(process_type);
base::ReplaceSubstringsAfterOffset(&profile_name, 0, "{type}", type); base::ReplaceSubstringsAfterOffset(&profile_name, 0, "{type}", type);
return profile_name; return profile_name;
...@@ -100,10 +101,10 @@ class ProfilingThreadControl { ...@@ -100,10 +101,10 @@ class ProfilingThreadControl {
DISALLOW_COPY_AND_ASSIGN(ProfilingThreadControl); DISALLOW_COPY_AND_ASSIGN(ProfilingThreadControl);
}; };
base::LazyInstance<ProfilingThreadControl>::Leaky base::LazyInstance<ProfilingThreadControl>::Leaky g_flush_thread_control =
g_flush_thread_control = LAZY_INSTANCE_INITIALIZER; LAZY_INSTANCE_INITIALIZER;
} // namespace } // namespace
// static // static
void Profiling::ProcessStarted() { void Profiling::ProcessStarted() {
...@@ -151,3 +152,5 @@ void Profiling::Toggle() { ...@@ -151,3 +152,5 @@ void Profiling::Toggle() {
else else
Start(); Start();
} }
} // namespace content
...@@ -2,19 +2,22 @@ ...@@ -2,19 +2,22 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef CHROME_COMMON_PROFILING_H_ #ifndef CONTENT_PUBLIC_COMMON_PROFILING_H_
#define CHROME_COMMON_PROFILING_H_ #define CONTENT_PUBLIC_COMMON_PROFILING_H_
#include "build/build_config.h" #include "build/build_config.h"
#include "base/debug/profiler.h" #include "base/debug/profiler.h"
#include "base/macros.h" #include "base/macros.h"
#include "content/common/content_export.h"
namespace content {
// The Profiling class manages the interaction with a sampling based profiler. // The Profiling class manages the interaction with a sampling based profiler.
// Its function is controlled by the kProfilingAtStart, kProfilingFile, and // Its function is controlled by the kProfilingAtStart, kProfilingFile, and
// kProfilingFlush command line values. // kProfilingFlush command line values.
// All of the API should only be called from the main thread of the process. // All of the API should only be called from the main thread of the process.
class Profiling { class CONTENT_EXPORT Profiling {
public: public:
// Called early in a process' life to allow profiling of startup time. // Called early in a process' life to allow profiling of startup time.
// the presence of kProfilingAtStart is checked. // the presence of kProfilingAtStart is checked.
...@@ -39,4 +42,6 @@ class Profiling { ...@@ -39,4 +42,6 @@ class Profiling {
DISALLOW_COPY_AND_ASSIGN(Profiling); DISALLOW_COPY_AND_ASSIGN(Profiling);
}; };
#endif // CHROME_COMMON_PROFILING_H_ } // namespace content
#endif // CONTENT_PUBLIC_COMMON_PROFILING_H_
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include "components/crash/core/common/crash_key.h" #include "components/crash/core/common/crash_key.h"
#include "content/public/browser/browser_main_runner.h" #include "content/public/browser/browser_main_runner.h"
#include "content/public/common/content_switches.h" #include "content/public/common/content_switches.h"
#include "content/public/common/profiling.h"
#include "headless/lib/browser/headless_browser_impl.h" #include "headless/lib/browser/headless_browser_impl.h"
#include "headless/lib/browser/headless_content_browser_client.h" #include "headless/lib/browser/headless_content_browser_client.h"
#include "headless/lib/headless_crash_reporter_client.h" #include "headless/lib/headless_crash_reporter_client.h"
...@@ -48,6 +49,10 @@ ...@@ -48,6 +49,10 @@
#include "headless/lib/renderer/headless_content_renderer_client.h" #include "headless/lib/renderer/headless_content_renderer_client.h"
#endif #endif
#if defined(OS_POSIX)
#include <signal.h>
#endif
namespace headless { namespace headless {
namespace { namespace {
// Keep in sync with content/common/content_constants_internal.h. // Keep in sync with content/common/content_constants_internal.h.
...@@ -123,6 +128,8 @@ bool HeadlessContentMainDelegate::BasicStartupComplete(int* exit_code) { ...@@ -123,6 +128,8 @@ bool HeadlessContentMainDelegate::BasicStartupComplete(int* exit_code) {
// preempt this attempt. // preempt this attempt.
command_line->AppendSwitch(::switches::kDisableGpuCompositing); command_line->AppendSwitch(::switches::kDisableGpuCompositing);
content::Profiling::ProcessStarted();
SetContentClient(&content_client_); SetContentClient(&content_client_);
return false; return false;
} }
...@@ -291,7 +298,29 @@ int HeadlessContentMainDelegate::RunProcess( ...@@ -291,7 +298,29 @@ int HeadlessContentMainDelegate::RunProcess(
#endif // !defined(CHROME_MULTIPLE_DLL_CHILD) #endif // !defined(CHROME_MULTIPLE_DLL_CHILD)
#if defined(OS_LINUX) #if defined(OS_LINUX)
void SIGTERMProfilingShutdown(int signal) {
content::Profiling::Stop();
struct sigaction sigact;
memset(&sigact, 0, sizeof(sigact));
sigact.sa_handler = SIG_DFL;
CHECK_EQ(sigaction(SIGTERM, &sigact, NULL), 0);
raise(signal);
}
void SetUpProfilingShutdownHandler() {
struct sigaction sigact;
sigact.sa_handler = SIGTERMProfilingShutdown;
sigact.sa_flags = SA_RESETHAND;
sigemptyset(&sigact.sa_mask);
CHECK_EQ(sigaction(SIGTERM, &sigact, NULL), 0);
}
void HeadlessContentMainDelegate::ZygoteForked() { void HeadlessContentMainDelegate::ZygoteForked() {
content::Profiling::ProcessStarted();
if (content::Profiling::BeingProfiled()) {
base::debug::RestartProfilingAfterFork();
SetUpProfilingShutdownHandler();
}
const base::CommandLine& command_line( const base::CommandLine& command_line(
*base::CommandLine::ForCurrentProcess()); *base::CommandLine::ForCurrentProcess());
const std::string process_type = const std::string process_type =
......
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