Just a quick app to test and demonstrate how to get run times from a specific thread on FreeBSD.
32 lines
719 B
C++
32 lines
719 B
C++
/*
|
|
* SPDX-FileCopyrightText: 2025 Eilertsens Kodeknekkeri
|
|
* SPDX-FileCopyrightText: 2025 The FreeBSD Foundation
|
|
* SPDX-FileContributor: Harald Eilertsen <haraldei@anduin.net>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include "fast_cpu_time.hpp"
|
|
#include "helpers.hpp"
|
|
#include <cassert>
|
|
|
|
namespace {
|
|
clockid_t get_thread_clock_id(pthread_t thread) {
|
|
clockid_t clock_id;
|
|
|
|
auto rc = pthread_getcpuclockid(thread, &clock_id);
|
|
assert(rc == 0);
|
|
|
|
return clock_id;
|
|
}
|
|
}
|
|
|
|
unsigned long fast_thread_cpu_time(pthread_t thread) {
|
|
auto clock_id = get_thread_clock_id(thread);
|
|
|
|
struct timespec time;
|
|
auto rc = clock_gettime(clock_id, &time);
|
|
assert(rc == 0);
|
|
|
|
return time.tv_sec * 1000000 + time.tv_nsec;
|
|
}
|