mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-10 09:32:06 +00:00
Add coverage file flush for clickhouse-server when std::atexit is not called. Also slightly improved logging in stateless tests with coverage.
This commit is contained in:
parent
94b98e7f29
commit
a175ea5b73
@ -18,6 +18,7 @@
|
|||||||
#include <common/config_common.h>
|
#include <common/config_common.h>
|
||||||
#include <common/ErrorHandlers.h>
|
#include <common/ErrorHandlers.h>
|
||||||
#include <common/getMemoryAmount.h>
|
#include <common/getMemoryAmount.h>
|
||||||
|
#include <common/coverage.h>
|
||||||
#include <Common/ClickHouseRevision.h>
|
#include <Common/ClickHouseRevision.h>
|
||||||
#include <Common/DNSResolver.h>
|
#include <Common/DNSResolver.h>
|
||||||
#include <Common/CurrentMetrics.h>
|
#include <Common/CurrentMetrics.h>
|
||||||
@ -938,6 +939,8 @@ int Server::main(const std::vector<std::string> & /*args*/)
|
|||||||
/// (they are effectively dangling objects, but they use global thread pool
|
/// (they are effectively dangling objects, but they use global thread pool
|
||||||
/// and global thread pool destructor will wait for threads, preventing server shutdown).
|
/// and global thread pool destructor will wait for threads, preventing server shutdown).
|
||||||
|
|
||||||
|
/// Dump coverage here, because std::atexit callback would not be called.
|
||||||
|
dumpCoverageReportIfPossible();
|
||||||
LOG_INFO(log, "Will shutdown forcefully.");
|
LOG_INFO(log, "Will shutdown forcefully.");
|
||||||
_exit(Application::EXIT_OK);
|
_exit(Application::EXIT_OK);
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,16 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
kill_clickhouse () {
|
kill_clickhouse () {
|
||||||
|
echo "clickhouse pids" `ps aux | grep clickhouse` | ts '%Y-%m-%d %H:%M:%S'
|
||||||
kill `pgrep -u clickhouse` 2>/dev/null
|
kill `pgrep -u clickhouse` 2>/dev/null
|
||||||
|
|
||||||
for i in {1..10}
|
for i in {1..10}
|
||||||
do
|
do
|
||||||
if ! kill -0 `pgrep -u clickhouse`; then
|
if ! kill -0 `pgrep -u clickhouse`; then
|
||||||
echo "No clickhouse process"
|
echo "No clickhouse process" | ts '%Y-%m-%d %H:%M:%S'
|
||||||
break
|
break
|
||||||
else
|
else
|
||||||
echo "Process" `pgrep -u clickhouse` "still alive"
|
echo "Process" `pgrep -u clickhouse` "still alive" | ts '%Y-%m-%d %H:%M:%S'
|
||||||
sleep 10
|
sleep 10
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
@ -18,7 +19,7 @@ kill_clickhouse () {
|
|||||||
wait_llvm_profdata () {
|
wait_llvm_profdata () {
|
||||||
while kill -0 `pgrep llvm-profdata-9`;
|
while kill -0 `pgrep llvm-profdata-9`;
|
||||||
do
|
do
|
||||||
echo "Waiting for profdata" `pgrep llvm-profdata-9` "still alive"
|
echo "Waiting for profdata" `pgrep llvm-profdata-9` "still alive" | ts '%Y-%m-%d %H:%M:%S'
|
||||||
sleep 3
|
sleep 3
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,7 @@ add_library (common
|
|||||||
src/argsToConfig.cpp
|
src/argsToConfig.cpp
|
||||||
src/Pipe.cpp
|
src/Pipe.cpp
|
||||||
src/phdr_cache.cpp
|
src/phdr_cache.cpp
|
||||||
|
src/coverage.cpp
|
||||||
|
|
||||||
include/common/SimpleCache.h
|
include/common/SimpleCache.h
|
||||||
include/common/Types.h
|
include/common/Types.h
|
||||||
@ -51,6 +52,7 @@ add_library (common
|
|||||||
include/common/sleep.h
|
include/common/sleep.h
|
||||||
include/common/SimpleCache.h
|
include/common/SimpleCache.h
|
||||||
include/common/phdr_cache.h
|
include/common/phdr_cache.h
|
||||||
|
include/common/coverage.h
|
||||||
|
|
||||||
include/ext/bit_cast.h
|
include/ext/bit_cast.h
|
||||||
include/ext/chrono_io.h
|
include/ext/chrono_io.h
|
||||||
|
9
libs/libcommon/include/common/coverage.h
Normal file
9
libs/libcommon/include/common/coverage.h
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
/// Flush coverage report to file, depending on coverage system
|
||||||
|
/// proposed by compiler (llvm for clang and gcov for gcc).
|
||||||
|
///
|
||||||
|
/// Noop if build without coverage (WITH_COVERAGE=0).
|
||||||
|
/// Thread safe (use exclusive lock).
|
||||||
|
/// Idempotent, may be called multiple times.
|
||||||
|
void dumpCoverageReportIfPossible();
|
31
libs/libcommon/src/coverage.cpp
Normal file
31
libs/libcommon/src/coverage.cpp
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
#include <common/coverage.h>
|
||||||
|
#include <common/config_common.h>
|
||||||
|
|
||||||
|
#if WITH_COVERAGE
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
|
#if defined(__clang__)
|
||||||
|
extern "C" void __llvm_profile_dump();
|
||||||
|
#elif defined(__GNUC__) || defined(__GNUG__)
|
||||||
|
extern "C" void __gcov_exit();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
void dumpCoverageReportIfPossible()
|
||||||
|
{
|
||||||
|
#if WITH_COVERAGE
|
||||||
|
static std::mutex mutex;
|
||||||
|
std::lock_guard lock(mutex);
|
||||||
|
|
||||||
|
#if defined(__clang__)
|
||||||
|
__llvm_profile_dump();
|
||||||
|
#elif defined(__GNUC__) || defined(__GNUG__)
|
||||||
|
__gcov_exit();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
}
|
@ -25,6 +25,7 @@
|
|||||||
#include <Poco/Observer.h>
|
#include <Poco/Observer.h>
|
||||||
#include <Poco/AutoPtr.h>
|
#include <Poco/AutoPtr.h>
|
||||||
#include <common/getThreadNumber.h>
|
#include <common/getThreadNumber.h>
|
||||||
|
#include <common/coverage.h>
|
||||||
#include <Poco/PatternFormatter.h>
|
#include <Poco/PatternFormatter.h>
|
||||||
#include <Poco/TaskManager.h>
|
#include <Poco/TaskManager.h>
|
||||||
#include <Poco/File.h>
|
#include <Poco/File.h>
|
||||||
@ -461,6 +462,7 @@ void BaseDaemon::terminate()
|
|||||||
|
|
||||||
void BaseDaemon::kill()
|
void BaseDaemon::kill()
|
||||||
{
|
{
|
||||||
|
dumpCoverageReportIfPossible();
|
||||||
pid.clear();
|
pid.clear();
|
||||||
if (::raise(SIGKILL) != 0)
|
if (::raise(SIGKILL) != 0)
|
||||||
throw Poco::SystemException("cannot kill process");
|
throw Poco::SystemException("cannot kill process");
|
||||||
|
Loading…
Reference in New Issue
Block a user