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