added iOS source code
[wl-app.git] / iOS / Pods / Realm / include / core / realm / metrics / metrics.hpp
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
19 #ifndef REALM_METRICS_HPP
20 #define REALM_METRICS_HPP
21
22 #include <memory>
23 #include <vector>
24
25 #include <realm/metrics/query_info.hpp>
26 #include <realm/metrics/transaction_info.hpp>
27 #include <realm/util/features.h>
28
29 namespace realm {
30
31 class Group;
32
33 namespace metrics {
34
35 #if REALM_METRICS
36
37 class Metrics {
38 public:
39     Metrics();
40     ~Metrics() noexcept;
41     size_t num_query_metrics() const;
42     size_t num_transaction_metrics() const;
43
44     void add_query(QueryInfo info);
45     void add_transaction(TransactionInfo info);
46
47     void start_read_transaction();
48     void start_write_transaction();
49     void end_read_transaction(size_t total_size, size_t free_space, size_t num_objects, size_t num_versions);
50     void end_write_transaction(size_t total_size, size_t free_space, size_t num_objects, size_t num_versions);
51     static std::unique_ptr<MetricTimer> report_fsync_time(const Group& g);
52     static std::unique_ptr<MetricTimer> report_write_time(const Group& g);
53
54     using QueryInfoList = std::vector<QueryInfo>;
55     using TransactionInfoList = std::vector<TransactionInfo>;
56
57     // Get the list of metric objects tracked since the last take
58     std::unique_ptr<QueryInfoList> take_queries();
59     std::unique_ptr<TransactionInfoList> take_transactions();
60 private:
61     std::unique_ptr<QueryInfoList> m_query_info;
62     std::unique_ptr<TransactionInfoList> m_transaction_info;
63
64     std::unique_ptr<TransactionInfo> m_pending_read;
65     std::unique_ptr<TransactionInfo> m_pending_write;
66 };
67
68
69 #else
70
71 class Metrics
72 {
73 };
74
75 #endif // REALM_METRICS
76
77 } // namespace metrics
78 } // namespace realm
79
80
81
82 #endif // REALM_METRICS_HPP