1 /**
2  * Copyright (c) 2021-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 PANDA_RUNTIME_DPROFILER_DPROFILER_H_
16 #define PANDA_RUNTIME_DPROFILER_DPROFILER_H_
17 
18 #include <memory>
19 #include <string>
20 #include <unordered_set>
21 
22 #include "dprof/profiling_data.h"
23 #include "libpandabase/macros.h"
24 #include "runtime/include/mem/panda_containers.h"
25 #include "runtime/include/mem/panda_smart_pointers.h"
26 #include "runtime/include/mem/panda_string.h"
27 
28 namespace ark {
29 
30 class Class;
31 class Method;
32 class Runtime;
33 class RuntimeListener;
34 
35 /// @brief The DProfiler class integrates the distributed profiling in the Panda.
36 class DProfiler final {
37 public:
38 #ifdef PANDA_TARGET_UNIX
39     DProfiler(std::string_view appName, Runtime *runtime);
40 #else
41     DProfiler([[maybe_unused]] std::string_view app_name, [[maybe_unused]] Runtime *runtime)
42     {
43         // Unsupported on windows platform
44         UNREACHABLE();
45     }
46 #endif  // PANDA_TARGET_UNIX
47     ~DProfiler() = default;
48 
49     /**
50      * @brief Add a ark::Class for the dump.
51      * @param klass
52      */
53     void AddClass(const Class *klass);
54 
55     /// @brief Send a dump of distributed profiling info
56     void Dump();
57 
58 private:
59     Runtime *runtime_;
60     PandaUniquePtr<dprof::ProfilingData> profilingData_;
61     PandaUniquePtr<RuntimeListener> listener_;
62     PandaUnorderedSet<const Method *> hotMethods_;
63 
64     NO_COPY_SEMANTIC(DProfiler);
65     NO_MOVE_SEMANTIC(DProfiler);
66 };
67 
68 }  // namespace ark
69 
70 #endif  // PANDA_RUNTIME_DPROFILER_DPROFILER_H_
71