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_TREES_H_ 18 #define SRC_TRACE_REDACTION_REDACT_PROCESS_TREES_H_ 19 20 #include "perfetto/base/status.h" 21 #include "perfetto/protozero/field.h" 22 #include "src/trace_redaction/redact_sched_events.h" 23 #include "src/trace_redaction/trace_redaction_framework.h" 24 25 #include "protos/perfetto/trace/ps/process_tree.pbzero.h" 26 27 namespace perfetto::trace_redaction { 28 29 class ProcessTreeModifier { 30 public: 31 virtual ~ProcessTreeModifier(); 32 virtual base::Status Modify(const Context& context, 33 protos::pbzero::ProcessTree* message) const = 0; 34 }; 35 36 class ProcessTreeDoNothing : public ProcessTreeModifier { 37 public: 38 base::Status Modify(const Context& context, 39 protos::pbzero::ProcessTree* message) const override; 40 }; 41 42 class ProcessTreeCreateSynthThreads : public ProcessTreeModifier { 43 public: 44 base::Status Modify(const Context& context, 45 protos::pbzero::ProcessTree* message) const override; 46 }; 47 48 // Removes threads and processes from the process tree based on whether or not 49 // they are connected to the target package. 50 class RedactProcessTrees : public TransformPrimitive { 51 public: 52 base::Status Transform(const Context& context, 53 std::string* packet) const override; 54 55 template <class Filter> emplace_filter()56 void emplace_filter() { 57 filter_ = std::make_unique<Filter>(); 58 } 59 60 template <class Builder> emplace_modifier()61 void emplace_modifier() { 62 modifier_ = std::make_unique<Builder>(); 63 } 64 65 private: 66 base::Status OnProcessTree(const Context& context, 67 uint64_t ts, 68 protozero::ConstBytes bytes, 69 protos::pbzero::ProcessTree* message) const; 70 71 base::Status OnProcess(const Context& context, 72 uint64_t ts, 73 protozero::Field field, 74 protos::pbzero::ProcessTree* message) const; 75 76 base::Status OnThread(const Context& context, 77 uint64_t ts, 78 protozero::Field field, 79 protos::pbzero::ProcessTree* message) const; 80 81 base::Status AppendSynthThreads(const Context& context, 82 protos::pbzero::ProcessTree* message) const; 83 84 std::unique_ptr<PidFilter> filter_; 85 std::unique_ptr<ProcessTreeModifier> modifier_; 86 }; 87 88 } // namespace perfetto::trace_redaction 89 90 #endif // SRC_TRACE_REDACTION_REDACT_PROCESS_TREES_H_ 91