$Revision: 1.8 $
thread accounting (ta). ta.c - functions to keep track of activities
of threads within the server
Status: NOT REVUED, TESTED, COMPLETE
Design and implementation by: Marek Bukowy
Included Files
Preprocessor definitions
#define TA_IMPL
#define TA_HEADER "%-8s %15s %4s %4s %5s %5s %4s %6s %s\n"
#define TA_FORMAT "%-8s %15s %4d %4d %5.1f %5.1f %4d %6.3f %s\n"
GList* ta_list
pthread_mutex_t ta_mutex
Public adding function - adds the current thread to the list,
storing the given socket and type string along.
void TA_add ( int sock, char* type )
- int sock
- associated socket (if any, or 0 if not)
- char* type
- type string
Public deletion function - deletes the current thread from the list.
void TA_delete ( void )
increments the event counter for the current thread.
void TA_increment ( void )
resets the time and event counter of a specified thread.
void TA_reset_counters ( pthread_t thread_id )
- pthread_t thread_id
- thread_id
Public activity-setting function - sets the current activity string
for the current thread.
void TA_setactivity ( char* activity )
- char* activity
- new value
Public condat-setting function - associates a connection data
structure with the current thread.
void TA_setcondat ( sk_conn_st* condat )
- sk_conn_st* condat
- pointer to a connection data structure
Compiles a list of the threads' data records as text.
char* TA_tostring ( void )
- char* TA_tostring
- returns an allocated text, must be freed after use.
Finds a thread of the matching type, socket file descriptor and thread id
and executes the watchdog's triggers if it's defined.
void TA_trigger ( char* type, int sock, pthread_t thread_id )
- char* type
- thread type string
- int sock
- socket #
- pthread_t thread_id
- thread id
Finds a thread by thread_id, or creates a new entry if there isn't one.
Assumes locked list.
static ta_str_t* ta_findcreate_l ( GList** list, pthread_t thread_id )
- ta_str_t* ta_findcreate_l
- returns a pointer to the thread's record
- GList** list
- thread list
- pthread_t thread_id
- thread id
Finds a thread by thread_id. Assumes locked list.
static ta_str_t* ta_findonly_l ( GList** list, pthread_t thread_id )
- ta_str_t* ta_findonly_l
- returns a pointer to the thread's record
- GList** list
- thread list
- pthread_t thread_id
- thread id
prints a header for a list of threads to a specified buffer.
The output is truncated if the buffer is too small.
static void ta_print_header ( char* buf, unsigned length )
- char* buf
- pointer to the buffer
- unsigned length
- buffer size
Formats the data from one thread's record to an entry for a list of
threads. Prints to a specified buffer. Calculates the average time
spent per event as well as the lifetime of the thread. Checks the
address of the peer on the socket. The output is truncated if the
buffer is too small.
static void ta_printone_l ( ta_str_t* tas, char* buf, unsigned length, ut_timer_t* reftime )
- ta_str_t* tas
- pointer to the thread's record
- char* buf
- pointer to the buffer
- unsigned length
- buffer size
- ut_timer_t* reftime
- current time
finds and removes an entry for a thread given by thread_id.
Assumes locked list.
static void ta_remove_l ( GList** list, pthread_t thread_id )
- GList** list
- thread list
- pthread_t thread_id
- thread id
sets the activity field in the given thread's record.
Truncates the string if too long.
static void ta_setactivity_l ( ta_str_t* tas, char* activity )
- ta_str_t* tas
- pointer to the thread's record
- char* activity
- new value for the activity field