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 #include "src/trace_processor/importers/archive/archive_entry.h"
18
19 #include <tuple>
20
21 namespace perfetto::trace_processor {
22
operator <(const ArchiveEntry & rhs) const23 bool ArchiveEntry::operator<(const ArchiveEntry& rhs) const {
24 auto trace_priority = [](TraceType type) -> int {
25 if (type == kSymbolsTraceType)
26 // Traces with symbols should be the last ones to be read.
27 // TODO(carlscab): Proto traces with just ModuleSymbols packets should be
28 // an exception. We actually need those are the very end (once whe have
29 // all the Frames). Alternatively we could build a map address -> symbol
30 // during tokenization and use this during parsing to resolve symbols.
31 return 3;
32 if (type == TraceType::kProtoTraceType)
33 // Proto traces should always parsed first as they might contains clock
34 // sync data needed to correctly parse other traces.
35 return 0;
36 if (type == TraceType::kGzipTraceType)
37 return 1; // Middle priority
38 return 2; // Default for other trace types
39 };
40
41 // Compare first by trace type priority, then by name,
42 // and finally by index to ensure strict ordering.
43 int lhs_priority = trace_priority(trace_type);
44 int rhs_priority = trace_priority(rhs.trace_type);
45
46 return std::tie(lhs_priority, name, index) <
47 std::tie(rhs_priority, rhs.name, rhs.index);
48 }
49
50 } // namespace perfetto::trace_processor
51