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

Side by Side Diff: dbus/object_proxy.cc

Issue 11363173: Add DBusStatistics and DBusLogSource to log and show dbus stats (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 8 years, 1 month 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 | « dbus/dbus_statistics_unittest.cc ('k') | 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "dbus/bus.h" 5 #include "dbus/bus.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
11 #include "base/string_piece.h" 11 #include "base/string_piece.h"
12 #include "base/stringprintf.h" 12 #include "base/stringprintf.h"
13 #include "base/threading/thread.h" 13 #include "base/threading/thread.h"
14 #include "base/threading/thread_restrictions.h" 14 #include "base/threading/thread_restrictions.h"
15 #include "dbus/dbus_statistics.h"
15 #include "dbus/message.h" 16 #include "dbus/message.h"
16 #include "dbus/object_path.h" 17 #include "dbus/object_path.h"
17 #include "dbus/object_proxy.h" 18 #include "dbus/object_proxy.h"
18 #include "dbus/scoped_dbus_error.h" 19 #include "dbus/scoped_dbus_error.h"
19 20
20 namespace { 21 namespace {
21 22
22 const char kErrorServiceUnknown[] = "org.freedesktop.DBus.Error.ServiceUnknown"; 23 const char kErrorServiceUnknown[] = "org.freedesktop.DBus.Error.ServiceUnknown";
23 24
24 // Used for success ratio histograms. 1 for success, 0 for failure. 25 // Used for success ratio histograms. 1 for success, 0 for failure.
25 const int kSuccessRatioHistogramMaxValue = 2; 26 const int kSuccessRatioHistogramMaxValue = 2;
26 27
27 // The path of D-Bus Object sending NameOwnerChanged signal. 28 // The path of D-Bus Object sending NameOwnerChanged signal.
28 const char kDbusSystemObjectPath[] = "/org/freedesktop/DBus"; 29 const char kDBusSystemObjectPath[] = "/org/freedesktop/DBus";
29 30
30 // Gets the absolute signal name by concatenating the interface name and 31 // Gets the absolute signal name by concatenating the interface name and
31 // the signal name. Used for building keys for method_table_ in 32 // the signal name. Used for building keys for method_table_ in
32 // ObjectProxy. 33 // ObjectProxy.
33 std::string GetAbsoluteSignalName( 34 std::string GetAbsoluteSignalName(
34 const std::string& interface_name, 35 const std::string& interface_name,
35 const std::string& signal_name) { 36 const std::string& signal_name) {
36 return interface_name + "." + signal_name; 37 return interface_name + "." + signal_name;
37 } 38 }
38 39
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 ScopedDBusError error; 77 ScopedDBusError error;
77 78
78 // Send the message synchronously. 79 // Send the message synchronously.
79 const base::TimeTicks start_time = base::TimeTicks::Now(); 80 const base::TimeTicks start_time = base::TimeTicks::Now();
80 DBusMessage* response_message = 81 DBusMessage* response_message =
81 bus_->SendWithReplyAndBlock(request_message, timeout_ms, error.get()); 82 bus_->SendWithReplyAndBlock(request_message, timeout_ms, error.get());
82 // Record if the method call is successful, or not. 1 if successful. 83 // Record if the method call is successful, or not. 1 if successful.
83 UMA_HISTOGRAM_ENUMERATION("DBus.SyncMethodCallSuccess", 84 UMA_HISTOGRAM_ENUMERATION("DBus.SyncMethodCallSuccess",
84 response_message ? 1 : 0, 85 response_message ? 1 : 0,
85 kSuccessRatioHistogramMaxValue); 86 kSuccessRatioHistogramMaxValue);
87 statistics::AddBlockingSentMethodCall(service_name_,
88 method_call->GetInterface(),
89 method_call->GetMember());
86 90
87 if (!response_message) { 91 if (!response_message) {
88 LogMethodCallFailure(method_call->GetInterface(), 92 LogMethodCallFailure(method_call->GetInterface(),
89 method_call->GetMember(), 93 method_call->GetMember(),
90 error.is_set() ? error.name() : "unknown error type", 94 error.is_set() ? error.name() : "unknown error type",
91 error.is_set() ? error.message() : ""); 95 error.is_set() ? error.message() : "");
92 return NULL; 96 return NULL;
93 } 97 }
94 // Record time spent for the method call. Don't include failures. 98 // Record time spent for the method call. Don't include failures.
95 UMA_HISTOGRAM_TIMES("DBus.SyncMethodCallTime", 99 UMA_HISTOGRAM_TIMES("DBus.SyncMethodCallTime",
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 DBusMessage* request_message = method_call->raw_message(); 141 DBusMessage* request_message = method_call->raw_message();
138 dbus_message_ref(request_message); 142 dbus_message_ref(request_message);
139 143
140 base::Closure task = base::Bind(&ObjectProxy::StartAsyncMethodCall, 144 base::Closure task = base::Bind(&ObjectProxy::StartAsyncMethodCall,
141 this, 145 this,
142 timeout_ms, 146 timeout_ms,
143 request_message, 147 request_message,
144 callback, 148 callback,
145 error_callback, 149 error_callback,
146 start_time); 150 start_time);
151 statistics::AddSentMethodCall(service_name_,
152 method_call->GetInterface(),
153 method_call->GetMember());
154
147 // Wait for the response in the D-Bus thread. 155 // Wait for the response in the D-Bus thread.
148 bus_->PostTaskToDBusThread(FROM_HERE, task); 156 bus_->PostTaskToDBusThread(FROM_HERE, task);
149 } 157 }
150 158
151 void ObjectProxy::ConnectToSignal(const std::string& interface_name, 159 void ObjectProxy::ConnectToSignal(const std::string& interface_name,
152 const std::string& signal_name, 160 const std::string& signal_name,
153 SignalCallback signal_callback, 161 SignalCallback signal_callback,
154 OnConnectedCallback on_connected_callback) { 162 OnConnectedCallback on_connected_callback) {
155 bus_->AssertOnOriginThread(); 163 bus_->AssertOnOriginThread();
156 164
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 // reference so we can use it in Signal. 434 // reference so we can use it in Signal.
427 dbus_message_ref(raw_message); 435 dbus_message_ref(raw_message);
428 scoped_ptr<Signal> signal( 436 scoped_ptr<Signal> signal(
429 Signal::FromRawMessage(raw_message)); 437 Signal::FromRawMessage(raw_message));
430 438
431 // Verify the signal comes from the object we're proxying for, this is 439 // Verify the signal comes from the object we're proxying for, this is
432 // our last chance to return DBUS_HANDLER_RESULT_NOT_YET_HANDLED and 440 // our last chance to return DBUS_HANDLER_RESULT_NOT_YET_HANDLED and
433 // allow other object proxies to handle instead. 441 // allow other object proxies to handle instead.
434 const dbus::ObjectPath path = signal->GetPath(); 442 const dbus::ObjectPath path = signal->GetPath();
435 if (path != object_path_) { 443 if (path != object_path_) {
436 if (path.value() == kDbusSystemObjectPath && 444 if (path.value() == kDBusSystemObjectPath &&
437 signal->GetMember() == "NameOwnerChanged") { 445 signal->GetMember() == "NameOwnerChanged") {
438 // Handle NameOwnerChanged separately 446 // Handle NameOwnerChanged separately
439 return HandleNameOwnerChanged(signal.Pass()); 447 return HandleNameOwnerChanged(signal.Pass());
440 } 448 }
441 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; 449 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
442 } 450 }
443 451
444 const std::string interface = signal->GetInterface(); 452 const std::string interface = signal->GetInterface();
445 const std::string member = signal->GetMember(); 453 const std::string member = signal->GetMember();
446 454
455 statistics::AddReceivedSignal(service_name_, interface, member);
456
447 // Check if we know about the signal. 457 // Check if we know about the signal.
448 const std::string absolute_signal_name = GetAbsoluteSignalName( 458 const std::string absolute_signal_name = GetAbsoluteSignalName(
449 interface, member); 459 interface, member);
450 MethodTable::const_iterator iter = method_table_.find(absolute_signal_name); 460 MethodTable::const_iterator iter = method_table_.find(absolute_signal_name);
451 if (iter == method_table_.end()) { 461 if (iter == method_table_.end()) {
452 // Don't know about the signal. 462 // Don't know about the signal.
453 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; 463 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
454 } 464 }
455 VLOG(1) << "Signal received: " << signal->ToString(); 465 VLOG(1) << "Signal received: " << signal->ToString();
456 466
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
653 } 663 }
654 return DBUS_HANDLER_RESULT_HANDLED; 664 return DBUS_HANDLER_RESULT_HANDLED;
655 } 665 }
656 } 666 }
657 667
658 // Untrusted or uninteresting signal 668 // Untrusted or uninteresting signal
659 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; 669 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
660 } 670 }
661 671
662 } // namespace dbus 672 } // namespace dbus
OLDNEW
« no previous file with comments | « dbus/dbus_statistics_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698