dbus_statistics.h 3.3 KB

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