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