1 /* 2 * Copyright (c) Huawei Technologies Co., Ltd. 2024. All rights reserved. 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 17 #ifndef NETWORK_PROFILER_H 18 #define NETWORK_PROFILER_H 19 20 #include <atomic> 21 #include <string> 22 #include <mutex> 23 #include <thread> 24 #include "param/sys_param.h" 25 #include "network_profiler_common.h" 26 #include "network_profiler_socker_client.h" 27 28 namespace OHOS::Developtools::Profiler { 29 class EXPORT_API NetworkProfiler { 30 public: 31 static NetworkProfiler* GetInstance(); 32 virtual ~NetworkProfiler(); 33 34 bool IsProfilerEnable(); 35 void NetworkProfiling(const uint8_t type, const char* data, size_t dataSize); 36 SetClockId(int32_t type)37 void SetClockId(int32_t type) 38 { 39 clockType_ = type; 40 } 41 SetEnableFlag(bool flag)42 void SetEnableFlag(bool flag) 43 { 44 enable_ = flag; 45 } 46 47 private: 48 NetworkProfiler(); 49 void CheckNetworkProfilerParam(); 50 void Enable(); 51 void Disable(); 52 void NetworkProfilerSendData(const void* src, size_t size, const char* payload = nullptr, size_t payloadSize = 0); 53 void GetThreadName(const void* src); 54 55 private: 56 static NetworkProfiler* instance_; 57 std::atomic_bool enable_{false}; 58 std::string processName_; 59 int32_t pid_{0}; 60 std::shared_ptr<NetworkProfilerSocketClient> socketClent_{nullptr}; 61 int32_t clockType_{0}; 62 }; 63 } // OHOS::Developtools::Profiler 64 #define NetworkProfilerIns OHOS::Developtools::Profiler::NetworkProfiler::GetInstance() 65 66 #endif // NETWORK_PROFILER_H