• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 Huawei Device Co., Ltd.
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  */
15 
16 #ifndef RDB_STAT_REPORTER_H
17 #define RDB_STAT_REPORTER_H
18 
19 #include <ctime>
20 #include <memory>
21 
22 #include "rdb_store_config.h"
23 #include "rdb_types.h"
24 namespace OHOS::NativeRdb {
25 enum StatType : int32_t {
26     RDB_PERF = 1,
27 };
28 
29 enum SubType : int32_t {
30     INSERT = 1,
31     BATCHINSERT,
32     UPDATE,
33     DELETE,
34     EXECUTESQL,
35     EXECUTE,
36     BEGINTRANSACTION,
37     COMMIT,
38     ROLLBACK,
39 };
40 
41 enum TimeType : int32_t {
42     TIME_LEVEL_NONE = 0,
43     TIME_LEVEL_FIRST,
44     TIME_LEVEL_SECOND,
45     TIME_LEVEL_THIRD,
46 };
47 
48 class RdbStatReporter {
49 public:
50     using ReportFunc = std::function<void(const DistributedRdb::RdbStatEvent &)>;
51     RdbStatReporter(StatType statType, SubType subType, const RdbStoreConfig &config, std::shared_ptr<ReportFunc> func);
52     ~RdbStatReporter();
53     static TimeType GetTimeType(uint32_t costTime);
54 private:
55     std::chrono::steady_clock::time_point startTime_;
56     DistributedRdb::RdbStatEvent statEvent_;
57     std::shared_ptr<ReportFunc> reportFunc_ = nullptr;
58     static std::atomic<std::chrono::steady_clock::time_point> reportTime_;
59 };
60 
61 } // namespace OHOS::NativeRdb
62 #endif // RDB_STAT_REPORTER_H