• 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 HIVIEWDFX_HIVIEW_TELEMETRY_STORAGE_H
17 #define HIVIEWDFX_HIVIEW_TELEMETRY_STORAGE_H
18 #include "memory"
19 
20 #include "rdb_store.h"
21 
22 namespace OHOS::HiviewDFX {
23 
24 struct TeleMetryFlowRecord {
25     int64_t usedSize = 0;
26     int64_t quotaSize = 0;
27     int64_t totalUsedSize = 0;
28     int64_t totalQuotaSize = 0;
29 };
30 
31 enum class TelemetryRet {
32     SUCCESS,
33     OVER_FLOW,
34     EXIT
35 };
36 
37 class TeleMetryStorage {
38 public:
TeleMetryStorage(std::shared_ptr<NativeRdb::RdbStore> dbStore)39     explicit TeleMetryStorage(std::shared_ptr<NativeRdb::RdbStore> dbStore) : dbStore_(dbStore) {}
40     ~TeleMetryStorage() = default;
41     TelemetryRet InitTelemetryControl(const std::string &telemetryId, int64_t &runningTime,
42         const std::map<std::string, int64_t> &flowControlQuotas);
43     TelemetryRet NeedTelemetryDump(const std::string &module);
44     void ClearTelemetryData();
45     bool QueryRunningTime(int64_t &runningTime);
46     bool UpdateRunningTime(int64_t runningTime);
47     void TelemetryStore(const std::string &module, int64_t traceSize);
48 
49 private:
50     bool GetFlowRecord(const std::string &module, TeleMetryFlowRecord &flowRecord);
51     void InsertNewData(const std::string &telemetryId, const std::map<std::string, int64_t> &flowControlQuotas);
52     bool QueryTable(const std::string &module, int64_t &usedSize, int64_t &quotaSize);
53     bool UpdateTable(const std::string &module, int64_t newSize);
54 
55 private:
56     std::shared_ptr<NativeRdb::RdbStore> dbStore_;
57 };
58 
59 }
60 #endif //HIVIEWDFX_HIVIEW_TELEMETRY_STORAGE_H
61