1 /* 2 * Copyright (c) 2023-2024 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 #ifndef INTERFACES_INNER_API_UNIFIED_COLLECTION_CLIENT_TRACE_COLLECTOR_H 16 #define INTERFACES_INNER_API_UNIFIED_COLLECTION_CLIENT_TRACE_COLLECTOR_H 17 #include <cinttypes> 18 #include <memory> 19 #include <string> 20 #include <vector> 21 22 #include "collect_result.h" 23 #include "trace_caller.h" 24 25 namespace OHOS { 26 namespace HiviewDFX { 27 namespace UCollectClient { 28 constexpr int32_t ACTION_ID_START_TRACE = 1; 29 constexpr int32_t ACTION_ID_DUMP_TRACE = 2; 30 31 struct AppCaller { 32 int32_t actionId; // 1: start trace; 2: dump trace 33 std::string bundleName; // app bundle name 34 std::string bundleVersion; // app bundle version 35 std::string threadName; // app thread name 36 int32_t foreground; // app foreground 37 int32_t uid; // app user id 38 int32_t pid; // app process id 39 int64_t happenTime; // jank happend time, millisecond unit 40 int64_t beginTime; // message handle begin time, millisecond unit 41 int64_t endTime; // message handle end time, millisecond unit 42 bool isBusinessJank = false; // is business jank or not, control output file name 43 }; 44 45 class TraceCollector { 46 public: 47 TraceCollector() = default; 48 virtual ~TraceCollector() = default; 49 50 public: 51 virtual CollectResult<int32_t> OpenSnapshot(const std::vector<std::string>& tagGroups) = 0; 52 virtual CollectResult<std::vector<std::string>> DumpSnapshot( 53 UCollect::TraceCaller caller = UCollect::TraceCaller::OTHER) = 0; 54 virtual CollectResult<int32_t> OpenRecording(const std::string& tags) = 0; 55 virtual CollectResult<int32_t> RecordingOn() = 0; 56 virtual CollectResult<std::vector<std::string>> RecordingOff() = 0; 57 virtual CollectResult<int32_t> Close() = 0; 58 virtual CollectResult<int32_t> Recover() = 0; 59 // use for hap main looper 60 virtual CollectResult<int32_t> CaptureDurationTrace(AppCaller &appCaller) = 0; 61 62 static std::shared_ptr<TraceCollector> Create(); 63 }; // TraceCollector 64 } // UCollectClient 65 } // HiviewDFX 66 } // OHOS 67 #endif // INTERFACES_INNER_API_UNIFIED_COLLECTION_CLIENT_TRACE_COLLECTOR_H 68