xref: /aosp_15_r20/external/perfetto/src/trace_redaction/modify.h (revision 6dbdd20afdafa5e3ca9b8809fa73465d530080dc)
1 /*
2  * Copyright (C) 2024 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 #include <cstdint>
18 
19 #include "protos/perfetto/trace/ftrace/ftrace_event_bundle.pbzero.h"
20 #include "src/trace_redaction/trace_redaction_framework.h"
21 
22 #ifndef SRC_TRACE_REDACTION_MODIFY_H_
23 #define SRC_TRACE_REDACTION_MODIFY_H_
24 
25 namespace perfetto::trace_redaction {
26 
27 class PidCommModifier {
28  public:
29   virtual ~PidCommModifier();
30   virtual void Modify(const Context& context,
31                       uint64_t ts,
32                       int32_t cpu,
33                       int32_t* pid,
34                       std::string* comm) const = 0;
35 };
36 
37 class FtraceEventModifier {
38  public:
39   virtual ~FtraceEventModifier();
40   virtual void Modify(const Context& context,
41                       const protos::pbzero::FtraceEventBundle::Decoder& bundle,
42                       protozero::Field event,
43                       protos::pbzero::FtraceEventBundle* message) const = 0;
44 };
45 
46 class ClearComms : public PidCommModifier {
47  public:
48   void Modify(const Context& context,
49               uint64_t ts,
50               int32_t cpu,
51               int32_t* pid,
52               std::string* comm) const override;
53 };
54 
55 // Implementation of every type of modifier, allow any modifier to be assigned
56 // "Do Nothing" as if it was nullptr.
57 class DoNothing : public PidCommModifier, public FtraceEventModifier {
58  public:
59   void Modify(const Context& context,
60               uint64_t ts,
61               int32_t cpu,
62               int32_t* pid,
63               std::string* comm) const override;
64 
65   void Modify(const Context& context,
66               const protos::pbzero::FtraceEventBundle::Decoder& bundle,
67               protozero::Field event,
68               protos::pbzero::FtraceEventBundle* message) const override;
69 };
70 
71 }  // namespace perfetto::trace_redaction
72 
73 #endif  // SRC_TRACE_REDACTION_MODIFY_H_
74