• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 OHOS_ABILITY_RUNTIME_DUMP_RUNTIME_HELPER_H
17 #define OHOS_ABILITY_RUNTIME_DUMP_RUNTIME_HELPER_H
18 
19 #include "app_jsheap_mem_info.h"
20 #include "app_cjheap_mem_info.h"
21 #include "napi_common_want.h"
22 #include "ohos_application.h"
23 #include "runtime.h"
24 
25 namespace OHOS {
26 namespace AppExecFwk {
27 class DumpRuntimeHelper : public std::enable_shared_from_this<DumpRuntimeHelper> {
28 public:
29     explicit DumpRuntimeHelper(const std::shared_ptr<OHOSApplication> &application);
30     ~DumpRuntimeHelper() = default;
31     void SetAppFreezeFilterCallback();
32     void DumpJsHeap(const OHOS::AppExecFwk::JsHeapDumpInfo &info);
33     void DumpCjHeap(const OHOS::AppExecFwk::CjHeapDumpInfo &info);
34 private:
35     std::shared_ptr<OHOSApplication> application_ = nullptr;
36 
37     static bool Check2DOOMDumpOpt();
38     void GetCheckList(const std::unique_ptr<AbilityRuntime::Runtime> &runtime, std::string &checkList);
39     void WriteCheckList(const std::string &checkList);
40     napi_value GetJsLeakModule(napi_env env, napi_value global);
41     napi_value GetMethodCheck(napi_env env, napi_value requireValue, napi_value global);
42     static bool Init2DOOMDumpQuota(const std::string &path, uint32_t oomDumpProcessMaxQuota);
43     static bool Check2DOOMDumpQuota(uint32_t oomDumpMaxQuota, uint32_t oomDumpProcessMaxQuota);
44     static bool Get2DQuota(const std::string &path, const std::string &property, uint64_t &timestamp, int &quota);
45     static bool GetQuota(const std::string &path, const std::string &property,
46                          std::vector<int64_t> &output, size_t size);
47     static bool Set2DQuota(const std::string &path, uint64_t timestamp, int newQuota);
48     static uint64_t GetCurrentTimestamp();
49     static bool CheckOOMFreeSpace(uint64_t maxSpace);
50     static uint64_t GetMaskFromDirXattr(const std::string &path);
51     static bool CheckAppListenedEvents(const std::string &path);
52     static bool SetDirXattr(const std::string &path, const std::string &name, const std::string &value);
53     static bool GetDirXattr(const std::string &path, const std::string &name, std::string &value);
54     static bool IsFileExists(const std::string &file);
55     static bool ForceCreateDirectory(const std::string &path);
56     static bool CreateDir(const std::string &path);
57     static void CreateDirDelay(const std::string &path);
58     static bool CheckOomdumpSwitch();
59     static bool Check2CQuota();
60     static bool Check2DQuota(bool needDecreaseQuota);
61     static bool SafeStoll(const std::string &str, long long &value);
62     static int GetCompressQuota (const std::vector<int64_t> &quotas);
63     static bool SplitPropertyByComma(const std::string &property, std::string &runningId, std::string &value);
64     static std::string GetEventConfig(const std::string &key);
65 };
66 } // namespace AppExecFwk
67 } // namespace OHOS
68 
69 #endif // OHOS_ABILITY_RUNTIME_DUMP_RUNTIME_HELPER_H
70