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