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_REDACT_PROCESS_EVENTS_H_ 18 #define SRC_TRACE_REDACTION_REDACT_PROCESS_EVENTS_H_ 19 20 #include <memory> 21 22 #include "src/trace_redaction/redact_sched_events.h" 23 #include "src/trace_redaction/trace_redaction_framework.h" 24 25 #include "protos/perfetto/trace/ftrace/ftrace_event_bundle.pbzero.h" 26 27 namespace perfetto::trace_redaction { 28 29 // Goes through a trace packet and filters: 30 // 31 // - task_rename 32 // - task_newtask 33 // - sched_process_free 34 // - print 35 // 36 // Goes through a trace packet and modifies pid and comm: 37 // 38 // - task_newtask 39 // - sched_process_free 40 // - task_rename 41 // 42 // 'print' does not support modification. 43 // 44 // These operations are separate from the scheduling events in an effort to make 45 // the code easier to understand, however they use the same filter and modifier 46 // types and should have the same values when used together. 47 class RedactProcessEvents : public TransformPrimitive { 48 public: 49 base::Status Transform(const Context& context, 50 std::string* packet) const override; 51 52 template <class Modifier> emplace_modifier()53 void emplace_modifier() { 54 modifier_ = std::make_unique<Modifier>(); 55 } 56 57 template <class Filter> emplace_filter()58 void emplace_filter() { 59 filter_ = std::make_unique<Filter>(); 60 } 61 62 private: 63 base::Status OnFtraceEvents(const Context& context, 64 protozero::ConstBytes bytes, 65 protos::pbzero::FtraceEventBundle* message) const; 66 67 base::Status OnFtraceEvent(const Context& context, 68 int32_t cpu, 69 protozero::ConstBytes bytes, 70 std::string* shared_comm, 71 protos::pbzero::FtraceEvent* message) const; 72 73 base::Status OnProcessFree(const Context& context, 74 uint64_t ts, 75 int32_t cpu, 76 protozero::ConstBytes bytes, 77 std::string* shared_comm, 78 protos::pbzero::FtraceEvent* parent_message) const; 79 80 base::Status OnNewTask(const Context& context, 81 uint64_t ts, 82 int32_t cpu, 83 protozero::ConstBytes bytes, 84 std::string* shared_comm, 85 protos::pbzero::FtraceEvent* parent_message) const; 86 87 base::Status OnProcessRename( 88 const Context& context, 89 uint64_t ts, 90 int32_t cpu, 91 protozero::ConstBytes bytes, 92 std::string* shared_comm, 93 protos::pbzero::FtraceEvent* parent_message) const; 94 95 // Unlike the other On* functions, this one required the event's byte buffer 96 // because it needs the pid from it. 97 base::Status OnPrint(const Context& context, 98 uint64_t ts, 99 protozero::ConstBytes event_bytes, 100 protos::pbzero::FtraceEvent* parent_message) const; 101 102 base::Status OnSuspendResume( 103 const Context& context, 104 uint64_t ts, 105 protozero::ConstBytes event_bytes, 106 protos::pbzero::FtraceEvent* parent_message) const; 107 108 base::Status OnSchedBlockedReason( 109 const Context& context, 110 uint64_t ts, 111 protozero::ConstBytes event_bytes, 112 protos::pbzero::FtraceEvent* parent_message) const; 113 114 std::unique_ptr<PidCommModifier> modifier_; 115 std::unique_ptr<PidFilter> filter_; 116 }; 117 118 } // namespace perfetto::trace_redaction 119 120 #endif // SRC_TRACE_REDACTION_REDACT_PROCESS_EVENTS_H_ 121