1 /* 2 * Copyright (c) 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 16 #ifndef RS_GRAPHIC_TEST_PROFILER_THREAD_H 17 #define RS_GRAPHIC_TEST_PROFILER_THREAD_H 18 19 #include <iostream> 20 #include <thread> 21 #include <mutex> 22 #include <queue> 23 #include <condition_variable> 24 #include <cstring> 25 #include <sys/socket.h> 26 #include <sys/un.h> 27 #include <unistd.h> 28 29 namespace OHOS { 30 namespace Rosen { 31 class RSGraphicTestProfilerThread { 32 public: 33 #ifdef RS_PROFILER_ENABLED 34 ~RSGraphicTestProfilerThread(); 35 36 void Start(); 37 void Stop(); 38 void SendCommand(const std::string command, int outTime); 39 private: 40 void MainLoop(); 41 void SendMessage(); 42 void RecieveMessage(); 43 bool RecieveHeader(void* data, size_t& size); 44 bool IsReceiveWaitMessage(const std::string& message); 45 private: 46 int32_t socket_ = -1; 47 std::thread thread_; 48 std::queue<std::string> message_queue_; 49 bool runnig_ = false; 50 bool waitReceive_ = false; 51 std::mutex queue_mutex_; 52 std::mutex wait_mutex_; 53 std::condition_variable cv_; 54 #else 55 void Start() {} 56 void Stop() {} 57 void SendCommand(const std::string command, int outTime) {} 58 #endif 59 }; 60 61 } // namespace Rosen 62 } // namespace OHOS 63 #endif