pthread_getrusage_np Subroutine

Purpose

Enable or disable pthread library resource collection, and retrieve resource information for any pthread in the current process.

Library

Threads Library (libpthreads.a)

Syntax

#include <pthread.h>

int pthread_getrusage_np (Ptid, RUsage, Mode)
pthread_t Ptid;
struct rusage *RUsage;
int Mode;

Description

The pthread_getrusage_np subroutine enables and disables resource collection in the pthread library and collects resource information for any pthread in the current process. When compiled in 64-bit mode, resource usage (rusage) counters are 64-bits for the calling thread. When compiled in 32-bit mode, rusage counters are 32-bits for the calling pthread.

This functionality is enabled by default. The previous AIXTHREAD_ENRUSG used with pthread_getrusage_np is no longer supported.

Parameters

Item Description
Ptid Specifies the target thread. Must be within the current process.
RUsage Points to a buffer described in the /usr/include/sys/resource.h file. The fields are defined as follows:
ru_utime
The total amount of time running in user mode.
ru_stime
The total amount of time spent in the system executing on behalf of the processes.
ru_maxrss
The maximum size, in kilobytes, of the used resident set size.
ru_ixrss
An integral value indicating the amount of memory used by the text segment that was also shared among other processes. This value is expressed in units of kilobytes X seconds-of-execution and is calculated by adding the number of shared memory pages in use each time the internal system clock ticks, and then averaging over one-second intervals.
ru_idrss
An integral value of the amount of unshared memory in the data segment of a process, which is expressed in units of kilobytes X seconds-of-execution.
ru_minflt
The number of page faults serviced without any I/O activity. In this case, I/O activity is avoided by reclaiming a page frame from the list of pages awaiting reallocation.
ru_majflt
The number of page faults serviced that required I/O activity.
ru_nswap
The number of times that a process was swapped out of main memory.
ru_inblock
The number of times that the file system performed input.
ru_oublock
The number of times that the file system performed output.
Note: The numbers that the ru_inblock and ru_oublock fields display account for real I/O only; data supplied by the caching mechanism is charged only to the first process that reads or writes the data.
ru_msgsnd
The number of IPC messages sent.
ru_msgrcv
The number of IPC messages received.
ru_nsignals
The number of signals delivered.
ru_nvcsw
The number of times a context switch resulted because a process voluntarily gave up the processor before its time slice was completed. This usually occurs while the process waits for a resource to become available.
ru_nivcsw
The number of times a context switch resulted because a higher priority process ran or because the current process exceeded its time slice.
Mode Indicates which task the subroutine should perform. Acceptable values are as follows:
PTHRDSINFO_RUSAGE_START
Returns the current resource utilization, which will be the start measurement.
PTHRDSINFO_RUSAGE_STOP
Returns total current resource utilization since the last time a PTHRDSINFO_RUSAGE_START was performed. If the task PTHRDSINFO_RUSAGE_START was not performed, then the resource information returned is the accumulated value since the start of the pthread.
PTHRDSINFO_RUSAGE_COLLECT
Collects resource information for the target thread. If the task PTHRDSINFO_RUSAGE_START was not performed, then the resource information returned is the accumulated value since the start of the pthread.

Return Values

Upon successful completion, the pthread_getrusage_np subroutine returns a value of 0. Otherwise, an error number is returned to indicate the error.

Error Codes

The pthread_getrusage_np subroutine fails if one of the following is true:
Item Description
EINVAL The address specified for RUsage is NULL, not valid, or a null value for Ptid was given.
ESRCH Either no thread could be found corresponding to the ID thread of the Ptid thread or the thread corresponding to the Ptid thread ID was not in the current process.