1 /* 2 * Copyright (c) 2021 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 ECMASCRIPT_CPU_PROCESSOR_H 17 #define ECMASCRIPT_CPU_PROCESSOR_H 18 #include <pthread.h> 19 20 #include "ecmascript/ecma_vm.h" 21 #include "ecmascript/cpu_profiler/profile_generator.h" 22 #include "ecmascript/interpreter/frame_handler.h" 23 #include "ecmascript/platform/task.h" 24 25 namespace panda::ecmascript { 26 class ProfileProcessor : public Task { 27 public: 28 static uint64_t GetMicrosecondsTimeStamp(); 29 static JSThread *GetJSThread(); 30 static void SetIsStart(bool isStart); 31 32 explicit ProfileProcessor(ProfileGenerator *generator, const EcmaVM *vm, int interval); 33 virtual ~ProfileProcessor(); 34 35 bool Run(uint32_t threadIndex) override; 36 void WriteSampleDataToFile(); 37 38 NO_COPY_SEMANTIC(ProfileProcessor); 39 NO_MOVE_SEMANTIC(ProfileProcessor); 40 private: 41 static JSThread *thread_; 42 static bool isStart_; 43 ProfileGenerator *generator_ = nullptr; 44 int interval_ = 0; 45 pthread_t pid_ = 0; 46 }; 47 } // namespace panda::ecmascript 48 #endif // ECMASCRIPT_CPU_PROCESSOR_H