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_COMMON_H 17 #define FFRT_PROFILER_COMMON_H 18 19 #include <string.h> 20 #include <fstream> 21 22 namespace OHOS::Developtools::Profiler { 23 const std::string PARAM_KAY = "hiviewdfx.hiprofiler.ffrtprofiler.target"; 24 static constexpr uint8_t MAX_COMM_LEN = 16; 25 static constexpr int32_t TRACE_DATA = -1; 26 static constexpr int32_t ALIGNAS_NUM = 8; 27 28 void SplitString(const std::string& str, const std::string &sep, std::vector<std::string>& ret); 29 std::string GetProcessName(int32_t pid); 30 31 struct FfrtConfig { 32 int32_t shmSize = 0; 33 int32_t flushCount = 0; 34 int32_t clock = 0; 35 bool block = 0; 36 }; 37 38 enum class EventType : int32_t { 39 MIN_TYPE = 0, 40 INVALID = 0, 41 }; 42 43 struct alignas(ALIGNAS_NUM) FfrtResultBase { 44 int32_t type = static_cast<int32_t>(EventType::INVALID); 45 int32_t tid = 0; 46 struct timespec ts; 47 char threadName[MAX_COMM_LEN] = {0}; 48 }; 49 50 struct alignas(ALIGNAS_NUM) FfrtTraceEvent : public FfrtResultBase { 51 uint64_t cookie = 0; 52 uint8_t traceType; 53 uint8_t cpu = 0; 54 }; 55 } 56 57 #endif // FFRT_PROFILER_COMMON_H