• 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 "app_caller_event.h"
24 #include "audit_log_parser.h"
25 #include "client/memory_collector_client.h"
26 #include "client/trace_collector_client.h"
27 #include "utility/cpu_collector.h"
28 #include "utility/graphic_memory_collector.h"
29 #include "utility/trace_collector.h"
30 
31 namespace OHOS {
32 namespace HiviewDFX {
33 class HiviewService {
34 public:
35     HiviewService();
~HiviewService()36     ~HiviewService(){};
37 
38     void StartService();
39     // Dump interface
40     void DumpRequestDispatcher(int fd, const std::vector<std::string>& cmds);
41 
42     int32_t Copy(const std::string& srcFilePath, const std::string& destFilePath);
43     int32_t Move(const std::string& srcFilePath, const std::string& destFilePath);
44     int32_t Remove(const std::string& filePath);
45 
46     // Trace interfaces
47     CollectResult<int32_t> OpenSnapshotTrace(const std::vector<std::string>& tagGroups);
48     CollectResult<std::vector<std::string>> DumpSnapshotTrace(UCollect::TraceClient client);
49     CollectResult<int32_t> OpenRecordingTrace(const std::string& tags);
50     CollectResult<int32_t> RecordingTraceOn();
51     CollectResult<std::vector<std::string>> RecordingTraceOff();
52     CollectResult<int32_t> CloseTrace();
53     CollectResult<int32_t> CaptureDurationTrace(UCollectClient::AppCaller &appCaller);
54     CollectResult<double> GetSysCpuUsage();
55     CollectResult<int32_t> SetAppResourceLimit(UCollectClient::MemoryCaller& memoryCaller);
56     CollectResult<int32_t> GetGraphicUsage(int32_t pid);
57     CollectResult<int32_t> SetSplitMemoryValue(std::vector<UCollectClient::MemoryCaller>& memList);
58 
59 private:
60     void DumpDetailedInfo(int fd);
61     void DumpPluginInfo(int fd, const std::vector<std::string>& cmds) const;
62     void DumpLoadedPluginInfo(int fd) const;
63     void DumpPluginUsageInfo(int fd);
64     void DumpPluginUsageInfo(int fd, const std::string& pluginName) const;
65 
66     void DumpThreadUsageInfo(int fd) const;
67     void DumpThreadUsageInfo(int fd, const std::string& threadName) const;
68 
69     void DumpPipelineUsageInfo(int fd) const;
70     void DumpPipelineUsageInfo(int fd, const std::string& pipelineName) const;
71 
72     bool InnerHasCallAppTrace(std::shared_ptr<AppCallerEvent> appCallerEvent);
73     CollectResult<int32_t> InnerResponseStartAppTrace(UCollectClient::AppCaller &appCaller);
74     CollectResult<int32_t> InnerResponseDumpAppTrace(UCollectClient::AppCaller &appCaller);
75 
76     int CopyFile(const std::string& srcFilePath, const std::string& destFilePath);
77 
78     void PrintUsage(int fd) const;
79 
80 private:
81     std::unique_ptr<AuditLogParser> parser_ = nullptr;
82     std::shared_ptr<UCollectUtil::CpuCollector> cpuCollector_;
83     std::shared_ptr<UCollectUtil::GraphicMemoryCollector> graphicMemoryCollector_;
84 };
85 } // namespace HiviewDFX
86 } // namespace OHOS
87 #endif // HIVIEW_PLATFORM_MANAGEMENT_INFO_EXPORT_SERVICE_H
88