metrics.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. // Copyright 2016 The Crashpad Authors. All rights reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #ifndef CRASHPAD_UTIL_MISC_METRICS_H_
  15. #define CRASHPAD_UTIL_MISC_METRICS_H_
  16. #include <inttypes.h>
  17. #include "base/macros.h"
  18. #include "util/file/file_io.h"
  19. namespace crashpad {
  20. //! \brief Container class to hold shared UMA metrics integration points.
  21. //!
  22. //! Each static function in this class will call a `UMA_*` from
  23. //! `base/metrics/histogram_macros.h`. When building Crashpad standalone,
  24. //! (against mini_chromium), these macros do nothing. When built against
  25. //! Chromium's base, they allow integration with its metrics system.
  26. class Metrics {
  27. public:
  28. //! \brief Values for CrashReportPending().
  29. //!
  30. //! \note These are used as metrics enumeration values, so new values should
  31. //! always be added at the end, before PendingReportReason::kMaxValue.
  32. enum class PendingReportReason : int32_t {
  33. //! \brief A report was newly created and is ready for upload.
  34. kNewlyCreated = 0,
  35. //! \brief The user manually requested the report be uploaded.
  36. kUserInitiated = 1,
  37. //! \brief The number of values in this enumeration; not a valid value.
  38. kMaxValue
  39. };
  40. //! \brief Reports when a crash upload has entered the pending state.
  41. static void CrashReportPending(PendingReportReason reason);
  42. //! \brief Reports the size of a crash report file in bytes. Should be called
  43. //! when a new report is written to disk.
  44. static void CrashReportSize(FileHandle file);
  45. //! \brief Reports on a crash upload attempt, and if it succeeded.
  46. static void CrashUploadAttempted(bool successful);
  47. //! \brief Values for CrashUploadSkipped().
  48. //!
  49. //! \note These are used as metrics enumeration values, so new values should
  50. //! always be added at the end, before CrashSkippedReason::kMaxValue.
  51. enum class CrashSkippedReason : int32_t {
  52. //! \brief Crash uploading is disabled.
  53. kUploadsDisabled = 0,
  54. //! \brief There was another upload too recently, so this one was throttled.
  55. kUploadThrottled = 1,
  56. //! \brief The report had an unexpected timestamp.
  57. kUnexpectedTime = 2,
  58. //! \brief The database reported an error, likely due to a filesystem
  59. //! problem.
  60. kDatabaseError = 3,
  61. //! \brief The upload of the crash failed during communication with the
  62. //! server.
  63. kUploadFailed = 4,
  64. //! \brief The number of values in this enumeration; not a valid value.
  65. kMaxValue
  66. };
  67. //! \brief Reports when a report is moved to the completed state in the
  68. //! database, without the report being uploadad.
  69. static void CrashUploadSkipped(CrashSkippedReason reason);
  70. //! \brief The result of capturing an exception.
  71. //!
  72. //! \note These are used as metrics enumeration values, so new values should
  73. //! always be added at the end, before CaptureResult::kMaxValue.
  74. enum class CaptureResult : int32_t {
  75. //! \brief The exception capture succeeded normally.
  76. kSuccess = 0,
  77. //! \brief Unexpected exception behavior.
  78. //!
  79. //! This value is only used on macOS.
  80. kUnexpectedExceptionBehavior = 1,
  81. //! \brief Failed due to attempt to suspend self.
  82. //!
  83. //! This value is only used on macOS.
  84. kFailedDueToSuspendSelf = 2,
  85. //! \brief The process snapshot could not be captured.
  86. kSnapshotFailed = 3,
  87. //! \brief The exception could not be initialized.
  88. kExceptionInitializationFailed = 4,
  89. //! \brief The attempt to prepare a new crash report in the crash database
  90. //! failed.
  91. kPrepareNewCrashReportFailed = 5,
  92. //! \brief Writing the minidump to disk failed.
  93. kMinidumpWriteFailed = 6,
  94. //! \brief There was a database error in attempt to complete the report.
  95. kFinishedWritingCrashReportFailed = 7,
  96. //! \brief The number of values in this enumeration; not a valid value.
  97. kMaxValue
  98. };
  99. //! \brief Reports on the outcome of capturing a report in the exception
  100. //! handler. Should be called on all capture completion paths.
  101. static void ExceptionCaptureResult(CaptureResult result);
  102. //! \brief The exception code for an exception was retrieved.
  103. //!
  104. //! These values are OS-specific, and correspond to
  105. //! MINIDUMP_EXCEPTION::ExceptionCode.
  106. static void ExceptionCode(uint32_t exception_code);
  107. //! \brief The exception handler server started capturing an exception.
  108. static void ExceptionEncountered();
  109. //! \brief An important event in a handler process’ lifetime.
  110. //!
  111. //! \note These are used as metrics enumeration values, so new values should
  112. //! always be added at the end, before LifetimeMilestone::kMaxValue.
  113. enum class LifetimeMilestone : int32_t {
  114. //! \brief The handler process started.
  115. kStarted = 0,
  116. //! \brief The handler process exited normally and cleanly.
  117. kExitedNormally,
  118. //! \brief The handler process exited early, but was successful in
  119. //! performing some non-default action on user request.
  120. kExitedEarly,
  121. //! \brief The handler process exited with a failure code.
  122. kFailed,
  123. //! \brief The handler process was forcibly terminated.
  124. kTerminated,
  125. //! \brief The handler process crashed.
  126. kCrashed,
  127. //! \brief The number of values in this enumeration; not a valid value.
  128. kMaxValue
  129. };
  130. //! \brief Records a handler start/exit/crash event.
  131. static void HandlerLifetimeMilestone(LifetimeMilestone milestone);
  132. //! \brief The handler process crashed with the given exception code.
  133. //!
  134. //! This is currently only reported on Windows.
  135. static void HandlerCrashed(uint32_t exception_code);
  136. private:
  137. DISALLOW_IMPLICIT_CONSTRUCTORS(Metrics);
  138. };
  139. } // namespace crashpad
  140. #endif // CRASHPAD_UTIL_MISC_METRICS_H_