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

Side by Side Diff: services/service_manager/standalone/context.cc

Issue 2852183002: Delete the tracing service (Closed)
Patch Set: Created 3 years, 7 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 #include "services/service_manager/standalone/context.h" 5 #include "services/service_manager/standalone/context.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <utility> 10 #include <utility>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/bind.h" 13 #include "base/bind.h"
14 #include "base/command_line.h" 14 #include "base/command_line.h"
15 #include "base/files/file_path.h" 15 #include "base/files/file_path.h"
16 #include "base/json/json_file_value_serializer.h" 16 #include "base/json/json_file_value_serializer.h"
17 #include "base/macros.h" 17 #include "base/macros.h"
18 #include "base/memory/ptr_util.h" 18 #include "base/memory/ptr_util.h"
19 #include "base/message_loop/message_loop.h" 19 #include "base/message_loop/message_loop.h"
20 #include "base/path_service.h" 20 #include "base/path_service.h"
21 #include "base/process/process_info.h" 21 #include "base/process/process_info.h"
22 #include "base/strings/string_number_conversions.h" 22 #include "base/strings/string_number_conversions.h"
23 #include "base/strings/string_split.h" 23 #include "base/strings/string_split.h"
24 #include "base/strings/string_util.h" 24 #include "base/strings/string_util.h"
25 #include "base/strings/utf_string_conversions.h" 25 #include "base/strings/utf_string_conversions.h"
26 #include "base/threading/sequenced_worker_pool.h" 26 #include "base/threading/sequenced_worker_pool.h"
27 #include "base/trace_event/trace_event.h" 27 #include "base/trace_event/trace_event.h"
28 #include "build/build_config.h" 28 #include "build/build_config.h"
29 #include "components/tracing/common/tracing_switches.h"
30 #include "services/catalog/catalog.h" 29 #include "services/catalog/catalog.h"
31 #include "services/service_manager/connect_params.h" 30 #include "services/service_manager/connect_params.h"
32 #include "services/service_manager/connect_util.h" 31 #include "services/service_manager/connect_util.h"
33 #include "services/service_manager/runner/common/switches.h" 32 #include "services/service_manager/runner/common/switches.h"
34 #include "services/service_manager/runner/host/service_process_launcher.h" 33 #include "services/service_manager/runner/host/service_process_launcher.h"
35 #include "services/service_manager/service_manager.h" 34 #include "services/service_manager/service_manager.h"
36 #include "services/service_manager/standalone/tracer.h"
37 #include "services/service_manager/switches.h" 35 #include "services/service_manager/switches.h"
38 #include "services/tracing/public/cpp/provider.h"
39 #include "services/tracing/public/cpp/switches.h"
40 #include "services/tracing/public/interfaces/constants.mojom.h"
41 #include "services/tracing/public/interfaces/tracing.mojom.h"
42 36
43 #if defined(OS_MACOSX) 37 #if defined(OS_MACOSX)
44 #include "services/service_manager/public/cpp/standalone_service/mach_broker.h" 38 #include "services/service_manager/public/cpp/standalone_service/mach_broker.h"
45 #endif 39 #endif
46 40
47 namespace base { 41 namespace base {
48 class TaskRunner; 42 class TaskRunner;
49 } 43 }
50 44
51 namespace service_manager { 45 namespace service_manager {
(...skipping 26 matching lines...) Expand all
78 72
79 const char kService[] = "service"; 73 const char kService[] = "service";
80 74
81 } // namespace 75 } // namespace
82 76
83 Context::Context( 77 Context::Context(
84 ServiceProcessLauncher::Delegate* service_process_launcher_delegate, 78 ServiceProcessLauncher::Delegate* service_process_launcher_delegate,
85 std::unique_ptr<base::Value> catalog_contents) 79 std::unique_ptr<base::Value> catalog_contents)
86 : main_entry_time_(base::Time::Now()) { 80 : main_entry_time_(base::Time::Now()) {
87 TRACE_EVENT0("service_manager", "Context::Context"); 81 TRACE_EVENT0("service_manager", "Context::Context");
88 const base::CommandLine& command_line =
89 *base::CommandLine::ForCurrentProcess();
90
91 bool trace_startup = command_line.HasSwitch(::switches::kTraceStartup);
92 if (trace_startup) {
93 tracer_.Start(
94 command_line.GetSwitchValueASCII(::switches::kTraceStartup),
95 command_line.GetSwitchValueASCII(::switches::kTraceStartupDuration),
96 "mojo_runner.trace");
97 }
98 82
99 blocking_pool_ = new base::SequencedWorkerPool( 83 blocking_pool_ = new base::SequencedWorkerPool(
100 kThreadPoolMaxThreads, "blocking_pool", base::TaskPriority::USER_VISIBLE); 84 kThreadPoolMaxThreads, "blocking_pool", base::TaskPriority::USER_VISIBLE);
101 85
102 std::unique_ptr<ServiceProcessLauncherFactory> 86 std::unique_ptr<ServiceProcessLauncherFactory>
103 service_process_launcher_factory = 87 service_process_launcher_factory =
104 base::MakeUnique<ServiceProcessLauncherFactoryImpl>( 88 base::MakeUnique<ServiceProcessLauncherFactoryImpl>(
105 blocking_pool_.get(), 89 blocking_pool_.get(),
106 service_process_launcher_delegate); 90 service_process_launcher_delegate);
107 catalog_.reset(new catalog::Catalog(std::move(catalog_contents))); 91 catalog_.reset(new catalog::Catalog(std::move(catalog_contents)));
108 service_manager_.reset( 92 service_manager_.reset(
109 new ServiceManager(std::move(service_process_launcher_factory), 93 new ServiceManager(std::move(service_process_launcher_factory),
110 catalog_->TakeService())); 94 catalog_->TakeService()));
111
112 bool enable_stats_collection_bindings =
113 command_line.HasSwitch(tracing::kEnableStatsCollectionBindings);
114
115 if (enable_stats_collection_bindings ||
116 command_line.HasSwitch(switches::kEnableTracing)) {
117 Identity source_identity = CreateServiceManagerIdentity();
118 Identity tracing_identity(tracing::mojom::kServiceName, mojom::kRootUserID);
119 tracing::mojom::FactoryPtr factory;
120 BindInterface(service_manager(), source_identity, tracing_identity,
121 &factory);
122 provider_.InitializeWithFactory(&factory);
123
124 if (command_line.HasSwitch(tracing::kTraceStartup)) {
125 tracing::mojom::CollectorPtr coordinator;
126 BindInterface(service_manager(), source_identity, tracing_identity,
127 &coordinator);
128 tracer_.StartCollectingFromTracingService(std::move(coordinator));
129 }
130
131 // Record the service manager startup metrics used for performance testing.
132 if (enable_stats_collection_bindings) {
133 tracing::mojom::StartupPerformanceDataCollectorPtr collector;
134 BindInterface(service_manager(), source_identity, tracing_identity,
135 &collector);
136 #if defined(OS_MACOSX) || defined(OS_WIN) || defined(OS_LINUX)
137 // CurrentProcessInfo::CreationTime is only defined on some platforms.
138 const base::Time creation_time = base::CurrentProcessInfo::CreationTime();
139 collector->SetServiceManagerProcessCreationTime(
140 creation_time.ToInternalValue());
141 #endif
142 collector->SetServiceManagerMainEntryPointTime(
143 main_entry_time_.ToInternalValue());
144 }
145 }
146 } 95 }
147 96
148 Context::~Context() { blocking_pool_->Shutdown(); } 97 Context::~Context() { blocking_pool_->Shutdown(); }
149 98
150 void Context::RunCommandLineApplication() { 99 void Context::RunCommandLineApplication() {
151 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); 100 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
152 if (command_line->HasSwitch(kService)) 101 if (command_line->HasSwitch(kService))
153 Run(command_line->GetSwitchValueASCII(kService)); 102 Run(command_line->GetSwitchValueASCII(kService));
154 } 103 }
155 104
156 void Context::Run(const std::string& name) { 105 void Context::Run(const std::string& name) {
157 service_manager_->SetInstanceQuitCallback(base::Bind(&OnInstanceQuit, name)); 106 service_manager_->SetInstanceQuitCallback(base::Bind(&OnInstanceQuit, name));
158 107
159 std::unique_ptr<ConnectParams> params(new ConnectParams); 108 std::unique_ptr<ConnectParams> params(new ConnectParams);
160 params->set_source(CreateServiceManagerIdentity()); 109 params->set_source(CreateServiceManagerIdentity());
161 params->set_target(Identity(name, mojom::kRootUserID)); 110 params->set_target(Identity(name, mojom::kRootUserID));
162 service_manager_->Connect(std::move(params)); 111 service_manager_->Connect(std::move(params));
163 } 112 }
164 113
165 } // namespace service_manager 114 } // namespace service_manager
OLDNEW
« no previous file with comments | « services/service_manager/standalone/context.h ('k') | services/service_manager/standalone/tracer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698