• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 #ifndef HIVIEW_PLATFORM_MANAGEMENT_INFO_EXPORT_SERVICE_H
16 #define HIVIEW_PLATFORM_MANAGEMENT_INFO_EXPORT_SERVICE_H
17 
18 #include <cstdint>
19 #include <memory>
20 #include <string>
21 #include <vector>
22 
23 #include "audit_log_parser.h"
24 #include "utility/trace_collector.h"
25 #include "utility/cpu_collector.h"
26 #include "client/trace_collector.h"
27 #include "client/memory_collector.h"
28 
29 namespace OHOS {
30 namespace HiviewDFX {
31 class HiviewService {
32 public:
33     HiviewService();
~HiviewService()34     ~HiviewService(){};
35 
36     void StartService();
37     // Dump interface
38     void DumpRequestDispatcher(int fd, const std::vector<std::string>& cmds);
39 
40     int32_t Copy(const std::string& srcFilePath, const std::string& destFilePath);
41     int32_t Move(const std::string& srcFilePath, const std::string& destFilePath);
42     int32_t Remove(const std::string& filePath);
43 
44     // Trace interfaces
45     CollectResult<int32_t> OpenSnapshotTrace(const std::vector<std::string>& tagGroups);
46     CollectResult<std::vector<std::string>> DumpSnapshotTrace(UCollect::TraceCaller caller);
47     CollectResult<int32_t> OpenRecordingTrace(const std::string& tags);
48     CollectResult<int32_t> RecordingTraceOn();
49     CollectResult<std::vector<std::string>> RecordingTraceOff();
50     CollectResult<int32_t> CloseTrace();
51     CollectResult<int32_t> RecoverTrace();
52     CollectResult<int32_t> CaptureDurationTrace(UCollectClient::AppCaller &appCaller);
53     CollectResult<double> GetSysCpuUsage();
54     CollectResult<int32_t> SetAppResourceLimit(UCollectClient::MemoryCaller& memoryCaller);
55 private:
56     void DumpDetailedInfo(int fd);
57     void DumpPluginInfo(int fd, const std::vector<std::string>& cmds) const;
58     void DumpLoadedPluginInfo(int fd) const;
59     void DumpPluginUsageInfo(int fd);
60     void DumpPluginUsageInfo(int fd, const std::string& pluginName) const;
61 
62     void DumpThreadUsageInfo(int fd) const;
63     void DumpThreadUsageInfo(int fd, const std::string& threadName) const;
64 
65     void DumpPipelineUsageInfo(int fd) const;
66     void DumpPipelineUsageInfo(int fd, const std::string& pipelineName) const;
67 
68     int CopyFile(const std::string& srcFilePath, const std::string& destFilePath);
69 
70     void PrintUsage(int fd) const;
71 
72 private:
73     std::unique_ptr<AuditLogParser> parser_ = nullptr;
74     std::shared_ptr<UCollectUtil::TraceCollector> traceCollector_;
75     std::shared_ptr<UCollectUtil::CpuCollector> cpuCollector_;
76 };
77 } // namespace HiviewDFX
78 } // namespace OHOS
79 #endif // HIVIEW_PLATFORM_MANAGEMENT_INFO_EXPORT_SERVICE_H
80