metrics.cc 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. #include "util/misc/metrics.h"
  15. #include "base/metrics/histogram_macros.h"
  16. #include "base/metrics/sparse_histogram.h"
  17. #include "build/build_config.h"
  18. #if defined(OS_MACOSX)
  19. #define METRICS_OS_NAME "Mac"
  20. #elif defined(OS_WIN)
  21. #define METRICS_OS_NAME "Win"
  22. #elif defined(OS_ANDROID)
  23. #define METRICS_OS_NAME "Android"
  24. #elif defined(OS_LINUX)
  25. #define METRICS_OS_NAME "Linux"
  26. #endif
  27. namespace crashpad {
  28. namespace {
  29. //! \brief Metrics values used to track the start and completion of a crash
  30. //! handling. These are used as metrics values directly, so
  31. //! enumeration values so new values should always be added at the end.
  32. enum class ExceptionProcessingState {
  33. //! \brief Logged when exception processing is started.
  34. kStarted = 0,
  35. //! \brief Logged when exception processing completes.
  36. kFinished = 1,
  37. };
  38. void ExceptionProcessing(ExceptionProcessingState state) {
  39. UMA_HISTOGRAM_COUNTS("Crashpad.ExceptionEncountered",
  40. static_cast<int32_t>(state));
  41. }
  42. } // namespace
  43. // static
  44. void Metrics::CrashReportPending(PendingReportReason reason) {
  45. UMA_HISTOGRAM_ENUMERATION(
  46. "Crashpad.CrashReportPending",
  47. static_cast<int32_t>(reason),
  48. static_cast<int32_t>(PendingReportReason::kMaxValue));
  49. }
  50. // static
  51. void Metrics::CrashReportSize(FileHandle file) {
  52. const FileOffset size = LoggingFileSizeByHandle(file);
  53. UMA_HISTOGRAM_CUSTOM_COUNTS(
  54. "Crashpad.CrashReportSize", size, 0, 20 * 1024 * 1024, 50);
  55. }
  56. // static
  57. void Metrics::CrashUploadAttempted(bool successful) {
  58. UMA_HISTOGRAM_COUNTS("Crashpad.CrashUpload.AttemptSuccessful",
  59. static_cast<int32_t>(successful));
  60. }
  61. // static
  62. void Metrics::CrashUploadSkipped(CrashSkippedReason reason) {
  63. UMA_HISTOGRAM_ENUMERATION(
  64. "Crashpad.CrashUpload.Skipped",
  65. static_cast<int32_t>(reason),
  66. static_cast<int32_t>(CrashSkippedReason::kMaxValue));
  67. }
  68. // static
  69. void Metrics::ExceptionCaptureResult(CaptureResult result) {
  70. ExceptionProcessing(ExceptionProcessingState::kFinished);
  71. UMA_HISTOGRAM_ENUMERATION("Crashpad.ExceptionCaptureResult",
  72. static_cast<int32_t>(result),
  73. static_cast<int32_t>(CaptureResult::kMaxValue));
  74. }
  75. // static
  76. void Metrics::ExceptionCode(uint32_t exception_code) {
  77. UMA_HISTOGRAM_SPARSE_SLOWLY("Crashpad.ExceptionCode." METRICS_OS_NAME,
  78. static_cast<int32_t>(exception_code));
  79. }
  80. // static
  81. void Metrics::ExceptionEncountered() {
  82. ExceptionProcessing(ExceptionProcessingState::kStarted);
  83. }
  84. // static
  85. void Metrics::HandlerLifetimeMilestone(LifetimeMilestone milestone) {
  86. UMA_HISTOGRAM_ENUMERATION("Crashpad.HandlerLifetimeMilestone",
  87. static_cast<int32_t>(milestone),
  88. static_cast<int32_t>(LifetimeMilestone::kMaxValue));
  89. }
  90. // static
  91. void Metrics::HandlerCrashed(uint32_t exception_code) {
  92. UMA_HISTOGRAM_SPARSE_SLOWLY(
  93. "Crashpad.HandlerCrash.ExceptionCode." METRICS_OS_NAME,
  94. static_cast<int32_t>(exception_code));
  95. }
  96. } // namespace crashpad