Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Android.bp
Original file line number Diff line number Diff line change
Expand Up @@ -3265,6 +3265,7 @@ cc_test {
":perfetto_src_trace_processor_util_build_id",
":perfetto_src_trace_processor_util_bump_allocator",
":perfetto_src_trace_processor_util_clock",
":perfetto_src_trace_processor_util_cold_sort",
":perfetto_src_trace_processor_util_compressor",
":perfetto_src_trace_processor_util_decompressor",
":perfetto_src_trace_processor_util_descriptors",
Expand Down Expand Up @@ -21665,6 +21666,7 @@ cc_library_static {
":perfetto_src_trace_processor_util_build_id",
":perfetto_src_trace_processor_util_bump_allocator",
":perfetto_src_trace_processor_util_clock",
":perfetto_src_trace_processor_util_cold_sort",
":perfetto_src_trace_processor_util_compressor",
":perfetto_src_trace_processor_util_decompressor",
":perfetto_src_trace_processor_util_deobfuscation_deobfuscator",
Expand Down Expand Up @@ -22064,6 +22066,14 @@ filegroup {
],
}

// GN: //src/trace_processor/util:cold_sort
filegroup {
name: "perfetto_src_trace_processor_util_cold_sort",
srcs: [
"src/trace_processor/util/cold_sort.cc",
],
}

// GN: //src/trace_processor/util:compressor
filegroup {
name: "perfetto_src_trace_processor_util_compressor",
Expand Down Expand Up @@ -22347,6 +22357,7 @@ filegroup {
name: "perfetto_src_trace_processor_util_unittests",
srcs: [
"src/trace_processor/util/bump_allocator_unittest.cc",
"src/trace_processor/util/cold_sort_unittest.cc",
"src/trace_processor/util/concurrency_stress_test_util_unittest.cc",
"src/trace_processor/util/descriptors_unittest.cc",
"src/trace_processor/util/flatbuffer_reader_unittest.cc",
Expand Down Expand Up @@ -24739,6 +24750,7 @@ cc_test {
":perfetto_src_trace_processor_util_build_id",
":perfetto_src_trace_processor_util_bump_allocator",
":perfetto_src_trace_processor_util_clock",
":perfetto_src_trace_processor_util_cold_sort",
":perfetto_src_trace_processor_util_compressor",
":perfetto_src_trace_processor_util_concurrency_stress_test_util",
":perfetto_src_trace_processor_util_decompressor",
Expand Down Expand Up @@ -25868,6 +25880,7 @@ cc_library_static {
":perfetto_src_trace_processor_util_build_id",
":perfetto_src_trace_processor_util_bump_allocator",
":perfetto_src_trace_processor_util_clock",
":perfetto_src_trace_processor_util_cold_sort",
":perfetto_src_trace_processor_util_compressor",
":perfetto_src_trace_processor_util_decompressor",
":perfetto_src_trace_processor_util_descriptors",
Expand Down Expand Up @@ -26587,6 +26600,7 @@ cc_binary_host {
":perfetto_src_trace_processor_util_build_id",
":perfetto_src_trace_processor_util_bump_allocator",
":perfetto_src_trace_processor_util_clock",
":perfetto_src_trace_processor_util_cold_sort",
":perfetto_src_trace_processor_util_compressor",
":perfetto_src_trace_processor_util_decompressor",
":perfetto_src_trace_processor_util_deobfuscation_deobfuscator",
Expand Down
24 changes: 24 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,7 @@ perfetto_cc_library(
":src_trace_processor_plugins_wattson_gen_tpu_curves",
":src_trace_processor_trace_summary_gen_cc_trace_summary_descriptor",
":src_trace_processor_util_build_id",
":src_trace_processor_util_cold_sort",
":src_trace_processor_util_simple_json_parser",
] + PERFETTO_CONFIG.deps.sqlite +
PERFETTO_CONFIG.deps.sqlite_ext_percentile +
Expand Down Expand Up @@ -1068,6 +1069,7 @@ perfetto_cc_library(
":src_trace_processor_plugins_wattson_gen_tpu_curves",
":src_trace_processor_trace_summary_gen_cc_trace_summary_descriptor",
":src_trace_processor_util_build_id",
":src_trace_processor_util_cold_sort",
":src_trace_processor_util_deobfuscation_deobfuscator",
":src_trace_processor_util_simple_json_parser",
":src_trace_processor_util_symbolizer_symbolize_database",
Expand Down Expand Up @@ -6129,6 +6131,7 @@ perfetto_cc_library(
":protos_perfetto_trace_track_event_zero",
":protos_perfetto_trace_translation_zero",
":src_trace_processor_util_build_id",
":src_trace_processor_util_cold_sort",
":src_trace_processor_util_symbolizer_symbolizer",
],
linkstatic = True,
Expand Down Expand Up @@ -6225,6 +6228,25 @@ perfetto_filegroup(
],
)

# GN target: //src/trace_processor/util:cold_sort
perfetto_cc_library(
name = "src_trace_processor_util_cold_sort",
srcs = [
"src/trace_processor/util/cold_sort.cc",
],
hdrs = [
":include_perfetto_base_base",
":include_perfetto_ext_base_base",
":include_perfetto_public_abi_base",
":include_perfetto_public_base",
"src/trace_processor/util/cold_sort.h",
],
deps = [
":src_base_base",
],
linkstatic = True,
)

# GN target: //src/trace_processor/util:compressor
perfetto_filegroup(
name = "src_trace_processor_util_compressor",
Expand Down Expand Up @@ -12197,6 +12219,7 @@ perfetto_cc_library(
":src_trace_processor_plugins_wattson_gen_tpu_curves",
":src_trace_processor_trace_summary_gen_cc_trace_summary_descriptor",
":src_trace_processor_util_build_id",
":src_trace_processor_util_cold_sort",
":src_trace_processor_util_simple_json_parser",
] + PERFETTO_CONFIG.deps.sqlite +
PERFETTO_CONFIG.deps.sqlite_ext_percentile +
Expand Down Expand Up @@ -12543,6 +12566,7 @@ perfetto_cc_binary(
":src_trace_processor_plugins_wattson_gen_tpu_curves",
":src_trace_processor_trace_summary_gen_cc_trace_summary_descriptor",
":src_trace_processor_util_build_id",
":src_trace_processor_util_cold_sort",
":src_trace_processor_util_deobfuscation_deobfuscator",
":src_trace_processor_util_simple_json_parser",
":src_trace_processor_util_symbolizer_symbolize_database",
Expand Down
1 change: 1 addition & 0 deletions src/trace_processor/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ source_set("export_json") {
"tables",
"types",
"util:args_utils",
"util:cold_sort",
"util:json_value",
]
public_deps = [ "../../include/perfetto/ext/trace_processor:export_json" ]
Expand Down
1 change: 1 addition & 0 deletions src/trace_processor/core/dataframe/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ source_set("dataframe") {
"../../../base",
"../../../base/regex",
"../../containers",
"../../util:cold_sort",
"../../util:flatbuffer_reader",
"../../util:flatbuffer_writer",
"../../util:glob",
Expand Down
11 changes: 4 additions & 7 deletions src/trace_processor/core/dataframe/logical_plan.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "src/trace_processor/core/common/storage_types.h"
#include "src/trace_processor/core/dataframe/specs.h"
#include "src/trace_processor/core/dataframe/types.h"
#include "src/trace_processor/util/cold_sort.h"

namespace perfetto::trace_processor::core::dataframe {

Expand Down Expand Up @@ -204,13 +205,9 @@ class Planner {

base::Status Planner::Filter(std::vector<FilterSpec>& specs) {
// Sort filters by efficiency (most selective/cheapest first)
std::stable_sort(specs.begin(), specs.end(),
[this](const FilterSpec& a, const FilterSpec& b) {
const auto& a_col = GetColumn(a.col);
const auto& b_col = GetColumn(b.col);
return FilterPreference(a, a_col) <
FilterPreference(b, b_col);
});
ColdStableSortByKey(specs.begin(), specs.end(), [this](const FilterSpec& fs) {
return FilterPreference(fs, GetColumn(fs.col));
});

std::vector<uint8_t> specs_handled(specs.size(), false);

Expand Down
1 change: 1 addition & 0 deletions src/trace_processor/core/exec/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ source_set("exec") {
"../../../base",
"../../containers",
"../../util:bump_allocator",
"../../util:cold_sort",
"../common",
"../dataframe",
"../util",
Expand Down
6 changes: 3 additions & 3 deletions src/trace_processor/core/exec/interval_intersect.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#include "src/trace_processor/core/exec/row_store.h"
#include "src/trace_processor/core/util/bit_vector.h"
#include "src/trace_processor/core/util/span.h"
#include "src/trace_processor/util/cold_sort.h"

namespace perfetto::trace_processor::core::exec {
namespace {
Expand Down Expand Up @@ -276,9 +277,8 @@ void NarrowKey(const std::vector<const Group*>& groups,
auto count = static_cast<uint32_t>(groups.size());
order.resize(count);
std::iota(order.begin(), order.end(), 0u);
std::sort(order.begin(), order.end(), [&](uint32_t a, uint32_t b) {
return groups[a]->intervals.size() < groups[b]->intervals.size();
});
ColdSortByKey(order.begin(), order.end(),
[&](uint32_t i) { return groups[i]->intervals.size(); });

running.Clear();
for (const Interval& interval : groups[order.front()]->intervals) {
Expand Down
11 changes: 4 additions & 7 deletions src/trace_processor/export_json.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
#include "src/trace_processor/types/trace_processor_context.h"
#include "src/trace_processor/types/variadic.h"
#include "src/trace_processor/util/args_utils.h"
#include "src/trace_processor/util/cold_sort.h"
#include "src/trace_processor/util/json_value.h"

namespace perfetto::trace_processor::json {
Expand Down Expand Up @@ -212,13 +213,9 @@ class JsonExporter {
// is emitted before its parent's end event, even if both end events have
// the same timestamp. To accomplish this, we perform a stable sort in
// descending order and later iterate via reverse iterators.
struct {
bool operator()(const Dom& a, const Dom& b) const {
return a["ts"].AsInt64() > b["ts"].AsInt64();
}
} CompareEvents;
std::stable_sort(async_end_events_.begin(), async_end_events_.end(),
CompareEvents);
ColdStableSortByKeyDescending(
async_end_events_.begin(), async_end_events_.end(),
[](const Dom& event) { return event["ts"].AsInt64(); });

// Merge sort by timestamp. If events share the same timestamp, prefer
// instant events, then end events, so that old slices close before new
Expand Down
1 change: 1 addition & 0 deletions src/trace_processor/importers/android_bugreport/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ source_set("android_bugreport") {
"../../storage",
"../../tables:tables_python",
"../../types",
"../../util:cold_sort",
"../../util:trace_type",
"../../util:zip_reader",
"../common",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include "src/trace_processor/sorter/trace_sorter.h"
#include "src/trace_processor/storage/stats.h"
#include "src/trace_processor/types/trace_processor_context.h"
#include "src/trace_processor/util/cold_sort.h"
#include "src/trace_processor/util/trace_type.h"

namespace perfetto::trace_processor {
Expand Down Expand Up @@ -350,7 +351,9 @@ DedupingAndroidLogReader::DedupingAndroidLogReader(
std::vector<TimestampedAndroidLogEvent> events)
: AndroidLogReader(context, year, std::move(stream), wait_for_tz),
events_(std::move(events)) {
std::sort(events_.begin(), events_.end());
ColdSortByKey(
events_.begin(), events_.end(),
[](const TimestampedAndroidLogEvent& e) { return e.ts.count(); });
}

DedupingAndroidLogReader::~DedupingAndroidLogReader() {}
Expand Down
5 changes: 4 additions & 1 deletion src/trace_processor/importers/memory_tracker/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ import("../../../../gn/perfetto.gni")
import("../../../../gn/test.gni")

source_set("graph_processor") {
deps = [ "../../../../gn:default_deps" ]
deps = [
"../../../../gn:default_deps",
"../../util:cold_sort",
]
public_deps = [
"../../../../include/perfetto/base",
"../../../../include/perfetto/ext/base",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

#include <list>

#include "src/trace_processor/util/cold_sort.h"

namespace perfetto {
namespace trace_processor {

Expand Down Expand Up @@ -680,13 +682,11 @@ void GraphProcessor::CalculateNodeOwnershipCoefficient(Node* node) {
// Sort the owners in decreasing order of ownership priority and
// increasing order of not-owning sub-size (in case of equal priority).
std::vector<Edge*> owners = *node->owned_by_edges();
std::sort(owners.begin(), owners.end(), [](Edge* a, Edge* b) {
if (a->priority() == b->priority()) {
return a->source()->not_owning_sub_size() <
b->source()->not_owning_sub_size();
}
return b->priority() < a->priority();
ColdSortByKey(owners.begin(), owners.end(), [](Edge* edge) {
return edge->source()->not_owning_sub_size();
});
ColdStableSortByKeyDescending(owners.begin(), owners.end(),
[](Edge* edge) { return edge->priority(); });

// Loop over the list of owners and distribute the owned node's not-owned
// sub-size among them according to their ownership priority and
Expand Down
1 change: 1 addition & 0 deletions src/trace_processor/importers/ninja/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ source_set("ninja") {
"../../importers/common",
"../../sorter",
"../../storage",
"../../util:cold_sort",
"../../util:trace_type",
]
}
5 changes: 3 additions & 2 deletions src/trace_processor/importers/ninja/ninja_log_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "src/trace_processor/importers/common/track_tracker.h"
#include "src/trace_processor/storage/stats.h"
#include "src/trace_processor/storage/trace_storage.h"
#include "src/trace_processor/util/cold_sort.h"
#include "src/trace_processor/util/trace_type.h"

namespace perfetto::trace_processor {
Expand Down Expand Up @@ -126,8 +127,8 @@ base::Status NinjaLogParser::Parse(TraceBlobView blob) {
// been populated.
base::Status NinjaLogParser::OnPushDataToSorter() {
// Phase 1: Sort jobs and write slices directly to storage
std::sort(jobs_.begin(), jobs_.end(),
[](const Job& x, const Job& y) { return x.start_ms < y.start_ms; });
ColdSortByKey(jobs_.begin(), jobs_.end(),
[](const Job& job) { return job.start_ms; });

// Now we need to work out the job parallelism. There's no direct indication
// of that in the ninja logs, so it must be inferred by observing overlapping
Expand Down
1 change: 1 addition & 0 deletions src/trace_processor/importers/perf/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ source_set("perf") {
"../../tables:tables_python",
"../../types",
"../../util:build_id",
"../../util:cold_sort",
"../../util:trace_blob_view_reader",
"../../util:trace_type",
"../common",
Expand Down
25 changes: 14 additions & 11 deletions src/trace_processor/importers/perf/perf_data_tokenizer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
#include "src/trace_processor/types/variadic.h"
#include "src/trace_processor/util/build_id.h"
#include "src/trace_processor/util/clock_synchronizer.h"
#include "src/trace_processor/util/cold_sort.h"
#include "src/trace_processor/util/trace_blob_view_reader.h"
#include "src/trace_processor/util/trace_type.h"

Expand Down Expand Up @@ -437,17 +438,19 @@ PerfDataTokenizer::ParseFeatureSections() {
PERFETTO_CHECK(reader.Read(feature_sections_.back().second));
}

std::sort(feature_sections_.begin(), feature_sections_.end(),
[](const std::pair<uint8_t, PerfFile::Section>& lhs,
const std::pair<uint8_t, PerfFile::Section>& rhs) {
if (lhs.second.offset == rhs.second.offset) {
// Some sections have 0 length and thus there can be offset
// collisions. To make sure we parse sections by increasing
// offset parse empty sections first.
return lhs.second.size > rhs.second.size;
}
return lhs.second.offset > rhs.second.offset;
});
// Sorts by offset, then size, both descending: a stable sort by size, then
// by offset. Some sections have 0 length and thus there can be offset
// collisions. To make sure we parse sections by increasing offset parse
// empty sections first.
ColdSortByKeyDescending(feature_sections_.begin(), feature_sections_.end(),
[](const std::pair<uint8_t, PerfFile::Section>& s) {
return s.second.size;
});
ColdStableSortByKeyDescending(
feature_sections_.begin(), feature_sections_.end(),
[](const std::pair<uint8_t, PerfFile::Section>& s) {
return s.second.offset;
});

buffer_.PopFrontUntil(feature_headers_section_.end());
parsing_state_ = feature_sections_.empty() ? ParsingState::kDone
Expand Down
2 changes: 2 additions & 0 deletions src/trace_processor/importers/proto/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ source_set("minimal") {
"../../tables",
"../../types",
"../../util:build_id",
"../../util:cold_sort",
"../../util:decompressor",
"../../util:json_args",
"../../util:json_parser",
Expand Down Expand Up @@ -251,6 +252,7 @@ source_set("full") {
"../../tables",
"../../types",
"../../util:build_id",
"../../util:cold_sort",
"../../util:descriptors",
"../../util:profiler_util",
"../../util:proto_profiler",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "src/trace_processor/importers/proto/v8_module.h"
#include "src/trace_processor/storage/trace_storage.h"
#include "src/trace_processor/tables/android_tables_py.h"
#include "src/trace_processor/util/cold_sort.h"

#include "protos/perfetto/trace/android/cpu_per_uid_data.pbzero.h"
#include "protos/perfetto/trace/trace_packet.pbzero.h"
Expand Down Expand Up @@ -179,8 +180,8 @@ void AndroidCpuPerUidModule::OnEventsFullyExtracted() {
rows.push_back(row);
}

std::sort(rows.begin(), rows.end(),
[](auto& a, auto& b) { return a.track_id < b.track_id; });
ColdSortByKey(rows.begin(), rows.end(),
[](const auto& row) { return row.track_id.value; });

for (const auto& row : rows) {
context_->storage->mutable_android_cpu_per_uid_track_table()->Insert(row);
Expand Down
Loading
Loading