xref: /aosp_15_r20/external/perfetto/src/trace_redaction/collect_frame_cookies.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 #ifndef SRC_TRACE_REDACTION_COLLECT_FRAME_COOKIES_H_
18 #define SRC_TRACE_REDACTION_COLLECT_FRAME_COOKIES_H_
19 
20 #include "perfetto/protozero/field.h"
21 #include "src/trace_redaction/trace_redaction_framework.h"
22 
23 #include "protos/perfetto/trace/trace_packet.pbzero.h"
24 
25 namespace perfetto::trace_redaction {
26 
27 // Populates Context::global_frame_cookies using FrameTimelineEvent messages.
28 class CollectFrameCookies : public CollectPrimitive {
29  public:
30   base::Status Begin(Context* context) const override;
31 
32   base::Status Collect(const protos::pbzero::TracePacket::Decoder& packet,
33                        Context* context) const override;
34 
35  private:
36   void OnTimelineEvent(const protos::pbzero::TracePacket::Decoder& packet,
37                        protozero::ConstBytes bytes,
38                        Context* context) const;
39 };
40 
41 // Moves cookies from Context::global_frame_cookies to
42 // Context::package_frame_cookies using Cookies::timeline and
43 // Cookies::package_uid.
44 class ReduceFrameCookies : public BuildPrimitive {
45  public:
46   base::Status Build(Context* context) const override;
47 };
48 
49 class FilterFrameEvents : public TransformPrimitive {
50  public:
51   base::Status Transform(const Context& context,
52                          std::string* packet) const override;
53 
54  private:
55   bool KeepField(const Context& context, const protozero::Field& field) const;
56 };
57 
58 }  // namespace perfetto::trace_redaction
59 
60 #endif  // SRC_TRACE_REDACTION_COLLECT_FRAME_COOKIES_H_
61