• 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 #ifndef FFRT_PROFILER_SOCKET_CLIENT
17 #define FFRT_PROFILER_SOCKET_CLIENT
18 
19 #include "service_base.h"
20 #include "ffrt_profiler_write.h"
21 #include "unix_socket_client.h"
22 
23 namespace OHOS::Developtools::Profiler {
24 class FfrtProfiler;
25 class FfrtProfilerSocketClient : public ServiceBase {
26 public:
27     FfrtProfilerSocketClient(int pid, FfrtProfiler* profiler, void (*disableHookCallback)());
28     ~FfrtProfilerSocketClient();
29     bool Connect(const std::string addrname);
30     bool ProtocolProc(SocketContext &context, uint32_t pnum, const int8_t *buf, const uint32_t size) override;
GetSmbFd()31     int GetSmbFd()
32     {
33         return smbFd_;
34     }
GetEventFd()35     int GetEventFd()
36     {
37         return eventFd_;
38     }
39     void Flush();
40     bool SendFfrtProfilerData(const void* data, size_t size, const void* payload, size_t payloadSize);
41     void DisableHook();
42     bool PeerIsConnected();
ClientConnectState()43     bool ClientConnectState()
44     {
45         return unixSocketClient_ == nullptr ? false : true;
46     }
47 
48 private:
49     std::shared_ptr<UnixSocketClient> unixSocketClient_{nullptr};
50     int smbFd_{0};
51     int eventFd_{0};
52     int pid_{0};
53     std::shared_ptr<FfrtProfilerWriter> writer_{nullptr};
54     void (*disableHookCallback_)(){nullptr};
55     uint32_t flushInterval_{0};
56     FfrtProfiler* profiler_{nullptr};
57     bool block_{false};
58 };
59 } // namespace OHOS::Developtools::Profiler
60 
61 #endif // FFRT_PROFILER_SOCKET_CLIENT