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

Function setCoverageTest

base/base/coverage.cpp:367–417  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

365
366
367void setCoverageTest(std::string_view test_name)
368{
369 /// We collect what we need under the lock, then release it before invoking
370 /// the callback (which may do heavy DB work and must not hold the mutex).
371 std::string prev_test_name;
372 std::vector<CovCounter> name_refs;
373 std::vector<IndirectCallEntry> indirect_calls;
374 CoverageFlushCallback cb;
375
376 {
377 std::lock_guard lock(g_coverage_mutex);
378
379 if (!g_current_test_name.empty() && g_flush_callback)
380 {
381 /// Collect covered NameRefs and indirect-call observations before reset.
382 name_refs = getCurrentCoveredNameRefs();
383 indirect_calls = getCurrentIndirectCalls();
384 prev_test_name = g_current_test_name;
385 cb = g_flush_callback;
386 }
387
388 __llvm_profile_reset_counters(); // NOLINT
389
390#ifdef CLICKHOUSE_XRAY_INSTRUMENT_COVERAGE
391 /// Bump XRay generation so every thread resets its depth baseline on next call.
392 g_xray_generation.fetch_add(1, std::memory_order_relaxed);
393 /// Reset per-function min-depth array.
394 for (uint32_t i = 0; i < g_xray_depth_size; ++i)
395 g_xray_min_depth[i].store(UINT32_MAX, std::memory_order_relaxed);
396 if (!g_current_test_name.empty())
397 {
398 /// Deactivate XRay after collecting the previous test's data.
399 __xray_unpatch();
400 }
401 if (!test_name.empty())
402 {
403 /// Build the XRay→profile map lazily on first test start.
404 buildXRayProfileMap();
405 __xray_set_handler(xrayHandler);
406 __xray_patch();
407 }
408#endif
409
410 g_current_test_name = std::string(test_name);
411 }
412
413 /// Invoke the callback outside the lock so the DB layer can look up
414 /// source locations and insert into system.coverage_log without risking deadlock.
415 if (cb)
416 cb(prev_test_name, name_refs, indirect_calls);
417}
418
419void resetCoverage()
420{

Callers 2

resetCoverageFunction · 0.85
executeMethod · 0.85

Calls 6

getCurrentIndirectCallsFunction · 0.85
buildXRayProfileMapFunction · 0.85
cbFunction · 0.85
emptyMethod · 0.45
storeMethod · 0.45

Tested by

no test coverage detected