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

Side by Side Diff: extensions/common/features/feature_provider.cc

Issue 996013004: Add metric measuring Feature Provider Static() length in the browser process. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: longer comment Created 5 years, 9 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 "extensions/common/features/feature_provider.h" 5 #include "extensions/common/features/feature_provider.h"
6 6
7 #include <map> 7 #include <map>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/command_line.h"
10 #include "base/lazy_instance.h" 11 #include "base/lazy_instance.h"
11 #include "base/memory/linked_ptr.h" 12 #include "base/memory/linked_ptr.h"
13 #include "base/metrics/histogram_macros.h"
14 #include "base/trace_event/trace_event.h"
15 #include "content/public/common/content_switches.h"
12 #include "extensions/common/extensions_client.h" 16 #include "extensions/common/extensions_client.h"
17 #include "extensions/common/switches.h"
13 18
14 namespace extensions { 19 namespace extensions {
15 20
16 namespace { 21 namespace {
17 22
18 class Static { 23 class Static {
19 public: 24 public:
20 FeatureProvider* GetFeatures(const std::string& name) const { 25 FeatureProvider* GetFeatures(const std::string& name) const {
21 FeatureProviderMap::const_iterator it = feature_providers_.find(name); 26 FeatureProviderMap::const_iterator it = feature_providers_.find(name);
22 CHECK(it != feature_providers_.end()); 27 CHECK(it != feature_providers_.end());
23 return it->second.get(); 28 return it->second.get();
24 } 29 }
25 30
26 private: 31 private:
27 friend struct base::DefaultLazyInstanceTraits<Static>; 32 friend struct base::DefaultLazyInstanceTraits<Static>;
28 33
29 Static() { 34 Static() {
35 TRACE_EVENT0("startup", "extensions::FeatureProvider::Static");
36 base::Time begin_time = base::Time::Now();
37
30 ExtensionsClient* client = ExtensionsClient::Get(); 38 ExtensionsClient* client = ExtensionsClient::Get();
31 feature_providers_["api"] = 39 feature_providers_["api"] =
32 make_linked_ptr(client->CreateFeatureProvider("api").release()); 40 make_linked_ptr(client->CreateFeatureProvider("api").release());
33 feature_providers_["manifest"] = 41 feature_providers_["manifest"] =
34 make_linked_ptr(client->CreateFeatureProvider("manifest").release()); 42 make_linked_ptr(client->CreateFeatureProvider("manifest").release());
35 feature_providers_["permission"] = 43 feature_providers_["permission"] =
36 make_linked_ptr(client->CreateFeatureProvider("permission").release()); 44 make_linked_ptr(client->CreateFeatureProvider("permission").release());
37 feature_providers_["behavior"] = 45 feature_providers_["behavior"] =
38 make_linked_ptr(client->CreateFeatureProvider("behavior").release()); 46 make_linked_ptr(client->CreateFeatureProvider("behavior").release());
47
48 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
49 std::string process_type =
50 command_line->GetSwitchValueASCII(::switches::kProcessType);
51
52 // Measure time only for browser process. This method gets called by the
53 // browser process on startup, as well as on renderer and extension
54 // processes throughout the execution of the browser. We are more
55 // interested in how long this takes as a startup cost, so we are
56 // just measuring the time in the browser process.
57 if (process_type == "") {
Ilya Sherman 2015/03/13 22:25:18 nit: It's generally better to use std::string() ra
rkaplow 2015/03/14 19:16:32 Done.
58 UMA_HISTOGRAM_TIMES("Extensions.FeatureProviderStaticInitTime",
59 base::Time::Now() - begin_time);
60 }
39 } 61 }
40 62
41 typedef std::map<std::string, linked_ptr<FeatureProvider> > 63 typedef std::map<std::string, linked_ptr<FeatureProvider> >
42 FeatureProviderMap; 64 FeatureProviderMap;
43 65
44 FeatureProviderMap feature_providers_; 66 FeatureProviderMap feature_providers_;
45 }; 67 };
46 68
47 base::LazyInstance<Static> g_static = LAZY_INSTANCE_INITIALIZER; 69 base::LazyInstance<Static> g_static = LAZY_INSTANCE_INITIALIZER;
48 70
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 const Feature* FeatureProvider::GetPermissionFeature(const std::string& name) { 120 const Feature* FeatureProvider::GetPermissionFeature(const std::string& name) {
99 return GetFeatureFromProviderByName("permission", name); 121 return GetFeatureFromProviderByName("permission", name);
100 } 122 }
101 123
102 // static 124 // static
103 const Feature* FeatureProvider::GetBehaviorFeature(const std::string& name) { 125 const Feature* FeatureProvider::GetBehaviorFeature(const std::string& name) {
104 return GetFeatureFromProviderByName("behavior", name); 126 return GetFeatureFromProviderByName("behavior", name);
105 } 127 }
106 128
107 } // namespace extensions 129 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698