added iOS source code
[wl-app.git] / iOS / Pods / Realm / include / core / realm / metrics / transaction_info.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_TRANSACTION_INFO_HPP
20 #define REALM_TRANSACTION_INFO_HPP
21
22 #include <memory>
23 #include <string>
24
25 #include <realm/metrics/metric_timer.hpp>
26 #include <realm/util/features.h>
27
28 #if REALM_METRICS
29
30 namespace realm {
31 namespace metrics {
32
33 class Metrics;
34
35 class TransactionInfo {
36 public:
37     enum TransactionType {
38         read_transaction,
39         write_transaction
40     };
41     TransactionInfo(TransactionType type);
42     TransactionInfo(const TransactionInfo&) = default;
43     ~TransactionInfo() noexcept;
44
45     TransactionType get_transaction_type() const;
46     // the transaction time is a total amount which includes fsync_time + write_time + user_time
47     double get_transaction_time() const;
48     double get_fsync_time() const;
49     double get_write_time() const;
50     size_t get_disk_size() const;
51     size_t get_free_space() const;
52     size_t get_total_objects() const;
53     size_t get_num_available_versions() const;
54
55 private:
56     MetricTimerResult m_transaction_time;
57     std::shared_ptr<MetricTimerResult> m_fsync_time;
58     std::shared_ptr<MetricTimerResult> m_write_time;
59     MetricTimer m_transact_timer;
60
61     size_t m_realm_disk_size;
62     size_t m_realm_free_space;
63     size_t m_total_objects;
64     TransactionType m_type;
65     size_t m_num_versions;
66
67     friend class Metrics;
68     void update_stats(size_t disk_size, size_t free_space, size_t total_objects, size_t available_versions);
69     void finish_timer();
70 };
71
72 } // namespace metrics
73 } // namespace realm
74
75 #endif // REALM_METRICS
76
77 #endif // REALM_TRANSACTION_INFO_HPP