mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-09-19 16:20:50 +00:00
Merge pull request #64842 from Unalian/jemalloc_as_metric
[feature] Add an asynchronous metric jemalloc.profile.active to show whether sampling is currently active
This commit is contained in:
commit
d9a11faf4a
@ -639,6 +639,10 @@ An internal metric of the low-level memory allocator (jemalloc). See https://jem
|
|||||||
|
|
||||||
An internal metric of the low-level memory allocator (jemalloc). See https://jemalloc.net/jemalloc.3.html
|
An internal metric of the low-level memory allocator (jemalloc). See https://jemalloc.net/jemalloc.3.html
|
||||||
|
|
||||||
|
### jemalloc.prof.active
|
||||||
|
|
||||||
|
An internal metric of the low-level memory allocator (jemalloc). See https://jemalloc.net/jemalloc.3.html
|
||||||
|
|
||||||
**See Also**
|
**See Also**
|
||||||
|
|
||||||
- [Monitoring](../../operations/monitoring.md) — Base concepts of ClickHouse monitoring.
|
- [Monitoring](../../operations/monitoring.md) — Base concepts of ClickHouse monitoring.
|
||||||
|
@ -415,6 +415,15 @@ Value saveAllArenasMetric(AsynchronousMetricValues & values,
|
|||||||
fmt::format("jemalloc.arenas.all.{}", metric_name));
|
fmt::format("jemalloc.arenas.all.{}", metric_name));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename Value>
|
||||||
|
Value saveJemallocProf(AsynchronousMetricValues & values,
|
||||||
|
const std::string & metric_name)
|
||||||
|
{
|
||||||
|
return saveJemallocMetricImpl<Value>(values,
|
||||||
|
fmt::format("prof.{}", metric_name),
|
||||||
|
fmt::format("jemalloc.prof.{}", metric_name));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -607,6 +616,7 @@ void AsynchronousMetrics::update(TimePoint update_time, bool force_update)
|
|||||||
saveJemallocMetric<size_t>(new_values, "background_thread.num_threads");
|
saveJemallocMetric<size_t>(new_values, "background_thread.num_threads");
|
||||||
saveJemallocMetric<uint64_t>(new_values, "background_thread.num_runs");
|
saveJemallocMetric<uint64_t>(new_values, "background_thread.num_runs");
|
||||||
saveJemallocMetric<uint64_t>(new_values, "background_thread.run_intervals");
|
saveJemallocMetric<uint64_t>(new_values, "background_thread.run_intervals");
|
||||||
|
saveJemallocProf<size_t>(new_values, "active");
|
||||||
saveAllArenasMetric<size_t>(new_values, "pactive");
|
saveAllArenasMetric<size_t>(new_values, "pactive");
|
||||||
[[maybe_unused]] size_t je_malloc_pdirty = saveAllArenasMetric<size_t>(new_values, "pdirty");
|
[[maybe_unused]] size_t je_malloc_pdirty = saveAllArenasMetric<size_t>(new_values, "pdirty");
|
||||||
[[maybe_unused]] size_t je_malloc_pmuzzy = saveAllArenasMetric<size_t>(new_values, "pmuzzy");
|
[[maybe_unused]] size_t je_malloc_pmuzzy = saveAllArenasMetric<size_t>(new_values, "pmuzzy");
|
||||||
|
@ -0,0 +1,3 @@
|
|||||||
|
<clickhouse>
|
||||||
|
<asynchronous_metrics_update_period_s>1</asynchronous_metrics_update_period_s>
|
||||||
|
</clickhouse>
|
@ -0,0 +1,73 @@
|
|||||||
|
import time
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
from helpers.cluster import ClickHouseCluster
|
||||||
|
|
||||||
|
cluster = ClickHouseCluster(__file__)
|
||||||
|
node1 = cluster.add_instance(
|
||||||
|
"node1",
|
||||||
|
main_configs=["configs/asynchronous_metrics_update_period_s.xml"],
|
||||||
|
env_variables={"MALLOC_CONF": "background_thread:true,prof:true"},
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(scope="module")
|
||||||
|
def started_cluster():
|
||||||
|
try:
|
||||||
|
cluster.start()
|
||||||
|
yield cluster
|
||||||
|
|
||||||
|
finally:
|
||||||
|
cluster.shutdown()
|
||||||
|
|
||||||
|
|
||||||
|
# asynchronous metrics are updated once every 60s by default. To make the test run faster, the setting
|
||||||
|
# asynchronous_metric_update_period_s is being set to 1s so that the metrics are populated faster and
|
||||||
|
# are available for querying during the test.
|
||||||
|
def test_asynchronous_metric_jemalloc_profile_active(started_cluster):
|
||||||
|
# default open
|
||||||
|
if node1.is_built_with_sanitizer():
|
||||||
|
pytest.skip("Disabled for sanitizers")
|
||||||
|
|
||||||
|
res_o = node1.query(
|
||||||
|
"SELECT * FROM system.asynchronous_metrics WHERE metric ILIKE '%jemalloc.prof.active%' FORMAT Vertical;"
|
||||||
|
)
|
||||||
|
assert (
|
||||||
|
res_o
|
||||||
|
== """Row 1:
|
||||||
|
──────
|
||||||
|
metric: jemalloc.prof.active
|
||||||
|
value: 1
|
||||||
|
description: An internal metric of the low-level memory allocator (jemalloc). See https://jemalloc.net/jemalloc.3.html
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
# disable
|
||||||
|
node1.query("SYSTEM JEMALLOC DISABLE PROFILE")
|
||||||
|
time.sleep(5)
|
||||||
|
res_t = node1.query(
|
||||||
|
"SELECT * FROM system.asynchronous_metrics WHERE metric ILIKE '%jemalloc.prof.active%' FORMAT Vertical;"
|
||||||
|
)
|
||||||
|
assert (
|
||||||
|
res_t
|
||||||
|
== """Row 1:
|
||||||
|
──────
|
||||||
|
metric: jemalloc.prof.active
|
||||||
|
value: 0
|
||||||
|
description: An internal metric of the low-level memory allocator (jemalloc). See https://jemalloc.net/jemalloc.3.html
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
# enable
|
||||||
|
node1.query("SYSTEM JEMALLOC ENABLE PROFILE")
|
||||||
|
time.sleep(5)
|
||||||
|
res_f = node1.query(
|
||||||
|
"SELECT * FROM system.asynchronous_metrics WHERE metric ILIKE '%jemalloc.prof.active%' FORMAT Vertical;"
|
||||||
|
)
|
||||||
|
assert (
|
||||||
|
res_f
|
||||||
|
== """Row 1:
|
||||||
|
──────
|
||||||
|
metric: jemalloc.prof.active
|
||||||
|
value: 1
|
||||||
|
description: An internal metric of the low-level memory allocator (jemalloc). See https://jemalloc.net/jemalloc.3.html
|
||||||
|
"""
|
||||||
|
)
|
Loading…
Reference in New Issue
Block a user