• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_PROCESSOR_IMPORTERS_ETM_FILE_TRACKER_H_
18 #define SRC_TRACE_PROCESSOR_IMPORTERS_ETM_FILE_TRACKER_H_
19 
20 #include <optional>
21 #include <string>
22 #include <vector>
23 
24 #include "perfetto/base/logging.h"
25 #include "perfetto/base/status.h"
26 #include "perfetto/ext/base/flat_hash_map.h"
27 #include "perfetto/trace_processor/trace_blob_view.h"
28 #include "src/trace_processor/storage/trace_storage.h"
29 #include "src/trace_processor/tables/etm_tables_py.h"
30 #include "src/trace_processor/types/destructible.h"
31 #include "src/trace_processor/types/trace_processor_context.h"
32 
33 namespace perfetto::trace_processor::etm {
34 
35 class FileTracker : public Destructible {
36  public:
GetOrCreate(TraceProcessorContext * context)37   static FileTracker* GetOrCreate(TraceProcessorContext* context) {
38     if (!context->file_tracker) {
39       context->file_tracker.reset(new FileTracker(context));
40     }
41     return static_cast<FileTracker*>(context->file_tracker.get());
42   }
43 
44   ~FileTracker() override;
45 
46   base::Status AddFile(const std::string& name, TraceBlobView data);
GetContent(tables::FileTable::Id id)47   TraceBlobView GetContent(tables::FileTable::Id id) const {
48     PERFETTO_DCHECK(id.value < file_content_.size());
49     return file_content_[id.value].copy();
50   }
51 
52  private:
FileTracker(TraceProcessorContext * context)53   explicit FileTracker(TraceProcessorContext* context) : context_(context) {}
54   void IndexFileType(tables::FileTable::Id file_id,
55                      const TraceBlobView& content);
56   TraceProcessorContext* const context_;
57   // Indexed by `tables::FileTable::Id`
58   std::vector<TraceBlobView> file_content_;
59 
60   base::FlatHashMap<StringId, tables::FileTable::Id> files_by_path_;
61 };
62 
63 }  // namespace perfetto::trace_processor::etm
64 
65 #endif  // SRC_TRACE_PROCESSOR_IMPORTERS_ETM_FILE_TRACKER_H_
66