A simple app to get run times from a thread
Just a quick app to test and demonstrate how to get run times from a specific thread on FreeBSD.
This commit is contained in:
commit
45e6aebfbf
10 changed files with 366 additions and 0 deletions
34
procstat_cpu_time.hpp
Normal file
34
procstat_cpu_time.hpp
Normal file
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2025 Eilertsens Kodeknekkeri
|
||||
* SPDX-FileCopyrightText: 2025 The FreeBSD Foundation
|
||||
* SPDX-FileContributor: Harald Eilertsen <haraldei@anduin.net>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#ifndef __PROCSTAT_CPU_TIME_HPP
|
||||
#define __PROCSTAT_CPU_TIME_HPP
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
/**
|
||||
* Helper function to get the kernel thread id from a pthread_t handle.
|
||||
*/
|
||||
long ktid_from_pthread(pthread_t thread);
|
||||
|
||||
/**
|
||||
* Get the user and system runtime for a given thread by using libprocstat.
|
||||
*
|
||||
* Possibly slower than the fast_cpu_time method, as we have to iterate over the
|
||||
* thread info (kinfo_proc) structs for every thread in the process until we find
|
||||
* the correct one.
|
||||
*
|
||||
* Also the returned struct is dynamically allocated by the procstat_getprocs function,
|
||||
* and has to be freed by procstat_freeprocs after it's no longer needed.
|
||||
*
|
||||
* While this may be ok when retreiving the info for one struct, it would be way more
|
||||
* efficient to check multiple threads at once using the same returned array of structs.
|
||||
*/
|
||||
void procstat_cpu_time(pthread_t thread, struct timeval * utime, struct timeval * stime);
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue