1 /*
2 * Copyright (c) 2022 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 API_CORE_PERF_INTF_PERFORMANCE_TRACE_H
17 #define API_CORE_PERF_INTF_PERFORMANCE_TRACE_H
18
19 #include <cstdint>
20
21 #include <base/containers/refcnt_ptr.h>
22 #include <base/containers/string_view.h>
23 #include <base/namespace.h>
24 #include <base/util/uid.h>
25 #include <core/namespace.h>
26 #include <core/perf/intf_performance_data_manager.h>
27 #include <core/plugin/intf_interface.h>
28 #include <core/plugin/intf_plugin.h>
29
CORE_BEGIN_NAMESPACE()30 CORE_BEGIN_NAMESPACE()
31 /** IPerformanceTrace for events.
32 * Internally synchronized.
33 */
34 class IPerformanceTrace : public IInterface {
35 public:
36 using Ptr = BASE_NS::refcnt_ptr<IPerformanceTrace>;
37 static constexpr auto UID = BASE_NS::Uid { "18fc4522-29a3-4887-a2cf-0e170587edf9" };
38 static constexpr auto TRACY_UID = BASE_NS::Uid { "1FC3A1DE-A352-4A7C-A2E0-C1FE208DABD4" };
39 static constexpr auto ATRACE_UID = BASE_NS::Uid { "392C7588-86D5-47B9-963F-96412E439B9F" };
40 static constexpr auto HITRACE_UID = BASE_NS::Uid { "8d051c51-eaa4-47a1-be68-f923350bb3a8" };
41
42 IPerformanceTrace(const IPerformanceTrace&) = delete;
43 IPerformanceTrace& operator=(const IPerformanceTrace&) = delete;
44
45 /** Indicates start of an event.
46 * @param location Details where the event was triggered.
47 * @param text Optional label for the event.
48 * @return Event tag which is passed to EndEvent.
49 */
50 virtual uintptr_t BeginEvent(const IPerformanceDataManager::Event& location, BASE_NS::string_view text) = 0;
51
52 /** Indicates end of an event.
53 * @param eventTag Event tag from BeginEvent.
54 */
55 virtual void EndEvent(uintptr_t eventTag) = 0;
56 virtual void Message(const char* message, int callstack) = 0;
57 virtual void Message(const char* message, size_t len, int callstack) = 0;
58 virtual void AppInfo(const char* name, size_t len) = 0;
59 virtual void Plot(const char* name, int64_t value) = 0;
60 virtual void FrameBegin(const char* name) = 0;
61 virtual void FrameEnd(const char* name) = 0;
62 virtual void MemAllocNamed(const void* ptr, size_t size, bool secure, const char* name) = 0;
63 virtual void MemFreeNamed(const void* ptr, bool secure, const char* name) = 0;
64 virtual void GlobalFrameChanged() = 0;
65
66 protected:
67 IPerformanceTrace() = default;
68 virtual ~IPerformanceTrace() = default;
69 };
70
GetName(const IPerformanceTrace *)71 inline constexpr BASE_NS::string_view GetName(const IPerformanceTrace*)
72 {
73 return "IPerformanceTrace";
74 }
75
76 /** Information needed from the plugin for managing PerformanceTrace instances. */
77 struct PerformanceTraceTypeInfo : public ITypeInfo {
78 /** TypeInfo UID for performance trace type info. */
79 static constexpr BASE_NS::Uid UID { "fafc3bbb-b176-475c-b9bc-dd77cbd9e317" };
80
81 using CreateLoaderFn = IPerformanceTrace::Ptr (*)(PluginToken);
82 /* Token passed to creation (e.g. plugin specific data). */
83 const PluginToken token;
84 /** Unique ID of the performance trace implementation. */
85 const BASE_NS::Uid uid;
86 /** Pointer to function which is used to create performance trace instances. */
87 const CreateLoaderFn createLoader;
88 };
89 CORE_END_NAMESPACE()
90
91 #endif // API_CORE_PERF_INTF_PERFORMANCE_TRACE_H
92