mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-23 16:12:01 +00:00
Miscellaneous #2482
This commit is contained in:
parent
aef490d173
commit
1c4f5d3359
@ -56,7 +56,7 @@ public:
|
||||
static void attachQueryContext(Context & query_context);
|
||||
|
||||
/// You must call one of these methods when create a query child thread:
|
||||
/// Add current thread to a group associated with thr thread group
|
||||
/// Add current thread to a group associated with the thread group
|
||||
static void attachTo(const ThreadGroupStatusPtr & thread_group);
|
||||
/// Is useful for a ThreadPool tasks
|
||||
static void attachToIfDetached(const ThreadGroupStatusPtr & thread_group);
|
||||
|
@ -59,9 +59,10 @@ namespace ProfileEvents
|
||||
} while (current != nullptr);
|
||||
}
|
||||
|
||||
/// Every single value is fetched atomically, but not all values as a whole.
|
||||
Counters getPartiallyAtomicSnapshot() const;
|
||||
|
||||
/// Reset metrics and parent
|
||||
/// Reset all counters to zero and reset parent.
|
||||
void reset();
|
||||
|
||||
/// Get parent (thread unsafe)
|
||||
|
@ -174,7 +174,7 @@ bool TaskStatsInfoGetter::getStatImpl(int tid, ::taskstats & out_stats, bool thr
|
||||
{
|
||||
::nlmsgerr * err = static_cast<::nlmsgerr *>(NLMSG_DATA(&msg));
|
||||
if (throw_on_error)
|
||||
throw Exception("Can't get Netlink response, error=" + std::to_string(err->error), ErrorCodes::NETLINK_ERROR);
|
||||
throw Exception("Can't get Netlink response, error: " + std::to_string(err->error), ErrorCodes::NETLINK_ERROR);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
@ -198,16 +198,16 @@ bool TaskStatsInfoGetter::getStatImpl(int tid, ::taskstats & out_stats, bool thr
|
||||
{
|
||||
if (na->nla_type == TASKSTATS_TYPE_STATS)
|
||||
{
|
||||
::taskstats *ts = static_cast<::taskstats *>(NLA_DATA(na));
|
||||
::taskstats * ts = static_cast<::taskstats *>(NLA_DATA(na));
|
||||
out_stats = *ts;
|
||||
}
|
||||
|
||||
len2 += NLA_ALIGN(na->nla_len);
|
||||
na = reinterpret_cast<::nlattr *>((char *) na + len2);
|
||||
na = reinterpret_cast<::nlattr *>(reinterpret_cast<char *>(na) + len2);
|
||||
}
|
||||
}
|
||||
|
||||
na = reinterpret_cast<::nlattr *>((char *) GENLMSG_DATA(&msg) + len);
|
||||
na = reinterpret_cast<::nlattr *>(reinterpret_cast<char *>(GENLMSG_DATA(&msg)) + len);
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -215,13 +215,13 @@ bool TaskStatsInfoGetter::getStatImpl(int tid, ::taskstats & out_stats, bool thr
|
||||
|
||||
void TaskStatsInfoGetter::getStat(::taskstats & stat, int tid)
|
||||
{
|
||||
tid = tid < 0 ? getDefaultTid() : tid;
|
||||
tid = tid < 0 ? getDefaultTID() : tid;
|
||||
getStatImpl(tid, stat, true);
|
||||
}
|
||||
|
||||
bool TaskStatsInfoGetter::tryGetStat(::taskstats & stat, int tid)
|
||||
{
|
||||
tid = tid < 0 ? getDefaultTid() : tid;
|
||||
tid = tid < 0 ? getDefaultTID() : tid;
|
||||
return getStatImpl(tid, stat, false);
|
||||
}
|
||||
|
||||
@ -233,10 +233,11 @@ TaskStatsInfoGetter::~TaskStatsInfoGetter()
|
||||
|
||||
int TaskStatsInfoGetter::getCurrentTID()
|
||||
{
|
||||
/// This call is always successful. - man gettid
|
||||
return static_cast<int>(syscall(SYS_gettid));
|
||||
}
|
||||
|
||||
int TaskStatsInfoGetter::getDefaultTid()
|
||||
int TaskStatsInfoGetter::getDefaultTID()
|
||||
{
|
||||
if (default_tid < 0)
|
||||
default_tid = getCurrentTID();
|
||||
|
@ -10,11 +10,10 @@ namespace DB
|
||||
class Exception;
|
||||
|
||||
|
||||
/// Get taskstat infor from OS kernel via Netlink protocol
|
||||
/// Get taskstat info from OS kernel via Netlink protocol.
|
||||
class TaskStatsInfoGetter
|
||||
{
|
||||
public:
|
||||
|
||||
TaskStatsInfoGetter();
|
||||
TaskStatsInfoGetter(const TaskStatsInfoGetter &) = delete;
|
||||
|
||||
@ -30,9 +29,8 @@ public:
|
||||
static bool checkProcessHasRequiredPermissions();
|
||||
|
||||
private:
|
||||
|
||||
/// Caches current thread tid to avoid extra sys calls
|
||||
int getDefaultTid();
|
||||
int getDefaultTID();
|
||||
int default_tid = -1;
|
||||
|
||||
bool getStatImpl(int tid, ::taskstats & out_stats, bool throw_on_error = false);
|
||||
|
@ -99,7 +99,7 @@ void do_io(size_t id)
|
||||
get_info.getStat(stat, tid);
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex);
|
||||
std::cerr << "#" << id << ", tid " << tid << ", step2\n" << stat << "\n";
|
||||
std::cerr << "#" << id << ", tid " << tid << ", step3\n" << stat << "\n";
|
||||
}
|
||||
|
||||
Poco::File(path_dst).remove(false);
|
||||
@ -113,16 +113,12 @@ void test_perf()
|
||||
TaskStatsInfoGetter get_info;
|
||||
|
||||
rusage rusage;
|
||||
timespec ts;
|
||||
|
||||
constexpr size_t num_samples = 1000000;
|
||||
{
|
||||
Stopwatch watch;
|
||||
for (size_t i = 0; i < num_samples; ++i)
|
||||
{
|
||||
getrusage(RUSAGE_THREAD, &rusage);
|
||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||
}
|
||||
|
||||
auto ms = watch.elapsedMilliseconds();
|
||||
if (ms > 0)
|
||||
@ -151,13 +147,9 @@ try
|
||||
ThreadPool pool(num_threads);
|
||||
for (size_t i = 0; i < num_threads; ++i)
|
||||
pool.schedule([i]() { do_io(i); });
|
||||
|
||||
pool.wait();
|
||||
|
||||
|
||||
test_perf();
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
catch (...)
|
||||
|
Loading…
Reference in New Issue
Block a user