• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 #ifndef HIDUMPER_EXECUTOR_H
16 #define HIDUMPER_EXECUTOR_H
17 #include <memory>
18 #include <string>
19 #include <vector>
20 #include "hilog_wrapper.h"
21 #include "common.h"
22 #include "common/dumper_parameter.h"
23 namespace OHOS {
24 namespace HiviewDFX {
25 class HidumperExecutor {
26 public:
27     virtual ~HidumperExecutor();
28 
29     using StringMatrix = std::shared_ptr<std::vector<std::vector<std::string>>>;
30 
31     virtual DumpStatus PreExecute(const std::shared_ptr<DumperParameter>& parameter, StringMatrix dumpDatas) = 0;
32     virtual DumpStatus Execute() = 0;
33     virtual DumpStatus AfterExecute() = 0;
34     virtual void Reset();
35 public:
36     DumpStatus DoPreExecute(const std::shared_ptr<DumperParameter>& parameter, StringMatrix dumpDatas);
37     DumpStatus DoExecute();
38     DumpStatus DoAfterExecute();
39 
40     void SetDumpConfig(const std::shared_ptr<DumpCfg>& config);
41     const std::shared_ptr<DumpCfg>& GetDumpConfig() const;
42 
43     uint64_t GetTimeRemain() const;
44     bool IsTimeout() const;
45     bool IsCanceled() const;
46     std::string GetTimeoutStr(std::string head = "") const;
47 protected:
48     std::shared_ptr<DumpCfg> ptrDumpCfg_;
49 private:
50     static bool IsTimeout(uint64_t remain);
51     uint64_t GetHitTickCount(int nest = 0) const;
52 private:
53     std::shared_ptr<RawParam> rawParam_;
54     std::shared_ptr<HidumperExecutor> ptrParent_;
55     bool hasOnce_ {false};
56     bool hasOnceTimeout_ {false};
57     uint64_t hitTickCount_ {0};
58     uint64_t timeOutMillSec_ {0};
59     static const std::string TIME_OUT_STR;
60 };
61 } // namespace HiviewDFX
62 } // namespace OHOS
63 #endif // HIDUMPER_EXECUTOR_H
64