proto_leveldb_wrapper_metrics.cc 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. // Copyright 2018 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. #include "components/leveldb_proto/internal/proto_leveldb_wrapper_metrics.h"
  5. #include "base/metrics/histogram.h"
  6. #include "third_party/leveldatabase/env_chromium.h"
  7. namespace leveldb_proto {
  8. // static
  9. void ProtoLevelDBWrapperMetrics::RecordInit(const std::string& client,
  10. const leveldb::Status& status) {
  11. base::HistogramBase* init_status_histogram =
  12. base::LinearHistogram::FactoryGet(
  13. std::string("ProtoDB.InitStatus.") + client, 1,
  14. leveldb_env::LEVELDB_STATUS_MAX, leveldb_env::LEVELDB_STATUS_MAX + 1,
  15. base::Histogram::kUmaTargetedHistogramFlag);
  16. if (init_status_histogram)
  17. init_status_histogram->Add(leveldb_env::GetLevelDBStatusUMAValue(status));
  18. }
  19. // static
  20. void ProtoLevelDBWrapperMetrics::RecordUpdate(const std::string& client,
  21. bool success,
  22. const leveldb::Status& status) {
  23. base::HistogramBase* update_success_histogram_ =
  24. base::BooleanHistogram::FactoryGet(
  25. std::string("ProtoDB.UpdateSuccess.") + client,
  26. base::Histogram::kUmaTargetedHistogramFlag);
  27. base::HistogramBase* update_error_histogram_ =
  28. base::LinearHistogram::FactoryGet(
  29. std::string("ProtoDB.UpdateErrorStatus.") + client, 1,
  30. leveldb_env::LEVELDB_STATUS_MAX, leveldb_env::LEVELDB_STATUS_MAX + 1,
  31. base::Histogram::kUmaTargetedHistogramFlag);
  32. if (update_success_histogram_)
  33. update_success_histogram_->Add(success);
  34. if (!success && update_error_histogram_)
  35. update_error_histogram_->Add(leveldb_env::GetLevelDBStatusUMAValue(status));
  36. }
  37. // static
  38. void ProtoLevelDBWrapperMetrics::RecordGet(const std::string& client,
  39. bool success,
  40. bool found,
  41. const leveldb::Status& status) {
  42. base::HistogramBase* get_success_histogram =
  43. base::BooleanHistogram::FactoryGet(
  44. std::string("ProtoDB.GetSuccess.") + client,
  45. base::Histogram::kUmaTargetedHistogramFlag);
  46. base::HistogramBase* get_found_histogram = base::BooleanHistogram::FactoryGet(
  47. std::string("ProtoDB.GetFound.") + client,
  48. base::Histogram::kUmaTargetedHistogramFlag);
  49. base::HistogramBase* get_error_histogram = base::LinearHistogram::FactoryGet(
  50. std::string("ProtoDB.GetErrorStatus.") + client, 1,
  51. leveldb_env::LEVELDB_STATUS_MAX, leveldb_env::LEVELDB_STATUS_MAX + 1,
  52. base::Histogram::kUmaTargetedHistogramFlag);
  53. if (get_success_histogram)
  54. get_success_histogram->Add(success);
  55. if (get_found_histogram)
  56. get_found_histogram->Add(found);
  57. if (!success && get_error_histogram)
  58. get_error_histogram->Add(leveldb_env::GetLevelDBStatusUMAValue(status));
  59. }
  60. // static
  61. void ProtoLevelDBWrapperMetrics::RecordLoadKeys(const std::string& client,
  62. bool success) {
  63. base::HistogramBase* load_keys_success_histogram =
  64. base::BooleanHistogram::FactoryGet(
  65. std::string("ProtoDB.LoadKeysSuccess.") + client,
  66. base::Histogram::kUmaTargetedHistogramFlag);
  67. if (load_keys_success_histogram)
  68. load_keys_success_histogram->Add(success);
  69. }
  70. // static
  71. void ProtoLevelDBWrapperMetrics::RecordLoadEntries(const std::string& client,
  72. bool success) {
  73. base::HistogramBase* load_entries_success_histogram =
  74. base::BooleanHistogram::FactoryGet(
  75. std::string("ProtoDB.LoadEntriesSuccess.") + client,
  76. base::Histogram::kUmaTargetedHistogramFlag);
  77. if (load_entries_success_histogram)
  78. load_entries_success_histogram->Add(success);
  79. }
  80. // static
  81. void ProtoLevelDBWrapperMetrics::RecordLoadKeysAndEntries(
  82. const std::string& client,
  83. bool success) {
  84. base::HistogramBase* load_keys_and_entries_success_histogram =
  85. base::BooleanHistogram::FactoryGet(
  86. std::string("ProtoDB.LoadKeysAndEntriesSuccess.") + client,
  87. base::Histogram::kUmaTargetedHistogramFlag);
  88. if (load_keys_and_entries_success_histogram)
  89. load_keys_and_entries_success_histogram->Add(success);
  90. }
  91. // static
  92. void ProtoLevelDBWrapperMetrics::RecordDestroy(const std::string& client,
  93. bool success) {
  94. base::HistogramBase* destroy_success_histogram =
  95. base::BooleanHistogram::FactoryGet(
  96. std::string("ProtoDB.DestroySuccess.") + client,
  97. base::Histogram::kUmaTargetedHistogramFlag);
  98. if (destroy_success_histogram)
  99. destroy_success_histogram->Add(success);
  100. }
  101. } // namespace leveldb_proto