Skip to content

Commit

Permalink
Merge pull request ClickHouse#34749 from azat/profile-events-printing…
Browse files Browse the repository at this point in the history
…-fix

Print only total profile events for --profile-events-delay-ms=-1
  • Loading branch information
novikd authored Feb 22, 2022
2 parents c15b5c2 + 9b753c8 commit 90ae785
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/Client/ClientBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,7 @@ static void incrementProfileEventsBlock(Block & dst, const Block & src)
{
if (!dst)
{
dst = src;
return;
dst = src.cloneEmpty();
}

assertBlocksHaveEqualStructure(src, dst, "ProfileEvents");
Expand All @@ -142,20 +141,19 @@ static void incrementProfileEventsBlock(Block & dst, const Block & src)

const auto & src_column_host_name = typeid_cast<const ColumnString &>(*src.getByName("host_name").column);
const auto & src_array_current_time = typeid_cast<const ColumnUInt32 &>(*src.getByName("current_time").column).getData();
const auto & src_array_thread_id = typeid_cast<const ColumnUInt64 &>(*src.getByName("thread_id").column).getData();
// const auto & src_array_thread_id = typeid_cast<const ColumnUInt64 &>(*src.getByName("thread_id").column).getData();
const auto & src_column_name = typeid_cast<const ColumnString &>(*src.getByName("name").column);
const auto & src_array_value = typeid_cast<const ColumnInt64 &>(*src.getByName("value").column).getData();

struct Id
{
StringRef name;
StringRef host_name;
UInt64 thread_id;

bool operator<(const Id & rhs) const
{
return std::tie(name, host_name, thread_id)
< std::tie(rhs.name, rhs.host_name, rhs.thread_id);
return std::tie(name, host_name)
< std::tie(rhs.name, rhs.host_name);
}
};
std::map<Id, UInt64> rows_by_name;
Expand All @@ -164,7 +162,6 @@ static void incrementProfileEventsBlock(Block & dst, const Block & src)
Id id{
src_column_name.getDataAt(src_row),
src_column_host_name.getDataAt(src_row),
src_array_thread_id[src_row],
};
rows_by_name[id] = src_row;
}
Expand All @@ -175,7 +172,6 @@ static void incrementProfileEventsBlock(Block & dst, const Block & src)
Id id{
dst_column_name.getDataAt(dst_row),
dst_column_host_name.getDataAt(dst_row),
dst_array_thread_id[dst_row],
};

if (auto it = rows_by_name.find(id); it != rows_by_name.end())
Expand Down Expand Up @@ -206,7 +202,18 @@ static void incrementProfileEventsBlock(Block & dst, const Block & src)
}
}

/// Filter out snapshots
std::set<size_t> thread_id_filter_mask;
for (size_t i = 0; i < dst_array_thread_id.size(); ++i)
{
if (dst_array_thread_id[i] != 0)
{
thread_id_filter_mask.emplace(i);
}
}

dst.setColumns(std::move(mutable_columns));
dst.erase(thread_id_filter_mask);
}


Expand Down

0 comments on commit 90ae785

Please sign in to comment.