Skip to content

Commit

Permalink
Merge "tp: migrate counter dur generator to use modern iterators"
Browse files Browse the repository at this point in the history
  • Loading branch information
LalitMaganti authored and Gerrit Code Review committed Jun 30, 2022
2 parents c70c6ac + 31909c4 commit 2c4a70d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 32 deletions.
46 changes: 18 additions & 28 deletions src/trace_processor/dynamic/experimental_counter_dur_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,31 +70,26 @@ base::Status ExperimentalCounterDurGenerator::ComputeTable(

// static
ColumnStorage<int64_t> ExperimentalCounterDurGenerator::ComputeDurColumn(
const Table& table) {
const CounterTable& table) {
// Keep track of the last seen row for each track id.
std::unordered_map<TrackId, uint32_t> last_row_for_track_id;
std::unordered_map<TrackId, CounterTable::RowNumber> last_row_for_track_id;
ColumnStorage<int64_t> dur;

const auto* ts_col =
TypedColumn<int64_t>::FromColumn(table.GetColumnByName("ts"));
const auto* track_id_col =
TypedColumn<tables::CounterTrackTable::Id>::FromColumn(
table.GetColumnByName("track_id"));

for (uint32_t i = 0; i < table.row_count(); ++i) {
for (auto table_it = table.IterateRows(); table_it; ++table_it) {
// Check if we already have a previous row for the current track id.
TrackId track_id = (*track_id_col)[i];
TrackId track_id = table_it.track_id();
auto it = last_row_for_track_id.find(track_id);
if (it == last_row_for_track_id.end()) {
// This means we don't have any row - start tracking this row for the
// future.
last_row_for_track_id.emplace(track_id, i);
last_row_for_track_id.emplace(track_id, table_it.row_number());
} else {
// This means we have an previous row for the current track id. Update
// the duration of the previous row to be up to the current ts.
uint32_t old_row = it->second;
it->second = i;
dur.Set(old_row, (*ts_col)[i] - (*ts_col)[old_row]);
CounterTable::RowNumber old_row = it->second;
it->second = table_it.row_number();
dur.Set(old_row.row_number(),
table_it.ts() - old_row.ToRowReference(table).ts());
}
// Append -1 to mark this event as not having been finished. On a later
// row, we may set this to have the correct value.
Expand All @@ -105,31 +100,26 @@ ColumnStorage<int64_t> ExperimentalCounterDurGenerator::ComputeDurColumn(

// static
ColumnStorage<double> ExperimentalCounterDurGenerator::ComputeDeltaColumn(
const Table& table) {
const CounterTable& table) {
// Keep track of the last seen row for each track id.
std::unordered_map<TrackId, uint32_t> last_row_for_track_id;
std::unordered_map<TrackId, CounterTable::RowNumber> last_row_for_track_id;
ColumnStorage<double> delta;

const auto* value_col =
TypedColumn<double>::FromColumn(table.GetColumnByName("value"));
const auto* track_id_col =
TypedColumn<tables::CounterTrackTable::Id>::FromColumn(
table.GetColumnByName("track_id"));

for (uint32_t i = 0; i < table.row_count(); ++i) {
for (auto table_it = table.IterateRows(); table_it; ++table_it) {
// Check if we already have a previous row for the current track id.
TrackId track_id = (*track_id_col)[i];
TrackId track_id = table_it.track_id();
auto it = last_row_for_track_id.find(track_id);
if (it == last_row_for_track_id.end()) {
// This means we don't have any row - start tracking this row for the
// future.
last_row_for_track_id.emplace(track_id, i);
last_row_for_track_id.emplace(track_id, table_it.row_number());
} else {
// This means we have an previous row for the current track id. Update
// the duration of the previous row to be up to the current ts.
uint32_t old_row = it->second;
it->second = i;
delta.Set(old_row, (*value_col)[i] - (*value_col)[old_row]);
CounterTable::RowNumber old_row = it->second;
it->second = table_it.row_number();
delta.Set(old_row.row_number(),
table_it.value() - old_row.ToRowReference(table).value());
}
delta.Append(0);
}
Expand Down
10 changes: 6 additions & 4 deletions src/trace_processor/dynamic/experimental_counter_dur_generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ namespace trace_processor {

class ExperimentalCounterDurGenerator : public DynamicTableGenerator {
public:
explicit ExperimentalCounterDurGenerator(const tables::CounterTable& table);
using CounterTable = tables::CounterTable;

explicit ExperimentalCounterDurGenerator(const CounterTable& table);
virtual ~ExperimentalCounterDurGenerator() override;

Table::Schema CreateSchema() override;
Expand All @@ -38,11 +40,11 @@ class ExperimentalCounterDurGenerator : public DynamicTableGenerator {
std::unique_ptr<Table>& table_return) override;

// public + static for testing
static ColumnStorage<int64_t> ComputeDurColumn(const Table& table);
static ColumnStorage<double> ComputeDeltaColumn(const Table& table);
static ColumnStorage<int64_t> ComputeDurColumn(const CounterTable& table);
static ColumnStorage<double> ComputeDeltaColumn(const CounterTable& table);

private:
const tables::CounterTable* counter_table_ = nullptr;
const CounterTable* counter_table_ = nullptr;
std::unique_ptr<Table> counter_dur_table_;
};

Expand Down

0 comments on commit 2c4a70d

Please sign in to comment.