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 #include "lperf.h"
17
18 #include "lite_perf.h"
19
20 namespace OHOS {
21 namespace Developtools {
22 namespace HiPerf {
23 namespace HiPerfLocal {
24 class Lperf::Impl {
25 public:
26 Impl();
27 ~Impl();
28
29 int StartProcessStackSampling(const std::vector<int>& tids, int freq, int milliseconds, bool parseMiniDebugInfo);
30 int CollectSampleStackByTid(int tid, std::string& stack);
31 int FinishProcessStackSampling();
32
33 private:
34 std::shared_ptr<OHOS::HiviewDFX::LitePerf> litePerf_;
35 };
36
GetInstance()37 Lperf& Lperf::GetInstance()
38 {
39 static Lperf lperfInstance;
40 return lperfInstance;
41 }
42
Lperf()43 Lperf::Lperf() : Impl_(std::make_shared<Impl>())
44 {}
45
~Lperf()46 Lperf::~Lperf()
47 {
48 Impl_ = nullptr;
49 }
50
StartProcessStackSampling(const std::vector<int> & tids,int freq,int milliseconds,bool parseMiniDebugInfo)51 int Lperf::StartProcessStackSampling(const std::vector<int>& tids, int freq,
52 int milliseconds, bool parseMiniDebugInfo)
53 {
54 return Impl_->StartProcessStackSampling(tids, freq, milliseconds, parseMiniDebugInfo);
55 }
56
CollectSampleStackByTid(int tid,std::string & stack)57 int Lperf::CollectSampleStackByTid(int tid, std::string& stack)
58 {
59 return Impl_->CollectSampleStackByTid(tid, stack);
60 }
61
FinishProcessStackSampling()62 int Lperf::FinishProcessStackSampling()
63 {
64 return Impl_->FinishProcessStackSampling();
65 }
66
Impl()67 Lperf::Impl::Impl() : litePerf_(std::make_shared<OHOS::HiviewDFX::LitePerf>())
68 {}
69
~Impl()70 Lperf::Impl::~Impl()
71 {
72 litePerf_ = nullptr;
73 }
74
StartProcessStackSampling(const std::vector<int> & tids,int freq,int milliseconds,bool parseMiniDebugInfo)75 int Lperf::Impl::StartProcessStackSampling(const std::vector<int>& tids, int freq,
76 int milliseconds, bool parseMiniDebugInfo)
77 {
78 return litePerf_->StartProcessStackSampling(tids, freq, milliseconds, parseMiniDebugInfo);
79 }
80
CollectSampleStackByTid(int tid,std::string & stack)81 int Lperf::Impl::CollectSampleStackByTid(int tid, std::string& stack)
82 {
83 return litePerf_->CollectSampleStackByTid(tid, stack);
84 }
85
FinishProcessStackSampling()86 int Lperf::Impl::FinishProcessStackSampling()
87 {
88 return litePerf_->FinishProcessStackSampling();
89 }
90 } // namespace HiPerfLocal
91 } // namespace HiPerf
92 } // namespace Developtools
93 } // namespace OHOS