metrics.hpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*************************************************************************
  2. *
  3. * Copyright 2016 Realm Inc.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. *
  17. **************************************************************************/
  18. #ifndef REALM_METRICS_HPP
  19. #define REALM_METRICS_HPP
  20. #include <memory>
  21. #include <realm/metrics/query_info.hpp>
  22. #include <realm/metrics/transaction_info.hpp>
  23. #include <realm/util/features.h>
  24. #include "realm/util/fixed_size_buffer.hpp"
  25. namespace realm {
  26. class Group;
  27. namespace metrics {
  28. class Metrics {
  29. public:
  30. Metrics(size_t max_history_size);
  31. ~Metrics() noexcept;
  32. size_t num_query_metrics() const;
  33. size_t num_transaction_metrics() const;
  34. void add_query(QueryInfo info);
  35. void add_transaction(TransactionInfo info);
  36. void start_read_transaction();
  37. void start_write_transaction();
  38. void end_read_transaction(size_t total_size, size_t free_space, size_t num_objects, size_t num_versions,
  39. size_t num_decrypted_pages);
  40. void end_write_transaction(size_t total_size, size_t free_space, size_t num_objects, size_t num_versions,
  41. size_t num_decrypted_pages);
  42. static std::unique_ptr<MetricTimer> report_fsync_time(const Group& g);
  43. static std::unique_ptr<MetricTimer> report_write_time(const Group& g);
  44. using QueryInfoList = util::FixedSizeBuffer<QueryInfo>;
  45. using TransactionInfoList = util::FixedSizeBuffer<TransactionInfo>;
  46. // Get the list of metric objects tracked since the last take
  47. std::unique_ptr<QueryInfoList> take_queries();
  48. std::unique_ptr<TransactionInfoList> take_transactions();
  49. private:
  50. std::unique_ptr<QueryInfoList> m_query_info;
  51. std::unique_ptr<TransactionInfoList> m_transaction_info;
  52. std::unique_ptr<TransactionInfo> m_pending_read;
  53. std::unique_ptr<TransactionInfo> m_pending_write;
  54. size_t m_max_num_queries;
  55. size_t m_max_num_transactions;
  56. };
  57. } // namespace metrics
  58. } // namespace realm
  59. #endif // REALM_METRICS_HPP