xref: /aosp_15_r20/external/perfetto/src/trace_redaction/modify.cc (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 "src/trace_redaction/modify.h"
18 #include "src/trace_redaction/proto_util.h"
19 
20 namespace perfetto::trace_redaction {
21 
22 PidCommModifier::~PidCommModifier() = default;
23 
24 FtraceEventModifier::~FtraceEventModifier() = default;
25 
Modify(const Context & context,uint64_t ts,int32_t,int32_t * pid,std::string * comm) const26 void ClearComms::Modify(const Context& context,
27                         uint64_t ts,
28                         int32_t,
29                         int32_t* pid,
30                         std::string* comm) const {
31   PERFETTO_DCHECK(context.timeline);
32   PERFETTO_DCHECK(context.package_uid.has_value());
33   PERFETTO_DCHECK(pid);
34   PERFETTO_DCHECK(comm);
35 
36   if (!context.timeline->PidConnectsToUid(ts, *pid, *context.package_uid)) {
37     comm->clear();
38   }
39 }
40 
Modify(const Context &,uint64_t,int32_t,int32_t *,std::string *) const41 void DoNothing::Modify(const Context&,
42                        uint64_t,
43                        int32_t,
44                        int32_t*,
45                        std::string*) const {}
46 
47 // Because FtraceEventModifier is responsible for modifying and writing
48 // (compared to PidCommModifier), it needs to pass the value through to the
49 // message.
Modify(const Context &,const protos::pbzero::FtraceEventBundle::Decoder &,protozero::Field event,protos::pbzero::FtraceEventBundle * parent_message) const50 void DoNothing::Modify(
51     const Context&,
52     const protos::pbzero::FtraceEventBundle::Decoder&,
53     protozero::Field event,
54     protos::pbzero::FtraceEventBundle* parent_message) const {
55   proto_util::AppendField(event, parent_message);
56 }
57 
58 }  // namespace perfetto::trace_redaction
59