MCPcopy Create free account
hub / github.com/ClickHouse/ClickHouse / onProfileEvents

Method onProfileEvents

src/Client/ClientBase.cpp:1723–1813  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1721
1722
1723void ClientBase::onProfileEvents(Block & block)
1724{
1725 const auto rows = block.rows();
1726 if (rows == 0)
1727 return;
1728
1729 if (getName() == "local" || isEmbeeddedClient() || server_revision >= DBMS_MIN_PROTOCOL_VERSION_WITH_INCREMENTAL_PROFILE_EVENTS)
1730 {
1731 const auto & array_thread_id = typeid_cast<const ColumnUInt64 &>(*block.getByName("thread_id").column).getData();
1732 const auto & names = typeid_cast<const ColumnString &>(*block.getByName("name").column);
1733 const auto & host_names = typeid_cast<const ColumnString &>(*block.getByName("host_name").column);
1734 const auto & array_values = typeid_cast<const ColumnInt64 &>(*block.getByName("value").column).getData();
1735
1736 std::string_view user_time_name = ProfileEvents::getName(ProfileEvents::UserTimeMicroseconds);
1737 std::string_view system_time_name = ProfileEvents::getName(ProfileEvents::SystemTimeMicroseconds);
1738
1739 HostToTimesMap thread_times;
1740 for (size_t i = 0; i < rows; ++i)
1741 {
1742 auto thread_id = array_thread_id[i];
1743 std::string host_name{host_names.getDataAt(i)};
1744
1745 /// In ProfileEvents packets thread id 0 specifies common profiling information
1746 /// for all threads executing current query on specific host. So instead of summing per thread
1747 /// consumption it's enough to look for data with thread id 0.
1748 if (thread_id != THREAD_GROUP_ID)
1749 continue;
1750
1751 auto event_name = names.getDataAt(i);
1752 auto value = array_values[i];
1753
1754 /// Ignore negative time delta or memory usage just in case.
1755 if (value < 0)
1756 continue;
1757
1758 if (event_name == user_time_name)
1759 thread_times[host_name].user_ms = value;
1760 else if (event_name == system_time_name)
1761 thread_times[host_name].system_ms = value;
1762 else if (event_name == MemoryTracker::USAGE_EVENT_NAME)
1763 thread_times[host_name].memory_usage = value;
1764 else if (event_name == MemoryTracker::PEAK_USAGE_EVENT_NAME)
1765 thread_times[host_name].peak_memory_usage = value;
1766 /// Keep the literal in sync with TemporaryDataOnDiskScope::USAGE_EVENT_NAME.
1767 else if (event_name == "TemporaryDataOnDiskUsage")
1768 thread_times[host_name].temp_data_on_disk_usage = value;
1769 }
1770 progress_indication.updateThreadEventData(thread_times);
1771 progress_table.updateTable(block);
1772
1773 if (need_render_progress && tty_buf)
1774 {
1775 std::unique_lock lock(tty_mutex);
1776 progress_indication.writeProgress(*tty_buf, lock);
1777 }
1778 if (need_render_progress_table && tty_buf && !cancelled)
1779 {
1780 bool toggle_enabled = getClientConfiguration().getBool("enable-progress-table-toggle", true);

Callers

nothing calls this directly

Calls 15

getByNameMethod · 0.80
updateThreadEventDataMethod · 0.80
updateTableMethod · 0.80
writeTableMethod · 0.80
clearProgressOutputMethod · 0.80
clearTableOutputMethod · 0.80
writeProfileEventsMethod · 0.80
getNameFunction · 0.50
rowsMethod · 0.45
getDataMethod · 0.45
getDataAtMethod · 0.45

Tested by

no test coverage detected