xref: /aosp_15_r20/external/perfetto/src/trace_processor/importers/ftrace/pkvm_hyp_cpu_tracker.h (revision 6dbdd20afdafa5e3ca9b8809fa73465d530080dc)
1 /*
2  * Copyright (C) 2023 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef SRC_TRACE_PROCESSOR_IMPORTERS_FTRACE_PKVM_HYP_CPU_TRACKER_H_
18 #define SRC_TRACE_PROCESSOR_IMPORTERS_FTRACE_PKVM_HYP_CPU_TRACKER_H_
19 
20 #include "perfetto/ext/base/string_view.h"
21 #include "perfetto/protozero/field.h"
22 #include "src/trace_processor/storage/trace_storage.h"
23 
24 namespace perfetto {
25 namespace trace_processor {
26 
27 class TraceProcessorContext;
28 
29 // Handles parsing and showing hypervisor events in the UI.
30 // TODO(b/249050813): link to the documentation once it's available in AOSP.
31 class PkvmHypervisorCpuTracker {
32  public:
33   explicit PkvmHypervisorCpuTracker(TraceProcessorContext*);
34 
35   static bool IsPkvmHypervisorEvent(uint32_t /*event_id*/);
36 
37   void ParseHypEvent(uint32_t cput,
38                      int64_t timestamp,
39                      uint32_t event_id,
40                      protozero::ConstBytes blob);
41 
42  private:
43   void ParseHypEnter(uint32_t cpu, int64_t timestamp);
44   void ParseHypExit(uint32_t cpu, int64_t timestamp);
45   void ParseHostHcall(uint32_t cpu, protozero::ConstBytes blob);
46   void ParseHostSmc(uint32_t cpu, protozero::ConstBytes blob);
47   void ParseHostMemAbort(uint32_t cpu, protozero::ConstBytes blob);
48 
49   TraceProcessorContext* context_;
50   const StringId category_;
51   const StringId slice_name_;
52   const StringId hyp_enter_reason_;
53 };
54 
55 }  // namespace trace_processor
56 }  // namespace perfetto
57 
58 #endif  // SRC_TRACE_PROCESSOR_IMPORTERS_FTRACE_PKVM_HYP_CPU_TRACKER_H_
59