File ta/ta.c

  $Revision: 1.11 $

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 %4lu %5.1f %5.1f %4d %6.3f %s\n"


Global Variable Lock

pthread_mutex_t Lock
Included from /home/shane/code/RIP/include/ca_defs.h
Visible in:  aa/aa.c
   ac/access_control.c
   ca/ca_configFns.c
   ca/ca_initFn.c
   ca/ca_sanityCheck.c
   ca/ca_sourceLoader.c
   ca/ca_values.c
   co/constants.c
   df/defs.c
   er/er.c
   er/er_arrays.c
   er/er_macro.c
   er/er_paths.c
   er/er_print.c
   ip/ip.c
   ma/bitmask.c
   mm/mm.c
   nh/nh.c
   pa/gpg.c
   pa/spawn.c
   pc/pc_commands.c
   pc/protocol_config.c
   pm/pm_serials.c
   pm/protocol_mirror.c
   pr/properties.c
   pw/protocol_whois.c
   qc/mg_getopt.c
   qc/query_command.c
   qi/query_instructions.c
   rp/rp_convert.c
   rp/rp_load.c
   rp/rp_search.c
   rp/rp_tree.c
   rp/rp_update.c
   rx/rx_node.c
   rx/rx_print.c
   rx/rx_search.c
   rx/rx_tree.c
   sk/cd_socket.c
   sk/cd_watchdog.c
   sk/sk_socket.c
   sq/mysql_driver.c
   sv/server.c
   ta/ta.c
Used in: ca_get_adminIntElement()ca/ca_configFns.c
  ca_get_adminStrElement()ca/ca_configFns.c
  ca_get_boolean()ca/ca_configFns.c
  ca_get_dirlist()ca/ca_configFns.c
  ca_get_int()ca/ca_configFns.c
  ca_get_string()ca/ca_configFns.c
  ca_set_boolean()ca/ca_configFns.c
  ca_srchandle2Intelement()ca/ca_configFns.c
  ca_srchandle2Strelement()ca/ca_configFns.c

Global Variable ta_list

GList* ta_list
Included from /home/shane/code/RIP/include/ta.h
Visible in:  ta/ta.c
Used in: TA_add()ta/ta.c
  TA_delete()ta/ta.c
  TA_increment()ta/ta.c
  TA_reset_counters()ta/ta.c
  TA_setactivity()ta/ta.c
  TA_setcondat()ta/ta.c
  TA_tostring()ta/ta.c
  TA_trigger()ta/ta.c

Global Variable ta_mutex

pthread_mutex_t ta_mutex
Included from /home/shane/code/RIP/include/ta.h
Visible in:  ta/ta.c
Used in: TA_add()ta/ta.c
  TA_delete()ta/ta.c
  TA_increment()ta/ta.c
  TA_reset_counters()ta/ta.c
  TA_setactivity()ta/ta.c
  TA_setcondat()ta/ta.c
  TA_tostring()ta/ta.c
  TA_trigger()ta/ta.c

Global Function TA_add()

  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
Prototyped in: /home/shane/code/RIP/include/ta.h
Calls: ta_findcreate_l()ta/ta.c
  ta_setactivity_l()ta/ta.c
  UT_timeget(), pthread_mutex_lock(), pthread_mutex_unlock(), pthread_self(), snprintf()
Called by: AC_decay()ac/access_control.c
  PM_interact()pm/protocol_mirror.c
  RP_sql_load_reg()rp/rp_load.c
  SV_do_child()sv/server.c
  main_loop()sv/server.c
References Variables: ta_listta/ta.c
  ta_mutexta/ta.c

Global Function TA_delete()

  Public deletion function - deletes the current thread from the list.
void TA_delete ( void )
Prototyped in: /home/shane/code/RIP/include/ta.h
Calls: ta_remove_l()ta/ta.c
  pthread_mutex_lock(), pthread_mutex_unlock(), pthread_self()
Called by: AC_decay()ac/access_control.c
  PM_interact()pm/protocol_mirror.c
  RP_sql_load_reg()rp/rp_load.c
  SV_do_child()sv/server.c
  main_loop()sv/server.c
References Variables: ta_listta/ta.c
  ta_mutexta/ta.c

Global Function TA_increment()

   increments the event counter for the current thread.
void TA_increment ( void )
Prototyped in: /home/shane/code/RIP/include/ta.h
Calls: ta_findcreate_l()ta/ta.c
  UT_timeget(), pthread_mutex_lock(), pthread_mutex_unlock(), pthread_self()
Called by: PC_interact()pc/protocol_config.c
  PW_interact()pw/protocol_whois.c
  RP_sql_load_attr_space()rp/rp_load.c
  main_loop()sv/server.c
References Variables: ta_listta/ta.c
  ta_mutexta/ta.c

Global Function TA_reset_counters()

  resets the time and event counter of a specified thread.
void TA_reset_counters ( pthread_t thread_id )
pthread_t thread_id
thread_id
Prototyped in: /home/shane/code/RIP/include/ta.h
Calls: ta_findonly_l()ta/ta.c
  UT_timeget(), pthread_mutex_lock(), pthread_mutex_unlock()
References Variables: ta_listta/ta.c
  ta_mutexta/ta.c

Global Function TA_setactivity()

  Public activity-setting function - sets the current activity string
  for the current thread.
void TA_setactivity ( char* activity )
char* activity
new value
Prototyped in: /home/shane/code/RIP/include/ta.h
Calls: ta_findcreate_l()ta/ta.c
  ta_setactivity_l()ta/ta.c
  pthread_mutex_lock(), pthread_mutex_unlock(), pthread_self()
Called by: AC_decay()ac/access_control.c
  PC_interact()pc/protocol_config.c
  PM_interact()pm/protocol_mirror.c
  PW_interact()pw/protocol_whois.c
  RP_sql_load_attr_space()rp/rp_load.c
  main_loop()sv/server.c
References Variables: ta_listta/ta.c
  ta_mutexta/ta.c

Global Function TA_setcondat()

  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
Prototyped in: /home/shane/code/RIP/include/ta.h
Calls: ta_findcreate_l()ta/ta.c
  pthread_mutex_lock(), pthread_mutex_unlock(), pthread_self()
Called by: PW_interact()pw/protocol_whois.c
References Variables: ta_listta/ta.c
  ta_mutexta/ta.c

Global Function TA_tostring()

  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.
Prototyped in: /home/shane/code/RIP/include/ta.h
Calls: ta_print_header()ta/ta.c
  ta_printone_l()ta/ta.c
  UT_malloc_real(), UT_realloc_real(), UT_timeget(), g_list_first(), pthread_mutex_lock(), pthread_mutex_unlock(), strcat(), strcpy(), strlen()
Called by: show_threads()pc/pc_commands.c
References Variables: ta_listta/ta.c
  ta_mutexta/ta.c

Global Function TA_trigger()

  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
Prototyped in: /home/shane/code/RIP/include/ta.h
Calls: SK_watchtrigger()sk/cd_watchdog.c
  ta_findonly_l()ta/ta.c
  pthread_mutex_lock(), pthread_mutex_unlock(), strcmp()
References Variables: ta_listta/ta.c
  ta_mutexta/ta.c

Local Function asctime_r()

static char* asctime_r ( const struct tm* __tm, char* __buf )
Included from: /usr/include/time.h
Calls: __posix_asctime_r()

Local Function ctime_r()

static char* ctime_r ( const time_t* __time, char* __buf )
Included from: /usr/include/time.h
Calls: __posix_ctime_r()

Local Function getlogin_r()

static int getlogin_r ( char* __name, int __len )
Included from: /usr/include/unistd.h
Calls: __posix_getlogin_r()

Local Function readdir_r()

static int readdir_r ( DIR* __dp, struct dirent* __ent, struct dirent** __res )
Included from: /usr/include/dirent.h
Calls: __posix_readdir_r()

Local Function sigwait()

static int sigwait ( const sigset_t* __setp, int* __signo )
Included from: /usr/include/signal.h
Calls: __posix_sigwait()

Local Function ta_findcreate_l()

  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
Calls: ta_findonly_l()ta/ta.c
  UT_calloc_real(), g_list_append()
Called by: TA_add()ta/ta.c
  TA_increment()ta/ta.c
  TA_setactivity()ta/ta.c
  TA_setcondat()ta/ta.c

Local Function ta_findonly_l()

  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
Calls: g_list_first()
Called by: TA_reset_counters()ta/ta.c
  TA_trigger()ta/ta.c
  ta_findcreate_l()ta/ta.c

Local Function ta_print_header()

  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
Calls: snprintf()
Called by: TA_tostring()ta/ta.c

Local Function ta_printone_l()

  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
Calls: SK_getpeername()sk/sk_socket.c
  UT_free_real(), UT_timediff(), snprintf()
Called by: TA_tostring()ta/ta.c

Local Function ta_remove_l()

  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
Calls: g_list_first(), g_list_remove_link(), wr_real_clear_list()
Called by: TA_delete()ta/ta.c

Local Function ta_setactivity_l()

  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
Calls: strncpy(), strrchr()
Called by: TA_add()ta/ta.c
  TA_setactivity()ta/ta.c

Local Function ttyname_r()

static int ttyname_r ( int __fildes, char* __buf, size_t __size )
Included from: /usr/include/unistd.h
Calls: __posix_ttyname_r()