• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
3 // found in the LICENSE file.
4 
5 #ifndef DBUS_DBUS_STATISTICS_H_
6 #define DBUS_DBUS_STATISTICS_H_
7 
8 #include <string>
9 
10 #include "dbus/dbus_export.h"
11 
12 // The functions defined here are used to gather DBus statistics, and
13 // provide them in a format convenient for debugging. These functions are only
14 // valid when called from the main thread (the thread which Initialize() was
15 // called from). Calls from other threads will be ignored.
16 
17 namespace dbus {
18 namespace statistics {
19 
20 // Enum to specify what level of detail to show in GetAsString
21 enum ShowInString {
22   SHOW_SERVICE = 0,  // Service totals only
23   SHOW_INTERFACE = 1,  // Service + interface totals
24   SHOW_METHOD = 2,  // Service + interface + method totals
25 };
26 
27 // Enum to specify how to format the display in GetAsString
28 enum FormatString {
29   FORMAT_TOTALS = 0,  // Raw totals only
30   FORMAT_PER_MINUTE = 1,  // Per-minute only
31   FORMAT_ALL = 2  // Include all format details
32 };
33 
34 // Initializes / shuts down dbus statistics gathering. Calling Initialize
35 // more than once will reset the statistics.
36 CHROME_DBUS_EXPORT void Initialize();
37 CHROME_DBUS_EXPORT void Shutdown();
38 
39 // Add sent/received calls to the statistics gathering class. These methods
40 // do nothing unless Initialize() was called.
41 CHROME_DBUS_EXPORT void AddSentMethodCall(const std::string& service,
42                                           const std::string& interface,
43                                           const std::string& method);
44 CHROME_DBUS_EXPORT void AddReceivedSignal(const std::string& service,
45                                           const std::string& interface,
46                                           const std::string& method);
47 // Track synchronous calls independently since we want to highlight
48 // (and remove) these.
49 CHROME_DBUS_EXPORT void AddBlockingSentMethodCall(const std::string& service,
50                                                   const std::string& interface,
51                                                   const std::string& method);
52 
53 // Output the calls into a formatted string. |show| determines what level
54 // of detail to show: one line per service, per interface, or per method.
55 // If |show_per_minute| is true include per minute stats.
56 // Example output for SHOW_METHOD, FORMAT_TOTALS:
57 //   org.chromium.Mtpd.EnumerateStorage: Sent: 100
58 //   org.chromium.Mtpd.MTPStorageSignal: Received: 20
59 // Example output for SHOW_INTERFACE, FORMAT_ALL:
60 //   org.chromium.Mtpd: Sent: 100 (10/min) Received: 20 (2/min)
61 CHROME_DBUS_EXPORT std::string GetAsString(ShowInString show,
62                                            FormatString format);
63 
64 namespace testing {
65 // Sets |sent| to the number of sent calls, |received| to the number of
66 // received calls, and |blocking| to the number of sent blocking calls for
67 // service+interface+method. Used in unittests.
68 CHROME_DBUS_EXPORT bool GetCalls(const std::string& service,
69                                  const std::string& interface,
70                                  const std::string& method,
71                                  int* sent,
72                                  int* received,
73                                  int* blocking);
74 }  // namespace testing
75 
76 }  // namespace statistics
77 }  // namespace dbus
78 
79 #endif  // DBUS_DBUS_STATISTICS_H_
80