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

Side by Side Diff: extensions/browser/extension_function_dispatcher.cc

Issue 1939413002: [Extensions] Add coarse metrics for extension function performance (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Istiaque's Created 4 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/browser/extension_function_dispatcher.h" 5 #include "extensions/browser/extension_function_dispatcher.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/json/json_string_value_serializer.h" 10 #include "base/json/json_string_value_serializer.h"
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 base::TimeTicks::Now()); 285 base::TimeTicks::Now());
286 if (violation_error.empty()) { 286 if (violation_error.empty()) {
287 std::unique_ptr<base::ListValue> args(params.arguments.DeepCopy()); 287 std::unique_ptr<base::ListValue> args(params.arguments.DeepCopy());
288 NotifyApiFunctionCalled(extension->id(), params.name, std::move(args), 288 NotifyApiFunctionCalled(extension->id(), params.name, std::move(args),
289 static_cast<content::BrowserContext*>(profile_id)); 289 static_cast<content::BrowserContext*>(profile_id));
290 UMA_HISTOGRAM_SPARSE_SLOWLY("Extensions.FunctionCalls", 290 UMA_HISTOGRAM_SPARSE_SLOWLY("Extensions.FunctionCalls",
291 function->histogram_value()); 291 function->histogram_value());
292 tracked_objects::ScopedProfile scoped_profile( 292 tracked_objects::ScopedProfile scoped_profile(
293 FROM_HERE_WITH_EXPLICIT_FUNCTION(function->name()), 293 FROM_HERE_WITH_EXPLICIT_FUNCTION(function->name()),
294 tracked_objects::ScopedProfile::ENABLED); 294 tracked_objects::ScopedProfile::ENABLED);
295 base::ElapsedTimer timer;
295 function->Run()->Execute(); 296 function->Run()->Execute();
297 // TODO(devlin): Once we have a baseline metric for how long functions take,
298 // we can create a handful of buckets and record the function name so that
299 // we can find what the fastest/slowest are.
300 // Note: Many functions execute finish asynchronously, so this time is not
301 // always a representation of total time taken. See also
302 // Extensions.Functions.TotalExecutionTime.
303 UMA_HISTOGRAM_TIMES("Extensions.Functions.SynchronousExecutionTime",
304 timer.Elapsed());
296 } else { 305 } else {
297 function->OnQuotaExceeded(violation_error); 306 function->OnQuotaExceeded(violation_error);
298 } 307 }
299 } 308 }
300 309
301 ExtensionFunctionDispatcher::ExtensionFunctionDispatcher( 310 ExtensionFunctionDispatcher::ExtensionFunctionDispatcher(
302 content::BrowserContext* browser_context) 311 content::BrowserContext* browser_context)
303 : browser_context_(browser_context), delegate_(nullptr) {} 312 : browser_context_(browser_context), delegate_(nullptr) {}
304 313
305 ExtensionFunctionDispatcher::~ExtensionFunctionDispatcher() { 314 ExtensionFunctionDispatcher::~ExtensionFunctionDispatcher() {
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 404
396 // See crbug.com/39178. 405 // See crbug.com/39178.
397 ExtensionsBrowserClient::Get()->PermitExternalProtocolHandler(); 406 ExtensionsBrowserClient::Get()->PermitExternalProtocolHandler();
398 NotifyApiFunctionCalled(extension->id(), params.name, std::move(args), 407 NotifyApiFunctionCalled(extension->id(), params.name, std::move(args),
399 browser_context_); 408 browser_context_);
400 UMA_HISTOGRAM_SPARSE_SLOWLY("Extensions.FunctionCalls", 409 UMA_HISTOGRAM_SPARSE_SLOWLY("Extensions.FunctionCalls",
401 function->histogram_value()); 410 function->histogram_value());
402 tracked_objects::ScopedProfile scoped_profile( 411 tracked_objects::ScopedProfile scoped_profile(
403 FROM_HERE_WITH_EXPLICIT_FUNCTION(function->name()), 412 FROM_HERE_WITH_EXPLICIT_FUNCTION(function->name()),
404 tracked_objects::ScopedProfile::ENABLED); 413 tracked_objects::ScopedProfile::ENABLED);
414 base::ElapsedTimer timer;
405 function->Run()->Execute(); 415 function->Run()->Execute();
416 // TODO(devlin): Once we have a baseline metric for how long functions take,
417 // we can create a handful of buckets and record the function name so that
418 // we can find what the fastest/slowest are.
419 // Note: Many functions execute finish asynchronously, so this time is not
420 // always a representation of total time taken. See also
421 // Extensions.Functions.TotalExecutionTime.
422 UMA_HISTOGRAM_TIMES("Extensions.Functions.SynchronousExecutionTime",
423 timer.Elapsed());
406 } else { 424 } else {
407 function->OnQuotaExceeded(violation_error); 425 function->OnQuotaExceeded(violation_error);
408 } 426 }
409 427
410 // Note: do not access |this| after this point. We may have been deleted 428 // Note: do not access |this| after this point. We may have been deleted
411 // if function->Run() ended up closing the tab that owns us. 429 // if function->Run() ended up closing the tab that owns us.
412 430
413 // Check if extension was uninstalled by management.uninstall. 431 // Check if extension was uninstalled by management.uninstall.
414 if (!registry->enabled_extensions().GetByID(params.extension_id)) 432 if (!registry->enabled_extensions().GetByID(params.extension_id))
415 return; 433 return;
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 // static 512 // static
495 void ExtensionFunctionDispatcher::SendAccessDenied( 513 void ExtensionFunctionDispatcher::SendAccessDenied(
496 const ExtensionFunction::ResponseCallback& callback, 514 const ExtensionFunction::ResponseCallback& callback,
497 functions::HistogramValue histogram_value) { 515 functions::HistogramValue histogram_value) {
498 base::ListValue empty_list; 516 base::ListValue empty_list;
499 callback.Run(ExtensionFunction::FAILED, empty_list, 517 callback.Run(ExtensionFunction::FAILED, empty_list,
500 "Access to extension API denied.", histogram_value); 518 "Access to extension API denied.", histogram_value);
501 } 519 }
502 520
503 } // namespace extensions 521 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698