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 30 class EXPORT_API NetworkProfiler { 31 public: 32 struct CachedData { 33 uint8_t cachedType; 34 const char* cachedData; 35 size_t cachedDataSize; 36 }; 37 static void Disable(); 38 static void ServiceCloseCallback(); 39 static NetworkProfiler* GetInstance(); 40 virtual ~NetworkProfiler(); 41 42 bool IsProfilerEnable(); 43 void NetworkProfiling(const uint8_t type, const char* data, size_t dataSize); 44 SetClockId(int32_t type)45 void SetClockId(int32_t type) 46 { 47 clockType_ = type; 48 } 49 void SetWaitingFlag(bool flag); 50 void SetEnableFlag(bool flag); 51 void SendCachedData(); 52 53 private: 54 NetworkProfiler(); 55 void CheckNetworkProfilerParam(); 56 void Enable(); 57 void NetworkProfilerSendData(const void* src, size_t size, const char* payload = nullptr, size_t payloadSize = 0); 58 void GetThreadName(const char* src); 59 60 private: 61 static NetworkProfiler* instance_; 62 int32_t clockType_{0}; 63 }; 64 } // OHOS::Developtools::Profiler 65 #define NetworkProfilerIns OHOS::Developtools::Profiler::NetworkProfiler::GetInstance() 66 67 #endif // NETWORK_PROFILER_H