• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 ECMASCRIPT_TOOLING_AGENT_TRACING_IMPL_H
17 #define ECMASCRIPT_TOOLING_AGENT_TRACING_IMPL_H
18 
19 #include "base/pt_params.h"
20 #include "base/pt_returns.h"
21 #include "dispatcher.h"
22 
23 #include "ecmascript/dfx/cpu_profiler/samples_record.h"
24 #include "libpandabase/macros.h"
25 
26 namespace panda::ecmascript::tooling {
27 class TracingImpl final {
28 public:
TracingImpl(const EcmaVM * vm,ProtocolChannel * channel)29     explicit TracingImpl(const EcmaVM *vm, ProtocolChannel *channel) : vm_(vm), frontend_(channel) {}
30     ~TracingImpl() = default;
31 
32     DispatchResponse End();
33     DispatchResponse GetCategories(std::vector<std::string> categories);
34     DispatchResponse RecordClockSyncMarker(std::string syncId);
35     DispatchResponse RequestMemoryDump(std::unique_ptr<RequestMemoryDumpParams> params,
36                                        std::string dumpGuid,  bool success);
37     DispatchResponse Start(std::unique_ptr<StartParams> params);
38 
39     class DispatcherImpl final : public DispatcherBase {
40     public:
DispatcherImpl(ProtocolChannel * channel,std::unique_ptr<TracingImpl> tracing)41         DispatcherImpl(ProtocolChannel *channel, std::unique_ptr<TracingImpl> tracing)
42             : DispatcherBase(channel), tracing_(std::move(tracing)) {}
43         ~DispatcherImpl() override = default;
44         void Dispatch(const DispatchRequest &request) override;
45         void End(const DispatchRequest &request);
46         void GetCategories(const DispatchRequest &request);
47         void RecordClockSyncMarker(const DispatchRequest &request);
48         void RequestMemoryDump(const DispatchRequest &request);
49         void Start(const DispatchRequest &request);
50 
51     private:
52         NO_COPY_SEMANTIC(DispatcherImpl);
53         NO_MOVE_SEMANTIC(DispatcherImpl);
54 
55         using AgentHandler = void (TracingImpl::DispatcherImpl::*)(const DispatchRequest &request);
56         std::unique_ptr<TracingImpl> tracing_ {};
57     };
58 
59     class Frontend {
60     public:
Frontend(ProtocolChannel * channel)61         explicit Frontend(ProtocolChannel *channel) : channel_(channel) {}
62         ~Frontend() = default;
63 
64         void BufferUsage();
65         void DataCollected();
66         void TracingComplete();
67 
68     private:
69         bool AllowNotify() const;
70         ProtocolChannel *channel_ {nullptr};
71     };
72 
73 private:
74     NO_COPY_SEMANTIC(TracingImpl);
75     NO_MOVE_SEMANTIC(TracingImpl);
76 
77     [[maybe_unused]] const EcmaVM *vm_ {nullptr};
78     [[maybe_unused]] Frontend frontend_;
79 };
80 }  // namespace panda::ecmascript::tooling
81 #endif