Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(183)

Side by Side Diff: chrome/app/chrome_dll_main.cc

Issue 3051003: Fix stats table on linux. There were two problems:... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // TODO(port): the ifdefs in here are a first step towards trying to determine 5 // TODO(port): the ifdefs in here are a first step towards trying to determine
6 // the correct abstraction for all the OS functionality required at this 6 // the correct abstraction for all the OS functionality required at this
7 // stage of process initialization. It should not be taken as a final 7 // stage of process initialization. It should not be taken as a final
8 // abstraction. 8 // abstraction.
9 9
10 #include "build/build_config.h" 10 #include "build/build_config.h"
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 } else if (process_type == switches::kUtilityProcess) { 406 } else if (process_type == switches::kUtilityProcess) {
407 name_id = IDS_UTILITY_APP_NAME; 407 name_id = IDS_UTILITY_APP_NAME;
408 } 408 }
409 if (name_id) { 409 if (name_id) {
410 NSString* app_name = l10n_util::GetNSString(name_id); 410 NSString* app_name = l10n_util::GetNSString(name_id);
411 mac_util::SetProcessName(reinterpret_cast<CFStringRef>(app_name)); 411 mac_util::SetProcessName(reinterpret_cast<CFStringRef>(app_name));
412 } 412 }
413 } 413 }
414 #endif // defined(OS_MACOSX) 414 #endif // defined(OS_MACOSX)
415 415
416 void InitializeStatsTable(base::ProcessId browser_pid,
417 const CommandLine & parsed_command_line) {
418 // Initialize the Stats Counters table. With this initialized,
419 // the StatsViewer can be utilized to read counters outside of
420 // Chrome. These lines can be commented out to effectively turn
421 // counters 'off'. The table is created and exists for the life
422 // of the process. It is not cleaned up.
423 if (parsed_command_line.HasSwitch(switches::kEnableStatsTable) ||
424 parsed_command_line.HasSwitch(switches::kEnableBenchmarking)) {
425 // NOTIMPLEMENTED: we probably need to shut this down correctly to avoid
426 // leaking shared memory regions on posix platforms.
427 std::string statsfile =
428 StringPrintf("%s-%u", chrome::kStatsFilename,
429 static_cast<unsigned int>(browser_pid));
430 StatsTable *stats_table = new StatsTable(statsfile,
431 chrome::kStatsMaxThreads, chrome::kStatsMaxCounters);
432 StatsTable::set_current(stats_table);
433 }
434 }
435
416 } // namespace 436 } // namespace
417 437
418 #if defined(OS_WIN) 438 #if defined(OS_WIN)
419 DLLEXPORT int __cdecl ChromeMain(HINSTANCE instance, 439 DLLEXPORT int __cdecl ChromeMain(HINSTANCE instance,
420 sandbox::SandboxInterfaceInfo* sandbox_info, 440 sandbox::SandboxInterfaceInfo* sandbox_info,
421 TCHAR* command_line) { 441 TCHAR* command_line) {
422 #elif defined(OS_POSIX) 442 #elif defined(OS_POSIX)
423 int ChromeMain(int argc, char** argv) { 443 int ChromeMain(int argc, char** argv) {
424 #endif 444 #endif
425 #if defined(OS_CHROMEOS) 445 #if defined(OS_CHROMEOS)
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 569
550 base::ProcessId browser_pid = base::GetCurrentProcId(); 570 base::ProcessId browser_pid = base::GetCurrentProcId();
551 if (SubprocessIsBrowserChild(process_type)) { 571 if (SubprocessIsBrowserChild(process_type)) {
552 #if defined(OS_WIN) 572 #if defined(OS_WIN)
553 std::wstring channel_name = 573 std::wstring channel_name =
554 parsed_command_line.GetSwitchValue(switches::kProcessChannelID); 574 parsed_command_line.GetSwitchValue(switches::kProcessChannelID);
555 575
556 browser_pid = 576 browser_pid =
557 static_cast<base::ProcessId>(StringToInt(WideToASCII(channel_name))); 577 static_cast<base::ProcessId>(StringToInt(WideToASCII(channel_name)));
558 DCHECK_NE(browser_pid, 0u); 578 DCHECK_NE(browser_pid, 0u);
559 #else 579 #elif defined(OS_MACOSX)
560 browser_pid = base::GetCurrentProcId(); 580 browser_pid = base::GetCurrentProcId();
581 #elif defined(OS_POSIX)
582 // On linux, we're in the zygote here; so we need the parent process' id.
583 browser_pid = base::GetParentProcessId(base::GetCurrentProcId());
561 #endif 584 #endif
562 585
563 #if defined(OS_POSIX) 586 #if defined(OS_POSIX)
564 // When you hit Ctrl-C in a terminal running the browser 587 // When you hit Ctrl-C in a terminal running the browser
565 // process, a SIGINT is delivered to the entire process group. 588 // process, a SIGINT is delivered to the entire process group.
566 // When debugging the browser process via gdb, gdb catches the 589 // When debugging the browser process via gdb, gdb catches the
567 // SIGINT for the browser process (and dumps you back to the gdb 590 // SIGINT for the browser process (and dumps you back to the gdb
568 // console) but doesn't for the child processes, killing them. 591 // console) but doesn't for the child processes, killing them.
569 // The fix is to have child processes ignore SIGINT; they'll die 592 // The fix is to have child processes ignore SIGINT; they'll die
570 // on their own when the browser process goes away. 593 // on their own when the browser process goes away.
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 || mac_util::IsBackgroundOnlyProcess(); 634 || mac_util::IsBackgroundOnlyProcess();
612 if (!IsCrashReporterEnabled() && disable_apple_crash_reporter) { 635 if (!IsCrashReporterEnabled() && disable_apple_crash_reporter) {
613 DebugUtil::DisableOSCrashDumps(); 636 DebugUtil::DisableOSCrashDumps();
614 } 637 }
615 } 638 }
616 639
617 if (IsCrashReporterEnabled()) 640 if (IsCrashReporterEnabled())
618 InitCrashProcessInfo(); 641 InitCrashProcessInfo();
619 #endif // OS_MACOSX 642 #endif // OS_MACOSX
620 643
621 // Initialize the Stats Counters table. With this initialized, 644 InitializeStatsTable(browser_pid, parsed_command_line);
622 // the StatsViewer can be utilized to read counters outside of
623 // Chrome. These lines can be commented out to effectively turn
624 // counters 'off'. The table is created and exists for the life
625 // of the process. It is not cleaned up.
626 // TODO(port): we probably need to shut this down correctly to avoid
627 // leaking shared memory regions on posix platforms.
628 if (parsed_command_line.HasSwitch(switches::kEnableStatsTable) ||
629 parsed_command_line.HasSwitch(switches::kEnableBenchmarking)) {
630 std::string statsfile =
631 StringPrintf("%s-%u", chrome::kStatsFilename,
632 static_cast<unsigned int>(browser_pid));
633 StatsTable *stats_table = new StatsTable(statsfile,
634 chrome::kStatsMaxThreads, chrome::kStatsMaxCounters);
635 StatsTable::set_current(stats_table);
636 }
637 645
638 StatsScope<StatsCounterTimer> 646 StatsScope<StatsCounterTimer>
639 startup_timer(chrome::Counters::chrome_main()); 647 startup_timer(chrome::Counters::chrome_main());
640 648
641 // Enable the heap profiler as early as possible! 649 // Enable the heap profiler as early as possible!
642 EnableHeapProfiler(parsed_command_line); 650 EnableHeapProfiler(parsed_command_line);
643 651
644 // Enable Message Loop related state asap. 652 // Enable Message Loop related state asap.
645 if (parsed_command_line.HasSwitch(switches::kMessageLoopHistogrammer)) 653 if (parsed_command_line.HasSwitch(switches::kMessageLoopHistogrammer))
646 MessageLoop::EnableHistogrammer(true); 654 MessageLoop::EnableHistogrammer(true);
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
789 rv = NaClBrokerMain(main_params); 797 rv = NaClBrokerMain(main_params);
790 #endif 798 #endif
791 } else if (process_type == switches::kZygoteProcess) { 799 } else if (process_type == switches::kZygoteProcess) {
792 #if defined(OS_POSIX) && !defined(OS_MACOSX) 800 #if defined(OS_POSIX) && !defined(OS_MACOSX)
793 // This function call can return multiple times, once per fork(). 801 // This function call can return multiple times, once per fork().
794 if (ZygoteMain(main_params)) { 802 if (ZygoteMain(main_params)) {
795 // Zygote::HandleForkRequest may have reallocated the command 803 // Zygote::HandleForkRequest may have reallocated the command
796 // line so update it here with the new version. 804 // line so update it here with the new version.
797 const CommandLine& parsed_command_line = 805 const CommandLine& parsed_command_line =
798 *CommandLine::ForCurrentProcess(); 806 *CommandLine::ForCurrentProcess();
807
808 // The StatsTable must be initialized in each process; we already
809 // initialized for the browser process, now we need to initialize
810 // within the new processes as well.
811 InitializeStatsTable(browser_pid, parsed_command_line);
Evan Martin 2010/11/22 22:19:22 Hey, remember this old change? I am touching this
Mike Belshe 2010/11/22 22:30:52 I can't recall exactly what was broken before - bu
Evan Martin 2010/11/22 22:32:31 Can you advise me how I can test whether my refact
812
799 MainFunctionParams main_params(parsed_command_line, sandbox_wrapper, 813 MainFunctionParams main_params(parsed_command_line, sandbox_wrapper,
800 &autorelease_pool); 814 &autorelease_pool);
801 std::string process_type = 815 std::string process_type =
802 parsed_command_line.GetSwitchValueASCII(switches::kProcessType); 816 parsed_command_line.GetSwitchValueASCII(switches::kProcessType);
803 if (process_type == switches::kRendererProcess || 817 if (process_type == switches::kRendererProcess ||
804 process_type == switches::kExtensionProcess) { 818 process_type == switches::kExtensionProcess) {
805 rv = RendererMain(main_params); 819 rv = RendererMain(main_params);
806 #ifndef DISABLE_NACL 820 #ifndef DISABLE_NACL
807 } else if (process_type == switches::kNaClLoaderProcess) { 821 } else if (process_type == switches::kNaClLoaderProcess) {
808 rv = NaClMain(main_params); 822 rv = NaClMain(main_params);
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
883 897
884 logging::CleanupChromeLogging(); 898 logging::CleanupChromeLogging();
885 899
886 #if defined(OS_MACOSX) && defined(GOOGLE_CHROME_BUILD) 900 #if defined(OS_MACOSX) && defined(GOOGLE_CHROME_BUILD)
887 // TODO(mark): See the TODO(mark) above at InitCrashReporter. 901 // TODO(mark): See the TODO(mark) above at InitCrashReporter.
888 DestructCrashReporter(); 902 DestructCrashReporter();
889 #endif // OS_MACOSX && GOOGLE_CHROME_BUILD 903 #endif // OS_MACOSX && GOOGLE_CHROME_BUILD
890 904
891 return rv; 905 return rv;
892 } 906 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698