xref: /aosp_15_r20/external/perfetto/src/trace_processor/importers/ftrace/rss_stat_tracker.h (revision 6dbdd20afdafa5e3ca9b8809fa73465d530080dc)
1 /*
2  * Copyright (C) 2019 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_PROCESSOR_IMPORTERS_FTRACE_RSS_STAT_TRACKER_H_
18 #define SRC_TRACE_PROCESSOR_IMPORTERS_FTRACE_RSS_STAT_TRACKER_H_
19 
20 #include <cstdint>
21 #include <optional>
22 
23 #include "perfetto/ext/base/flat_hash_map.h"
24 #include "perfetto/protozero/field.h"
25 #include "src/trace_processor/storage/trace_storage.h"
26 
27 namespace perfetto::trace_processor {
28 
29 class TraceProcessorContext;
30 
31 class RssStatTracker {
32  public:
33   using ConstBytes = protozero::ConstBytes;
34 
35   explicit RssStatTracker(TraceProcessorContext*);
36 
37   void ParseRssStat(int64_t ts,
38                     uint32_t field_id,
39                     uint32_t pid,
40                     ConstBytes blob);
41   void ParseRssStat(int64_t ts,
42                     uint32_t pid,
43                     int64_t size,
44                     uint32_t member,
45                     std::optional<bool> curr,
46                     std::optional<int64_t> mm_id);
47 
48  private:
49   std::optional<UniqueTid> FindUtidForMmId(int64_t mm_id,
50                                            bool is_curr,
51                                            uint32_t pid);
52 
53   base::FlatHashMap<int64_t, UniqueTid> mm_id_to_utid_;
54   TraceProcessorContext* const context_;
55 };
56 
57 }  // namespace perfetto::trace_processor
58 
59 #endif  // SRC_TRACE_PROCESSOR_IMPORTERS_FTRACE_RSS_STAT_TRACKER_H_
60