• 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 TeleMetryRecord {
25     std::string module;
26     uint32_t usedSize = 0;
27     uint32_t quota = 0;
28     uint32_t threshold = 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 &beginTime,
42         const std::map<std::string, int64_t> &flowControlQuotas);
43     TelemetryRet NeedTelemetryDump(const std::string& module, int64_t traceSize);
44     void ClearTelemetryData();
45 
46 private:
47     std::shared_ptr<NativeRdb::RdbStore> dbStore_;
48 
49     void InsertNewData(const std::string &telemetryId, int64_t beginTime,
50         const std::map<std::string, int64_t> &flowControlQuotas);
51     bool QueryTable(const std::string &module, int64_t &usedSize, int64_t &quotaSize);
52     void UpdateTable(const std::string &module, int64_t newSize);
53 };
54 
55 }
56 #endif //HIVIEWDFX_HIVIEW_TELEMETRY_STORAGE_H
57