/* IBM_PROLOG_BEGIN_TAG */ /* This is an automatically generated prolog. */ /* */ /* bos720 src/bos/usr/samples/aacct/readaacct.c 1.6.3.1 */ /* */ /* Licensed Materials - Property of IBM */ /* */ /* Restricted Materials of IBM */ /* */ /* COPYRIGHT International Business Machines Corp. 2004,2012 */ /* All Rights Reserved */ /* */ /* US Government Users Restricted Rights - Use, duplication or */ /* disclosure restricted by GSA ADP Schedule Contract with IBM Corp. */ /* */ /* IBM_PROLOG_END_TAG */ static char sccsid[] = "@(#)76 1.6.3.1 src/bos/usr/samples/aacct/readaacct.c, cmdaacct, bos720 7/24/12 04:21:05"; #include #include #include #include #include #include #include #include #define NANO_SEC 1000000 #define NUM_SIZE 8 /* Size of num array */ #define UNDEFINED -1 /* Field not defined */ #define TWODIGIT 2 /* 2 digit year input*/ #define FOURDIGIT 4 /* 4 digit year input*/ #define SKIP 2 #define MIN_HH 00 /* Minimum value of hour */ #define MAX_HH 23 /* Maximum value of hour */ #define MIN_MM 00 /* Minimum value of minute */ #define MAX_MM 59 /* Maximum value of minute */ #define MIN_SS 00 /* Minimum value of second */ #define MAX_SS 61 /* Maximum value of second - accounts for leap second */ #define MIN_yy 00 /* Minimum value of 2 digit year */ #define MAX_yy 99 /* Maximum value of 2 digit year */ #define MIN_yyyy 1969 /* Minimum value of 4 digit year */ #define MAX_yyyy 2099 /* Maximum value of 4 digit year */ #define MIN_mm 00 /* Minimum value of month - zero based for mktime() */ #define MAX_mm 11 /* Maximum value of month - 0 is Jan & 11 is Dec */ #define MIN_dd 01 /* Minimum value of day */ #define PRINT_GLOBAL_WPAR 0 /* Print Global WPAR record */ #define PRINT_WPAR 1 /* Print WPAR record */ #define PRINT_ALL_REC 2 /* Print All record */ #define leapyr(A) (((A) % 4 == 0 && (A) % 100 != 0 || (A) % 400 == 0) ? 1 : 0) #define NUMBER(c1,c2) ( ((c1)-'0')*10 + ((c2)-'0') ) /* Maximum value of day for each month */ static char MAX_dd[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; static int filedesc ; static int tflg = 0, eflg = 0, bflg = 0, cflg = 0, hflg = 0, wparflg = 0, all_records = 0; static int trid=0; static char *wparname=NULL; unsigned long long max_file_offset ; unsigned long long begin_time = 0; unsigned long long end_time = 0; unsigned long long tran_time = 0; struct wlm_args wlm_args; void *ctx; int get_file_offset() ; int print_file_header (char *filename) ; int print_records () ; int print_w_records() ; int skip_file_header() ; int print_trans_header(struct aacct_tran_header *trans_header) ; int next_trans_record(struct aacct_tran_header *trans_header) ; int print_proc_trans_wrap(int) ; void print_proc_trans(struct tran_proc) ; void print_w_proc_trans(struct tran_w_proc) ; int print_agg_proc_trans_wrap(int) ; void print_agg_proc_trans(struct tran_agg_proc) ; void print_w_agg_proc_trans(struct tran_w_agg_proc) ; int print_agg_app_trans_wrap(int) ; void print_agg_app_trans(struct tran_agg_app) ; void print_w_agg_app_trans(struct tran_w_agg_app) ; int print_cpumem_trans_wrap(int) ; void print_cpumem_trans(struct tran_cpumem, int); void print_w_cpumem_trans(struct tran_w_cpumem) ; int print_policy_trans() ; int print_filesystem_trans_wrap(int) ; int print_filesystem_trans(struct tran_filesystem) ; int print_w_filesystem_trans(struct tran_w_filesystem) ; int print_netif_trans_wrap(int) ; void print_netif_trans(struct tran_netif) ; void print_w_netif_trans(struct tran_w_netif) ; int print_disk_trans() ; int print_lostdata_trans() ; int print_vscsi_target_trans() ; int print_vscsi_client_trans() ; int print_agg_ke_trans_wrap(int) ; void print_agg_ke_trans(struct tran_agg_ke) ; void print_w_agg_ke_trans(struct tran_w_agg_ke) ; int print_arm_applenv_trans() ; int print_arm_trenv_trans() ; int print_arm_trans() ; int print_agg_arm_trans() ; int print_project_trans(); unsigned long long parse_string(char *str); #define SKIP_CKEY_TO_NEXT_HEADER(x, y) { \ int ret_val = 0; \ int len = TRAN_HDR_SIZE + sizeof(y); \ ret_val = lseek(filedesc, ((x).tran_size - len), SEEK_CUR); \ if (ret_val < 0) \ return (ret_val); \ } void Usage() { printf("Usage : /usr/samples/aacct/readaacct [-F file ] [ -t trid ] [-b begin_time ] [-e end_time ] [-c] [-h] [-@ ]\n"); printf("-F file : Specify Accounting File\n"); printf("-t trid : Prints the details of the specific transaction ID\n"); printf("-b begin_time : Prints the transaction records collected on and after the time specified\n"); printf(" The date format should be MMddhhmmss\n"); printf("-e end_time : Prints the transaction records collected before the end time\n"); printf(" The date format should be MMddhhmmss\n"); printf("-c : Prints the records in colon separated format\n"); printf("-h : Prints the Accounting File Header\n"); printf("-@ : Prints the given WPAR specific transactions\n"); } int main(int argc, char *argv[]) { char choice ; int status = 0, rc = 0 ; char str[12]; char filename[255] = "/var/aacct/acctdata" ; while((choice = getopt(argc, argv, "cF:ht:b:e:@")) != (char) EOF) { switch(choice) { case 'F': strcpy(filename, optarg); break; case 'h': hflg++; break; case 'c': cflg++; break; case 't': tflg++; sscanf(optarg, "%d", &trid); break; case 'b': bflg++; strncpy(str, optarg, 10); str[10] = '\0'; begin_time=parse_string(str); if (begin_time == -1) { printf("Invalid time format\n"); exit(1); } break; case 'e': eflg++; strncpy(str, optarg, 10); str[10] = '\0'; end_time = parse_string(str); if (end_time == -1) { printf("Invalid time format\n"); exit(1); } break; case '@': wparflg++; wparname = strdup(argv[optind]); if (wparname[0] == '\0') all_records++; else optind++; break; case '?': Usage() ; exit(1) ; } } filedesc = open(filename , O_RDONLY) ; if(filedesc < 0) { perror("readaact") ; exit(1) ; } status = get_file_offset() ; if(status != 0) { close(filedesc) ; exit(2) ; } if (hflg) { status = print_file_header(filename) ; if(status != 0) { close(filedesc) ; exit(2) ; } } if (wlm_initialize(WLM_VERSION)) { perror("readaacct"); exit(1); } wlm_args.versflags=WLM_VERSION; strcpy(wlm_args.confdir, ""); if(wlm_initkey(&wlm_args, &ctx)) { perror("readaacct"); exit(1); } if (wparflg) { if (all_records) { status = print_all_records(); } else { status = print_w_records(); } if(status != 0) rc = 2; } else { status = print_records() ; if(status != 0) rc = 2; } close(filedesc); wlm_args.versflags=WLM_VERSION; if(wlm_endkey(&wlm_args, ctx)) { perror("readaacct"); exit(1); } exit(rc); } int get_file_offset() { struct acct_file_header file_header_buf ; int ret_val ; ret_val = read(filedesc, &file_header_buf, sizeof(struct acct_file_header)); if (ret_val != (sizeof(struct acct_file_header))) return(ret_val) ; max_file_offset = file_header_buf.afh_offset ; return 0 ; } int print_file_header(char *filename) { struct acct_file_header file_header_buf ; int ret_val ; ret_val = lseek(filedesc, 0, SEEK_SET) ; if (ret_val < 0) return(ret_val) ; ret_val = read(filedesc, &file_header_buf, sizeof(struct acct_file_header)); if (ret_val != (sizeof(struct acct_file_header))) return(ret_val) ; if (!cflg) { printf("File Name=%s\n",filename) ; printf("Version=%u\nFlags=%u\nOffset=%llu\n", file_header_buf.afh_version, file_header_buf.afh_flags, file_header_buf.afh_offset) ; printf("File Size=%llu\nState=%u\nID=%u\n", file_header_buf.afh_file_size, file_header_buf.afh_state, file_header_buf.afh_id) ; printf("First Time=%llu\nLast Time=%llu\n", file_header_buf.afh_time_first, file_header_buf.afh_time_last) ; printf("System ID=%s\nSystem Model=%s\nHost Name=%s\n", file_header_buf.afh_system_id, file_header_buf.afh_system_model, file_header_buf.afh_host_name); printf("Partition Name=%s\nPartition Number=%s\n", file_header_buf.afh_partition_name, file_header_buf.afh_partition_number); printf("--------------------------------------------------------------\n"); } else { printf("fname=%s:version=%u:flags=%u:offset=%llu:fsize=%llu:state=%u:id=%u:time_first=%llu" ":time_last=%llu:sysid=%s:sysmodel=%s:host_name=%s:partition_name=%s:partition_num=%s\n", filename, file_header_buf.afh_version, file_header_buf.afh_flags, file_header_buf.afh_offset, file_header_buf.afh_file_size, file_header_buf.afh_state, file_header_buf.afh_id, file_header_buf.afh_time_first, file_header_buf.afh_time_last, file_header_buf.afh_system_id, file_header_buf.afh_system_model, file_header_buf.afh_host_name, file_header_buf.afh_partition_name, file_header_buf.afh_partition_number); } return 0 ; } int print_records() { print_proc_trans_wrap(PRINT_GLOBAL_WPAR) ; print_agg_proc_trans_wrap(PRINT_GLOBAL_WPAR) ; print_agg_app_trans_wrap(PRINT_GLOBAL_WPAR) ; print_cpumem_trans_wrap(PRINT_GLOBAL_WPAR) ; print_policy_trans() ; print_filesystem_trans_wrap(PRINT_GLOBAL_WPAR) ; print_netif_trans_wrap(PRINT_GLOBAL_WPAR) ; print_disk_trans() ; print_lostdata_trans() ; print_vscsi_target_trans() ; print_vscsi_client_trans() ; print_agg_ke_trans_wrap(PRINT_GLOBAL_WPAR) ; print_arm_applenv_trans() ; print_arm_trenv_trans() ; print_arm_trans() ; print_agg_arm_trans() ; print_project_trans() ; return (0); } int print_w_records() { print_proc_trans_wrap(PRINT_WPAR) ; print_agg_proc_trans_wrap(PRINT_WPAR) ; print_agg_app_trans_wrap(PRINT_WPAR) ; print_cpumem_trans_wrap(PRINT_WPAR) ; print_filesystem_trans_wrap(PRINT_WPAR) ; print_netif_trans_wrap(PRINT_WPAR) ; print_agg_ke_trans_wrap(PRINT_WPAR) ; return (0); } int print_all_records() { print_proc_trans_wrap(PRINT_ALL_REC) ; print_agg_proc_trans_wrap(PRINT_ALL_REC) ; print_agg_app_trans_wrap(PRINT_ALL_REC) ; print_cpumem_trans_wrap(PRINT_ALL_REC) ; print_policy_trans() ; print_filesystem_trans_wrap(PRINT_ALL_REC) ; print_netif_trans_wrap(PRINT_ALL_REC) ; print_disk_trans() ; print_lostdata_trans() ; print_vscsi_target_trans() ; print_vscsi_client_trans() ; print_agg_ke_trans_wrap(PRINT_ALL_REC) ; print_arm_applenv_trans() ; print_arm_trenv_trans() ; print_arm_trans() ; print_agg_arm_trans() ; print_project_trans() ; return (0); } int print_proc_trans_wrap(int printopt) { struct aacct_tran_header trans_header ; struct tran_proc proc_trans; struct tran_w_proc w_proc_trans; int ret_val=0 ; unsigned long long cur_file_offset ; if (tflg && (trid != TRID_proc) && (trid != TRID_w_proc)) return; if (ret_val = skip_file_header()) return ret_val ; cur_file_offset = sizeof(struct acct_file_header) ; while(cur_file_offset < max_file_offset) { ret_val = read(filedesc, &trans_header, TRAN_HDR_SIZE) ; if (ret_val != TRAN_HDR_SIZE) { return(ret_val) ; } if ((trans_header.tran_id == TRID_proc) || (trans_header.tran_id == TRID_w_proc)) { if (bflg && begin_time > trans_header.tran_time) { if (ret_val = next_trans_record(&trans_header)) { return(ret_val) ; } cur_file_offset += trans_header.tran_size ; continue; } if (eflg && end_time < trans_header.tran_time) break; switch (printopt) { case PRINT_ALL_REC: case PRINT_GLOBAL_WPAR: if (trans_header.tran_id == TRID_proc) { if (tflg && trid != TRID_proc) { if (ret_val = next_trans_record(&trans_header)) { return(ret_val) ; } break; } ret_val = read(filedesc, &proc_trans,sizeof(struct tran_proc)) ; if (ret_val != (sizeof(struct tran_proc))) { return(ret_val) ; } if (trans_header.cor_flag) { /* Skip the ckey */ SKIP_CKEY_TO_NEXT_HEADER(trans_header, struct tran_proc); } print_trans_header(&trans_header); print_proc_trans(proc_trans); } else { if (printopt == PRINT_GLOBAL_WPAR) { if (ret_val = next_trans_record(&trans_header)) { return(ret_val) ; } break; } } case PRINT_WPAR: if (trans_header.tran_id == TRID_w_proc) { if (tflg && trid != TRID_w_proc) { if (ret_val = next_trans_record(&trans_header)) { return(ret_val) ; } break; } ret_val = read(filedesc, &w_proc_trans,sizeof(struct tran_w_proc)) ; if (ret_val != (sizeof(struct tran_w_proc))) { return(ret_val) ; } if (trans_header.cor_flag) { /* Skip the ckey */ SKIP_CKEY_TO_NEXT_HEADER(trans_header, struct tran_w_proc); } if(wparname[0] != '\0') { if (strcmp(w_proc_trans.trp_wparname, wparname)) { cur_file_offset += trans_header.tran_size ; break; } } print_trans_header(&trans_header); print_w_proc_trans(w_proc_trans); } else { if (printopt == PRINT_WPAR) { if (ret_val = next_trans_record(&trans_header)) { return(ret_val) ; } } } break; } } else { if (ret_val = next_trans_record(&trans_header)) { return(ret_val) ; } } cur_file_offset += trans_header.tran_size ; } } void print_proc_trans(struct tran_proc proc_trans) { char keyval[WLM_CLASSNAME_LENGTH*2+2]; wlm_args.versflags = WLM_VERSION|WLM_MUTE; if (!wlm_key2class(&wlm_args, proc_trans.trp_wlmkey, ctx)){ strcpy(keyval, wlm_args.cl_def.data.descr.name); } else sprintf(keyval, "%llu", proc_trans.trp_wlmkey); if (!cflg) { printf("\tProcess Transaction Instance\n") ; printf("\tUID=%u\n\tGID=%u\n\tPID=%u\n", proc_trans.trp_uid, proc_trans.trp_gid, proc_trans.trp_pid) ; printf("\teWLM Service Class=%d\n\tFlags=%d\n\tCommand Name=%s\n", proc_trans.trp_service_cl, proc_trans.trp_flags, proc_trans.trp_comm) ; printf("\tControlling Terminal's Device Number=%d,%d\n\tProcess Start Time=%llu\n\tWLM Class=%s\n", major64(proc_trans.trp_tty), minor64(proc_trans.trp_tty), proc_trans.trp_start, keyval) ; printf("\tIncrementing Statistics:\n"); printf("\tElapsed process time=%8.6lf seconds\n", (double) proc_trans.trp_counts.trp_count[0] / 1000000); printf("\tElapsed thread time=%8.6lf seconds\n", (double) proc_trans.trp_counts.trp_count[1] / 1000000); printf("\tProcess CPU time=%8.6lf seconds\n", (double) proc_trans.trp_counts.trp_count[2] / 1000000) ; printf("\tElapsed Page seconds of disk pages=%llu seconds\n", proc_trans.trp_counts.trp_count[3]); printf("\tElapsed Page seconds of real pages=%llu seconds\n", proc_trans.trp_counts.trp_count[4]); printf("\tElapsed Page seconds of virtual memory=%llu seconds\n", proc_trans.trp_counts.trp_count[5]); printf("\tBytes of local file I/O=%llu\n", proc_trans.trp_counts.trp_count[6]); printf("\tBytes of other file I/O=%llu\n", proc_trans.trp_counts.trp_count[7]); printf("\tBytes of local sockets=%llu\n", proc_trans.trp_counts.trp_count[8]); printf("\tBytes of remote sockets=%llu\n", proc_trans.trp_counts.trp_count[9]); printf("************************************************************\n"); } else { printf("uid=%u:gid=%u:pid=%u:serv_class=%d:flags=%d:cmd_name=%s:major_tty=%d" ":minor_tty=%d:time_start=%llu:wlmclass=%s:proc_time=%8.6lf:thd_time=%8.6lf" ":cpu_time=%8.6lf:disk_pg=%llu:real_pg=%llu:vmm=%llu:local_file=%llu" ":other_file=%llu:local_socket=%llu:remote_socket=%llu\n", proc_trans.trp_uid,proc_trans.trp_gid, proc_trans.trp_pid, proc_trans.trp_service_cl, proc_trans.trp_flags, proc_trans.trp_comm, major64(proc_trans.trp_tty), minor64(proc_trans.trp_tty), proc_trans.trp_start, keyval, (double) proc_trans.trp_counts.trp_count[0] / 1000000, (double) proc_trans.trp_counts.trp_count[1] / 1000000, (double) proc_trans.trp_counts.trp_count[2] / 1000000, proc_trans.trp_counts.trp_count[3], proc_trans.trp_counts.trp_count[4], proc_trans.trp_counts.trp_count[5], proc_trans.trp_counts.trp_count[6], proc_trans.trp_counts.trp_count[7], proc_trans.trp_counts.trp_count[8], proc_trans.trp_counts.trp_count[9]); } } void print_w_proc_trans(struct tran_w_proc w_proc_trans) { char keyval[WLM_CLASSNAME_LENGTH*2+2]; wlm_args.versflags = WLM_VERSION|WLM_MUTE; if (!wlm_key2class(&wlm_args, w_proc_trans.trp_wlmkey, ctx)){ strcpy(keyval, wlm_args.cl_def.data.descr.name); } else sprintf(keyval, "%llu", w_proc_trans.trp_wlmkey); if (!cflg) { printf("\tProcess Transaction Instance\n") ; printf("\tUID=%u\n\tGID=%u\n\tPID=%u\n", w_proc_trans.trp_uid, w_proc_trans.trp_gid, w_proc_trans.trp_pid) ; printf("\teWLM Service Class=%d\n\tFlags=%d\n\tCommand Name=%s\n", w_proc_trans.trp_service_cl, w_proc_trans.trp_flags, w_proc_trans.trp_comm) ; printf("\tControlling Terminal's Device Number=%d,%d\n\tProcess Start Time=%llu\n\tWLM Class=%s\n", major64(w_proc_trans.trp_tty), minor64(w_proc_trans.trp_tty), w_proc_trans.trp_start, keyval) ; printf("\tIncrementing Statistics:\n"); printf("\tElapsed process time=%8.6lf seconds\n", (double) w_proc_trans.trp_counts.trp_count[0] / 1000000); printf("\tElapsed thread time=%8.6lf seconds\n", (double) w_proc_trans.trp_counts.trp_count[1] / 1000000); printf("\tProcess CPU time=%8.6lf seconds\n", (double) w_proc_trans.trp_counts.trp_count[2] / 1000000) ; printf("\tElapsed Page seconds of disk pages=%llu seconds\n", w_proc_trans.trp_counts.trp_count[3]); printf("\tElapsed Page seconds of real pages=%llu seconds\n", w_proc_trans.trp_counts.trp_count[4]); printf("\tElapsed Page seconds of virtual memory=%llu seconds\n", w_proc_trans.trp_counts.trp_count[5]); printf("\tBytes of local file I/O=%llu\n", w_proc_trans.trp_counts.trp_count[6]); printf("\tBytes of other file I/O=%llu\n", w_proc_trans.trp_counts.trp_count[7]); printf("\tBytes of local sockets=%llu\n", w_proc_trans.trp_counts.trp_count[8]); printf("\tBytes of remote sockets=%llu\n", w_proc_trans.trp_counts.trp_count[9]); printf("\twparname=%s\n", w_proc_trans.trp_wparname); printf("************************************************************\n"); } else { printf("uid=%u:gid=%u:pid=%u:serv_class=%d:flags=%d:cmd_name=%s:major_tty=%d" ":minor_tty=%d:time_start=%llu:wlmclass=%s:proc_time=%8.6lf:thd_time=%8.6lf" ":cpu_time=%8.6lf:disk_pg=%llu:real_pg=%llu:vmm=%llu:local_file=%llu" ":other_file=%llu:local_socket=%llu:remote_socket=%llu:wparname=%s\n", w_proc_trans.trp_uid,w_proc_trans.trp_gid, w_proc_trans.trp_pid, w_proc_trans.trp_service_cl, w_proc_trans.trp_flags, w_proc_trans.trp_comm, major64(w_proc_trans.trp_tty), minor64(w_proc_trans.trp_tty), w_proc_trans.trp_start, keyval, w_proc_trans.trp_counts.trp_count[0], w_proc_trans.trp_counts.trp_count[1], w_proc_trans.trp_counts.trp_count[2], w_proc_trans.trp_counts.trp_count[3], w_proc_trans.trp_counts.trp_count[4], w_proc_trans.trp_counts.trp_count[5], w_proc_trans.trp_counts.trp_count[6], w_proc_trans.trp_counts.trp_count[7], w_proc_trans.trp_counts.trp_count[8], w_proc_trans.trp_counts.trp_count[9], w_proc_trans.trp_wparname); } } int print_agg_proc_trans_wrap(int printopt) { struct aacct_tran_header trans_header ; struct tran_agg_proc agg_proc_trans ; struct tran_w_agg_proc w_agg_proc_trans; int ret_val ; unsigned long long cur_file_offset ; if (tflg && (trid != TRID_agg_proc) && (trid != TRID_w_agg_proc)) return; if (ret_val = skip_file_header()) return ret_val ; cur_file_offset = sizeof(struct acct_file_header) ; while(cur_file_offset < max_file_offset) { ret_val = read(filedesc, &trans_header, TRAN_HDR_SIZE) ; if (ret_val != TRAN_HDR_SIZE) { return(ret_val) ; } if ((trans_header.tran_id == TRID_agg_proc) || (trans_header.tran_id == TRID_w_agg_proc)) { if (bflg && begin_time > trans_header.tran_time) { if (ret_val = next_trans_record(&trans_header)) { return(ret_val) ; } cur_file_offset += trans_header.tran_size ; continue; } if (eflg && end_time < trans_header.tran_time) break; switch ( printopt ) { case PRINT_ALL_REC: case PRINT_GLOBAL_WPAR: if (trans_header.tran_id == TRID_agg_proc) { if ( tflg && trid != TRID_agg_proc) { if (ret_val = next_trans_record(&trans_header)) { return(ret_val) ; } break; } ret_val = read(filedesc, &agg_proc_trans, sizeof(struct tran_agg_proc)) ; if (ret_val != (sizeof(struct tran_agg_proc))) { return(ret_val) ; } if (trans_header.cor_flag) { /* Skip the ckey */ SKIP_CKEY_TO_NEXT_HEADER(trans_header, struct tran_agg_proc); } print_trans_header(&trans_header); print_agg_proc_trans(agg_proc_trans); } else { if ( printopt == PRINT_GLOBAL_WPAR ) { if (ret_val = next_trans_record(&trans_header)) { return(ret_val) ; } break; } } case PRINT_WPAR: if (trans_header.tran_id == TRID_w_agg_proc) { if (tflg && trid != TRID_w_agg_proc) { if (ret_val = next_trans_record(&trans_header)) { return(ret_val) ; } break; } ret_val = read(filedesc, &w_agg_proc_trans, sizeof(struct tran_w_agg_proc)) ; if (ret_val != (sizeof(struct tran_w_agg_proc))) { return(ret_val) ; } if (trans_header.cor_flag) { /* Skip the ckey */ SKIP_CKEY_TO_NEXT_HEADER(trans_header, struct tran_w_agg_proc); } if(wparname[0] != '\0') { if (strcmp(w_agg_proc_trans.trp_wparname, wparname)) { cur_file_offset += trans_header.tran_size ; break; } } print_trans_header(&trans_header); print_w_agg_proc_trans(w_agg_proc_trans); } else { if ( printopt == PRINT_WPAR ) { if (ret_val = next_trans_record(&trans_header)) { return(ret_val) ; } } } } } else { if (ret_val = next_trans_record(&trans_header)) { return(ret_val) ; } } cur_file_offset += trans_header.tran_size ; } } void print_agg_proc_trans(struct tran_agg_proc agg_proc_trans) { if (!cflg) { printf("\tAggregated Process Transaction Instance\n") ; printf("\tStart Time=%llu\n\tUID=%u\n\tNo. of processes aggregated=%u\n", agg_proc_trans.trp_start, agg_proc_trans.trp_uid, agg_proc_trans.trp_procs) ; printf("\tIncrementing Statistics:\n"); printf("\tElapsed process time=%8.6lf seconds\n", (double) agg_proc_trans.trp_counts.trp_count[0] / 1000000); printf("\tElapsed thread time=%8.6lf seconds\n", (double) agg_proc_trans.trp_counts.trp_count[1] / 1000000); printf("\tProcess CPU time=%8.6lf seconds\n", (double) agg_proc_trans.trp_counts.trp_count[2] / 1000000); printf("\tElapsed Page seconds of disk pages=%llu seconds\n", agg_proc_trans.trp_counts.trp_count[3]); printf("\tElapsed Page seconds of real pages=%llu seconds\n", agg_proc_trans.trp_counts.trp_count[4]); printf("\tElapsed Page seconds of virtual memory=%llu seconds\n", agg_proc_trans.trp_counts.trp_count[5]); printf("\tBytes of local file I/O=%llu\n", agg_proc_trans.trp_counts.trp_count[6]); printf("\tBytes of other file I/O=%llu\n", agg_proc_trans.trp_counts.trp_count[7]); printf("\tBytes of local sockets=%llu\n", agg_proc_trans.trp_counts.trp_count[8]); printf("\tBytes of remote sockets=%llu\n", agg_proc_trans.trp_counts.trp_count[9]); printf("************************************************************\n"); } else { printf("time_start=%llu:uid=%u:num_proc=%u:proc_time=%8.6lf:thd_time=%8.6lf" ":cpu_time=%8.6lf:disk_pg=%llu:real_pg=%llu:vmm=%llu:local_file=%llu" ":other_file=%llu:local_socket=%llu:remote_socket=%llu\n", agg_proc_trans.trp_start, agg_proc_trans.trp_uid, agg_proc_trans.trp_procs, (double)agg_proc_trans.trp_counts.trp_count[0]/1000000, (double)agg_proc_trans.trp_counts.trp_count[1]/1000000, (double)agg_proc_trans.trp_counts.trp_count[2]/1000000, agg_proc_trans.trp_counts.trp_count[3], agg_proc_trans.trp_counts.trp_count[4], agg_proc_trans.trp_counts.trp_count[5], agg_proc_trans.trp_counts.trp_count[6], agg_proc_trans.trp_counts.trp_count[7], agg_proc_trans.trp_counts.trp_count[8], agg_proc_trans.trp_counts.trp_count[9]); } } void print_w_agg_proc_trans(struct tran_w_agg_proc w_agg_proc_trans) { if (!cflg) { printf("\tAggregated Process Transaction Instance\n") ; printf("\tStart Time=%llu\n\tUID=%u\n\tNo. of processes aggregated=%u\n", w_agg_proc_trans.trp_start, w_agg_proc_trans.trp_uid, w_agg_proc_trans.trp_procs) ; printf("\tIncrementing Statistics:\n"); printf("\tElapsed process time=%8.6lf seconds\n", (double) w_agg_proc_trans.trp_counts.trp_count[0] / 1000000); printf("\tElapsed thread time=%8.6lf seconds\n", (double) w_agg_proc_trans.trp_counts.trp_count[1] / 1000000); printf("\tProcess CPU time=%8.6lf seconds\n", (double) w_agg_proc_trans.trp_counts.trp_count[2] / 1000000); printf("\tElapsed Page seconds of disk pages=%llu seconds\n", w_agg_proc_trans.trp_counts.trp_count[3]); printf("\tElapsed Page seconds of real pages=%llu seconds\n", w_agg_proc_trans.trp_counts.trp_count[4]); printf("\tElapsed Page seconds of virtual memory=%llu seconds\n", w_agg_proc_trans.trp_counts.trp_count[5]); printf("\tBytes of local file I/O=%llu\n", w_agg_proc_trans.trp_counts.trp_count[6]); printf("\tBytes of other file I/O=%llu\n", w_agg_proc_trans.trp_counts.trp_count[7]); printf("\tBytes of local sockets=%llu\n", w_agg_proc_trans.trp_counts.trp_count[8]); printf("\tBytes of remote sockets=%llu\n", w_agg_proc_trans.trp_counts.trp_count[9]); printf("\twparname=%s\n", w_agg_proc_trans.trp_wparname); printf("************************************************************\n"); } else { printf("time_start=%llu:uid=%u:num_proc=%u:proc_time=%8.6lf:thd_time=%8.6lf" ":cpu_time=%8.6lf:disk_pg=%llu:real_pg=%llu:vmm=%llu:local_file=%llu" ":other_file=%llu:local_socket=%llu:remote_socket=%llu:wparname=%s\n", w_agg_proc_trans.trp_start, w_agg_proc_trans.trp_uid, w_agg_proc_trans.trp_procs, w_agg_proc_trans.trp_counts.trp_count[0], w_agg_proc_trans.trp_counts.trp_count[1], w_agg_proc_trans.trp_counts.trp_count[2], w_agg_proc_trans.trp_counts.trp_count[3], w_agg_proc_trans.trp_counts.trp_count[4], w_agg_proc_trans.trp_counts.trp_count[5], w_agg_proc_trans.trp_counts.trp_count[6], w_agg_proc_trans.trp_counts.trp_count[7], w_agg_proc_trans.trp_counts.trp_count[8], w_agg_proc_trans.trp_counts.trp_count[9], w_agg_proc_trans.trp_wparname); } } int print_agg_app_trans_wrap(int printopt) { struct aacct_tran_header trans_header ; struct tran_agg_app agg_app_trans ; struct tran_w_agg_app w_agg_app_trans; int ret_val, i ; unsigned long long cur_file_offset ; if (tflg && (trid != TRID_agg_app) && (trid != TRID_w_agg_app)) { return; } if (ret_val = skip_file_header()) return ret_val ; cur_file_offset = sizeof(struct acct_file_header) ; while(cur_file_offset < max_file_offset) { ret_val = read(filedesc, &trans_header, TRAN_HDR_SIZE) ; if (ret_val != TRAN_HDR_SIZE) { return(ret_val) ; } if ((trans_header.tran_id == TRID_agg_app) || (trans_header.tran_id == TRID_w_agg_app) ) { if (bflg && begin_time > trans_header.tran_time) { if (ret_val = next_trans_record(&trans_header)) { return(ret_val) ; } cur_file_offset += trans_header.tran_size ; continue; } if (eflg && end_time < trans_header.tran_time) break; switch ( printopt ) { case PRINT_ALL_REC: case PRINT_GLOBAL_WPAR: if (trans_header.tran_id == TRID_agg_app) { if (tflg && trid != TRID_agg_app) { if (ret_val = next_trans_record(&trans_header)) { return(ret_val) ; } break; } ret_val = read(filedesc, &agg_app_trans, sizeof(struct tran_agg_app)); if (ret_val != (sizeof(struct tran_agg_app))) { return(ret_val) ; } if (trans_header.cor_flag) { /* Skip the ckey */ SKIP_CKEY_TO_NEXT_HEADER(trans_header, struct tran_agg_app); } print_trans_header(&trans_header); print_agg_app_trans(agg_app_trans); } else { if (printopt == PRINT_GLOBAL_WPAR) { if (ret_val = next_trans_record(&trans_header)) { return(ret_val) ; } break; } } case PRINT_WPAR: if (trans_header.tran_id == TRID_w_agg_app) { if ( tflg && trid != TRID_w_agg_app) { if (ret_val = next_trans_record(&trans_header)) { return(ret_val) ; } break; } ret_val = read(filedesc, &w_agg_app_trans, sizeof(struct tran_w_agg_app)); if (ret_val != (sizeof(struct tran_w_agg_app))) { return(ret_val) ; } if (trans_header.cor_flag) { /* Skip the ckey */ SKIP_CKEY_TO_NEXT_HEADER(trans_header, struct tran_w_agg_app); } if(wparname[0] != '\0') { if (strcmp(w_agg_app_trans.trp_wparname, wparname)) { cur_file_offset += trans_header.tran_size ; break; } } print_trans_header(&trans_header); print_w_agg_app_trans(w_agg_app_trans); } else { if (printopt == PRINT_WPAR) { if (ret_val = next_trans_record(&trans_header)) { return(ret_val); } } } break; } } else { if (ret_val = next_trans_record(&trans_header)) { return(ret_val) ; } } cur_file_offset += trans_header.tran_size ; } } void print_agg_app_trans(struct tran_agg_app agg_app_trans) { if (!cflg) { printf("\tAggregated Application Transaction Instance\n") ; printf("\tStart Time=%llu\n\tUID=%u\n\tAggregated Invocations=%u\n", agg_app_trans.trp_start, agg_app_trans.trp_uid, agg_app_trans.trp_commands) ; printf("\tDevice No. for command=%llu\n\tInode for command=%llu\n", agg_app_trans.trp_dev, agg_app_trans.trp_ino) ; printf("\tIncrementing Statistics:\n"); printf("\tElapsed process time=%8.6lf seconds\n", (double) agg_app_trans.trp_counts.trp_count[0] / 1000000); printf("\tElapsed thread time=%8.6lf seconds\n", (double) agg_app_trans.trp_counts.trp_count[1] / 1000000); printf("\tProcess CPU time=%8.6lf seconds\n", (double) agg_app_trans.trp_counts.trp_count[2] / 1000000); printf("\tElapsed Page seconds of disk pages=%llu seconds\n", agg_app_trans.trp_counts.trp_count[3]); printf("\tElapsed Page seconds of real pages=%llu seconds\n", agg_app_trans.trp_counts.trp_count[4]); printf("\tElapsed Page seconds of virtual memory=%llu seconds\n", agg_app_trans.trp_counts.trp_count[5]); printf("\tBytes of local file I/O=%llu\n", agg_app_trans.trp_counts.trp_count[6]); printf("\tBytes of other file I/O=%llu\n", agg_app_trans.trp_counts.trp_count[7]); printf("\tBytes of local sockets=%llu\n", agg_app_trans.trp_counts.trp_count[8]); printf("\tBytes of remote sockets=%llu\n", agg_app_trans.trp_counts.trp_count[9]); printf("************************************************************\n"); } else { printf("time_start=%llu:uid=%u:num_cmds=%u:dev=%llu:inode=%llu", agg_app_trans.trp_start, agg_app_trans.trp_uid, agg_app_trans.trp_commands, agg_app_trans.trp_dev, agg_app_trans.trp_ino); printf(":proc_time=%8.6lf:thd_time=%8.6lf:cpu_time=%8.6lf:disk_pg=%llu:real_pg=%llu" ":vmm=%llu:local_file=%llu:other_file=%llu:local_socket=%llu:remote_socket=%llu\n", (double)agg_app_trans.trp_counts.trp_count[0]/1000000, (double)agg_app_trans.trp_counts.trp_count[1]/1000000, (double)agg_app_trans.trp_counts.trp_count[2]/1000000, agg_app_trans.trp_counts.trp_count[3], agg_app_trans.trp_counts.trp_count[4], agg_app_trans.trp_counts.trp_count[5], agg_app_trans.trp_counts.trp_count[6], agg_app_trans.trp_counts.trp_count[7], agg_app_trans.trp_counts.trp_count[8], agg_app_trans.trp_counts.trp_count[9]); } } void print_w_agg_app_trans(struct tran_w_agg_app w_agg_app_trans) { if (!cflg) { printf("\tAggregated Application Transaction Instance\n") ; printf("\tStart Time=%llu\n\tUID=%u\n\tAggregated Invocations=%u\n", w_agg_app_trans.trp_start, w_agg_app_trans.trp_uid, w_agg_app_trans.trp_commands) ; printf("\tDevice No. for command=%llu\n\tInode for command=%llu\n", w_agg_app_trans.trp_dev, w_agg_app_trans.trp_ino) ; printf("\tIncrementing Statistics:\n"); printf("\tElapsed process time=%8.6lf seconds\n", (double) w_agg_app_trans.trp_counts.trp_count[0] / 1000000); printf("\tElapsed thread time=%8.6lf seconds\n", (double) w_agg_app_trans.trp_counts.trp_count[1] / 1000000); printf("\tProcess CPU time=%8.6lf seconds\n", (double) w_agg_app_trans.trp_counts.trp_count[2] / 1000000); printf("\tElapsed Page seconds of disk pages=%llu seconds\n", w_agg_app_trans.trp_counts.trp_count[3]); printf("\tElapsed Page seconds of real pages=%llu seconds\n", w_agg_app_trans.trp_counts.trp_count[4]); printf("\tElapsed Page seconds of virtual memory=%llu seconds\n", w_agg_app_trans.trp_counts.trp_count[5]); printf("\tBytes of local file I/O=%llu\n", w_agg_app_trans.trp_counts.trp_count[6]); printf("\tBytes of other file I/O=%llu\n", w_agg_app_trans.trp_counts.trp_count[7]); printf("\tBytes of local sockets=%llu\n", w_agg_app_trans.trp_counts.trp_count[8]); printf("\tBytes of remote sockets=%llu\n", w_agg_app_trans.trp_counts.trp_count[9]); printf("\twparname=%s\n", w_agg_app_trans.trp_wparname); printf("************************************************************\n"); } else { printf("time_start=%llu:uid=%u:num_cmds=%u:dev=%llu:inode=%llu", w_agg_app_trans.trp_start, w_agg_app_trans.trp_uid, w_agg_app_trans.trp_commands, w_agg_app_trans.trp_dev, w_agg_app_trans.trp_ino); printf(":proc_time=%8.6lf:thd_time=%8.6lf:cpu_time=%8.6lf:disk_pg=%llu:real_pg=%llu" ":vmm=%llu:local_file=%llu:other_file=%llu:local_socket=%llu:remote_socket=%llu:wparname=%s\n", w_agg_app_trans.trp_counts.trp_count[0], w_agg_app_trans.trp_counts.trp_count[1], w_agg_app_trans.trp_counts.trp_count[2], w_agg_app_trans.trp_counts.trp_count[3], w_agg_app_trans.trp_counts.trp_count[4], w_agg_app_trans.trp_counts.trp_count[5], w_agg_app_trans.trp_counts.trp_count[6], w_agg_app_trans.trp_counts.trp_count[7], w_agg_app_trans.trp_counts.trp_count[8], w_agg_app_trans.trp_counts.trp_count[9], w_agg_app_trans.trp_wparname); } } int print_cpumem_trans_wrap(int printopt) { struct aacct_tran_header trans_header ; struct tran_cpumem cpumem_trans ; struct tran_w_cpumem w_cpumem_trans; int ret_val ; unsigned long long cur_file_offset ; int is_V3 = 0, delta; if (tflg && (trid != TRID_cpumem) && (trid != TRID_w_cpumem)) { return; } if (ret_val = skip_file_header()) return ret_val ; cur_file_offset = sizeof(struct acct_file_header) ; while(cur_file_offset < max_file_offset) { ret_val = read(filedesc, &trans_header, TRAN_HDR_SIZE) ; if (ret_val != TRAN_HDR_SIZE) { return(ret_val) ; } if ((trans_header.tran_id == TRID_cpumem) || (trans_header.tran_id == TRID_w_cpumem)) { if (bflg && begin_time > trans_header.tran_time) { if (ret_val = next_trans_record(&trans_header)) { return(ret_val) ; } cur_file_offset += trans_header.tran_size ; continue; } if (eflg && end_time < trans_header.tran_time) break; switch(printopt) { case PRINT_ALL_REC: case PRINT_GLOBAL_WPAR: if (trans_header.tran_id == TRID_cpumem) { if (tflg && trid != TRID_cpumem) { if (ret_val = next_trans_record(&trans_header)) { return(ret_val); } break; } delta = 0; is_V3 = !((TRAN_cpumem_V1(&trans_header)) ||(TRAN_cpumem_V2(&trans_header))); if (trans_header.cor_flag) delta = sizeof(ckey_t); ret_val = read(filedesc, &cpumem_trans, trans_header.tran_size - TRAN_HDR_SIZE - delta); if (ret_val != (trans_header.tran_size - TRAN_HDR_SIZE -delta)) { return(ret_val) ; } /* skip the ckey */ ret_val = lseek(filedesc, delta, SEEK_CUR); if (ret_val < 0) return (ret_val); print_trans_header(&trans_header); print_cpumem_trans(cpumem_trans,is_V3); } else { if (printopt == PRINT_GLOBAL_WPAR) { if (ret_val = next_trans_record(&trans_header)) { return(ret_val) ; } break; } } case PRINT_WPAR: if (trans_header.tran_id == TRID_w_cpumem) { if (tflg && trid != TRID_w_cpumem) { if (ret_val = next_trans_record(&trans_header)) { return(ret_val); } break; } ret_val = read(filedesc, &w_cpumem_trans, sizeof(struct tran_w_cpumem)); if (ret_val != (sizeof(struct tran_w_cpumem))) { return(ret_val) ; } if (trans_header.cor_flag) { /* Skip the ckey */ SKIP_CKEY_TO_NEXT_HEADER(trans_header, struct tran_w_cpumem); } if(wparname[0] != '\0') { if (strcmp(w_cpumem_trans.wparname, wparname)) { cur_file_offset += trans_header.tran_size ; break; } } print_trans_header(&trans_header); print_w_cpumem_trans(w_cpumem_trans); } else { if (printopt == PRINT_WPAR) { if (ret_val = next_trans_record(&trans_header)) { return(ret_val); } } } break; } } else { if (ret_val = next_trans_record(&trans_header)) { return(ret_val) ; } } cur_file_offset += trans_header.tran_size ; } } void print_cpumem_trans(struct tran_cpumem cpumem_trans, int is_V3) { if (!cflg) { printf("\tCPU Memory Transaction Instance\n") ; printf("\tRecord Type=%u\n\tNo. of CPUs=%u\n\tProcessor Entitled Capacity=%u\n", cpumem_trans.rec_type, cpumem_trans.ncpus, cpumem_trans.entitled_cap) ; printf("\tIdle Time=%llu\n\tI/O Wait Time=%llu\n\tKernel Process Time=%llu\n" "\tUser Process Time=%llu\n", cpumem_trans.idle_time, cpumem_trans.iowait_time, cpumem_trans.sprocess_time, cpumem_trans.uprocess_time) ; printf("\tInterrupt Time=%llu\n\tMemory Size=%llu\n\tTotal Large Pages=%llu\n", cpumem_trans.interrupt_time, cpumem_trans.memory_size, cpumem_trans.lgpg_total) ; printf("\tLarge Page In use=%llu\n\tNo. of page ins=%u\n\tNo. of Page outs=%u\n", cpumem_trans.lgpg_inuse, cpumem_trans.pgsp_ins, cpumem_trans.pgsp_outs) ; printf("\tNo. of I/Os=%u\n\tNo. of page steals=%u\n\tElapsed Time=%llu\n", cpumem_trans.num_ios, cpumem_trans.page_steals, cpumem_trans.elapsed) ; if(is_V3) printf("\tPhysical Memory In use=%llu\n\tI/O Entitled Capacity=%llu\n" "\tI/O Entitlement In use=%llu\n", cpumem_trans.phys_mem_pgsec, cpumem_trans.ent_mem_capacity, cpumem_trans.ent_mem_pgsec) ; printf("************************************************************\n"); } else { printf("rec_type=%u:ncpus=%u:cpu_entitled_cap=%u:idle_time=%llu:i/o_wait_time=%llu" ":kernel_process_time=%llu:uproc_time=%llu" ":intr_time=%llu:mem_size=%llu:lgpg_total=%llu:lgpg_inuse=%llu:pgsp_ins=%u" ":pgsp_outs=%u:num_ios=%u:page_steals=%u:elapsed_time=%llu", cpumem_trans.rec_type, cpumem_trans.ncpus, cpumem_trans.entitled_cap, cpumem_trans.idle_time, cpumem_trans.iowait_time, cpumem_trans.sprocess_time, cpumem_trans.uprocess_time, cpumem_trans.interrupt_time, cpumem_trans.memory_size, cpumem_trans.lgpg_total, cpumem_trans.lgpg_inuse, cpumem_trans.pgsp_ins, cpumem_trans.pgsp_outs, cpumem_trans.num_ios, cpumem_trans.page_steals, cpumem_trans.elapsed); if(is_V3) printf(":phy_mem_inuse=%llu:i/o_entitled_cap=%llu:i/o_ent_inuse=%llu", cpumem_trans.phys_mem_pgsec, cpumem_trans.ent_mem_capacity, cpumem_trans.ent_mem_pgsec); printf("\n"); } } void print_w_cpumem_trans(struct tran_w_cpumem w_cpumem_trans) { if (!cflg) { printf("\tCPU Memory Transaction Instance\n") ; printf("\tRecord Type=%u\n\tNo. of CPUs=%u\n\tEntitled Capacity=%u\n", w_cpumem_trans.rec_type, w_cpumem_trans.ncpus, w_cpumem_trans.entitled_cap) ; printf("\tIdle Time=%llu\n\tI/O Wait Time=%llu\n\tKernel Process Time=%llu\n" "\tUser Process Time=%llu\n", w_cpumem_trans.idle_time, w_cpumem_trans.iowait_time, w_cpumem_trans.sprocess_time, w_cpumem_trans.uprocess_time) ; printf("\tInterrupt Time=%llu\n\tMemory Size=%llu\n\tTotal Large Pages=%llu\n", w_cpumem_trans.interrupt_time, w_cpumem_trans.memory_size, w_cpumem_trans.lgpg_total) ; printf("\tLarge Page In use=%llu\n\tNo. of page ins=%u\n\tNo. of Page outs=%u\n", w_cpumem_trans.lgpg_inuse, w_cpumem_trans.pgsp_ins, w_cpumem_trans.pgsp_outs) ; printf("\tNo. of I/Os=%u\n\tNo. of page steals=%u\n\tElapsed Time=%llu\n" "\twparname=%s\n", w_cpumem_trans.num_ios, w_cpumem_trans.page_steals, w_cpumem_trans.elapsed, w_cpumem_trans.wparname) ; printf("************************************************************\n"); } else { printf("rec_type=%u:ncpus=%u:entitled_cap=%u:idle_time=%llu:i/o_wait_time=%llu" ":kernel_process_time=%llu:uproc_time=%llu" ":intr_time=%llu:mem_size=%llu:lgpg_total=%llu:lgpg_inuse=%llu:pgsp_ins=%u" ":pgsp_outs=%u:num_ios=%u:page_steals=%u:elapsed_time=%llu:wparname=%s\n", w_cpumem_trans.rec_type, w_cpumem_trans.ncpus, w_cpumem_trans.entitled_cap, w_cpumem_trans.idle_time, w_cpumem_trans.iowait_time, w_cpumem_trans.sprocess_time, w_cpumem_trans.uprocess_time, w_cpumem_trans.interrupt_time, w_cpumem_trans.memory_size, w_cpumem_trans.lgpg_total, w_cpumem_trans.lgpg_inuse, w_cpumem_trans.pgsp_ins, w_cpumem_trans.pgsp_outs, w_cpumem_trans.num_ios, w_cpumem_trans.page_steals, w_cpumem_trans.elapsed, w_cpumem_trans.wparname); } } int print_project_trans() { struct aacct_tran_header trans_header ; struct tran_project proj_tran; int ret_val ; unsigned long long cur_file_offset ; struct proj_rec *projp; char *projstrt; int i, dsize, first; if (tflg && trid != TRID_project) return; if (ret_val = skip_file_header()) return ret_val ; cur_file_offset = sizeof(struct acct_file_header) ; while(cur_file_offset < max_file_offset) { ret_val = read(filedesc, &trans_header, TRAN_HDR_SIZE) ; if (ret_val != TRAN_HDR_SIZE) { return(ret_val) ; } if (trans_header.tran_id == TRID_project) { if (bflg && begin_time > trans_header.tran_time) { if (ret_val = next_trans_record(&trans_header)) return(ret_val); cur_file_offset += trans_header.tran_size ; continue; } if (eflg && end_time < trans_header.tran_time) break; ret_val = read(filedesc, &proj_tran, sizeof(struct tran_project)); if (ret_val != (sizeof(struct tran_project))) return(ret_val) ; print_trans_header(&trans_header); dsize = proj_tran.size - sizeof(struct tran_project); projp = (struct proj_rec *)malloc(dsize); if (projp == NULL) return -1; projstrt = (char *)projp; ret_val = read(filedesc, projp, dsize); if (ret_val != dsize) { free(projp); return(ret_val); } /* ckey will be placed at the end of the transaction data for wpars.If we are reading the transaction record of wpar then we have to skip the size of corral key(that is 4 bytes) to go to next record(i,e file descriptor will be advanced to next transaction record) */ if (trans_header.cor_flag) { int len; len = TRAN_HDR_SIZE + proj_tran.size; len = trans_header.tran_size - len; lseek(filedesc, len, SEEK_CUR); } first = TRUE; for (i = 0; i < proj_tran.nproj; projp++, i++) { if (!cflg) { if (!first) printf(" "); printf("\tProject Transaction Instance\n") ; printf("\tProject ID=%d\n\tProject Origin=%d\n\tOffset=%s\n", projp->projid, projp->origin, projstrt + projp->offset); printf("************************************************************"); } else { if (!first) printf(":"); printf("projid=%d:origin=%d:offset=%s", projp->projid, projp->origin, projstrt + projp->offset); } first = FALSE; } printf("\n"); free(projp); } else { if (ret_val = next_trans_record(&trans_header)) return(ret_val) ; } cur_file_offset += trans_header.tran_size ; } } int print_policy_trans() { struct aacct_tran_header trans_header ; struct tran_policy policy_tran; int ret_val ; unsigned long long cur_file_offset ; if (tflg && trid != TRID_policy) return; if (ret_val = skip_file_header()) return ret_val ; cur_file_offset = sizeof(struct acct_file_header) ; while(cur_file_offset < max_file_offset) { ret_val = read(filedesc, &trans_header, TRAN_HDR_SIZE) ; if (ret_val != TRAN_HDR_SIZE) { return(ret_val) ; } if (trans_header.tran_id == TRID_policy) { if (bflg && begin_time > trans_header.tran_time) { if (ret_val = next_trans_record(&trans_header)) return(ret_val); cur_file_offset += trans_header.tran_size ; continue; } if (eflg && end_time < trans_header.tran_time) break; ret_val = read(filedesc, &policy_tran, sizeof(struct tran_policy)); if (ret_val != (sizeof(struct tran_policy))) return(ret_val) ; if (trans_header.cor_flag) { /* Skip the ckey */ SKIP_CKEY_TO_NEXT_HEADER(trans_header, struct tran_policy); } print_trans_header(&trans_header); if (!cflg) { printf("\tPolicy Transaction Instance\n") ; printf("\tType=%u\n\tEvent=%u\n", policy_tran.type, policy_tran.event); printf("************************************************************\n"); } else printf("type=%u:event=%u\n", policy_tran.type, policy_tran.event); } else { if (ret_val = next_trans_record(&trans_header)) return(ret_val) ; } cur_file_offset += trans_header.tran_size ; } return (0) ; } int print_filesystem_trans_wrap(int printopt) { struct aacct_tran_header trans_header ; struct tran_filesystem filesystem_trans ; struct tran_w_filesystem w_filesystem_trans; int ret_val ; unsigned long long cur_file_offset ; char *devname,*mountpt; int len = 0; if (tflg && (trid != TRID_file) && (trid != TRID_w_file)) { return; } if (ret_val = skip_file_header()) return ret_val ; cur_file_offset = sizeof(struct acct_file_header) ; while(cur_file_offset < max_file_offset) { ret_val = read(filedesc, &trans_header, TRAN_HDR_SIZE) ; if (ret_val != TRAN_HDR_SIZE) { return(ret_val) ; } if ( (trans_header.tran_id == TRID_file) || (trans_header.tran_id == TRID_w_file)) { if (bflg && begin_time > trans_header.tran_time) { if (ret_val = next_trans_record(&trans_header)) { return(ret_val) ; } cur_file_offset += trans_header.tran_size ; continue; } if (eflg && end_time < trans_header.tran_time) break; switch(printopt) { case PRINT_ALL_REC: case PRINT_GLOBAL_WPAR: if (trans_header.tran_id == TRID_file) { if (tflg && trid != TRID_file) { if (ret_val = next_trans_record(&trans_header)) { return(ret_val); } break; } ret_val = read(filedesc, &filesystem_trans, sizeof(struct tran_filesystem)); if (ret_val != (sizeof(struct tran_filesystem))) { return(ret_val) ; } print_trans_header(&trans_header) ; if( ret_val = print_filesystem_trans(filesystem_trans)) { return(ret_val); } if (trans_header.cor_flag) { /* Skip the ckey */ len = TRAN_HDR_SIZE + sizeof(struct tran_filesystem) + filesystem_trans.devname_len + filesystem_trans.mntptr_len; len = trans_header.tran_size - len; lseek(filedesc, len, SEEK_CUR); } } else { if (printopt == PRINT_GLOBAL_WPAR) { if (ret_val = next_trans_record(&trans_header)) { return(ret_val); } break; } } case PRINT_WPAR: if (trans_header.tran_id == TRID_w_file) { if (tflg && trid != TRID_w_file) { if (ret_val = next_trans_record(&trans_header)) { return(ret_val); } break; } ret_val = read(filedesc, &w_filesystem_trans, sizeof(struct tran_w_filesystem)); if (ret_val != (sizeof(struct tran_w_filesystem))) { return(ret_val) ; } if(wparname[0] != '\0') { if (strcmp(w_filesystem_trans.wparname, wparname)) { devname=(char *)malloc((w_filesystem_trans.devname_len)+1); mountpt=(char *)malloc((w_filesystem_trans.mntptr_len)+1); if (devname == 0 || mountpt == 0) { perror("malloc"); return -1; } read(filedesc,devname,w_filesystem_trans.devname_len); devname[w_filesystem_trans.devname_len]='\0'; read(filedesc,mountpt,w_filesystem_trans.mntptr_len); mountpt[w_filesystem_trans.mntptr_len]='\0'; cur_file_offset += trans_header.tran_size ; free(devname); free(mountpt); break; } } print_trans_header(&trans_header) ; if(ret_val = print_w_filesystem_trans(w_filesystem_trans)) { return(ret_val); } if (trans_header.cor_flag) { /* Skip the ckey */ len = TRAN_HDR_SIZE + sizeof(struct tran_w_filesystem) + w_filesystem_trans.devname_len + w_filesystem_trans.mntptr_len; len = trans_header.tran_size - len; lseek(filedesc, len, SEEK_CUR); } } else { if (printopt == PRINT_WPAR) { if (ret_val = next_trans_record(&trans_header)) { return(ret_val); } } } break; } } else { if (ret_val = next_trans_record(&trans_header)) { return(ret_val) ; } } cur_file_offset += trans_header.tran_size ; } } int print_filesystem_trans(struct tran_filesystem filesystem_trans ) { char *devname,*mountpt; if (!cflg) { printf("\tFilesystem Transaction Instance\n") ; printf("\tNo. of bytes transferred=%llu\n\tNo. of read/write=%llu\n\tNo. of Opens=%llu\n", filesystem_trans.DbytesTrans, filesystem_trans.DnumRdWrs, filesystem_trans.DnumOpens) ; printf("\tNo. of creates=%llu\n\tNo. of locks=%llu\n\tFile system type=%u\n", filesystem_trans.DnumCreates, filesystem_trans.DnumLocks, filesystem_trans.Dfstype) ; printf("\tDevice name length=%d\n\tMount point length=%d\n", filesystem_trans.devname_len, filesystem_trans.mntptr_len); } else { printf("bytes_xfer=%llu:bytes_rw=%llu:num_opens=%llu:num_creates=%llu:num_locks=%llu" ":fs_type=%u:dev_len=%d:mount_pt_len=%d:", filesystem_trans.DbytesTrans, filesystem_trans.DnumRdWrs, filesystem_trans.DnumOpens, filesystem_trans.DnumCreates, filesystem_trans.DnumLocks, filesystem_trans.Dfstype, filesystem_trans.devname_len, filesystem_trans.mntptr_len); } devname=(char *)malloc((filesystem_trans.devname_len)+1); mountpt=(char *)malloc((filesystem_trans.mntptr_len)+1); if (devname == 0 || mountpt == 0) { perror("malloc"); return -1; } if ((read(filedesc,devname,filesystem_trans.devname_len)) < 0) { perror("read"); return -1; } devname[filesystem_trans.devname_len]='\0'; if ((read(filedesc,mountpt,filesystem_trans.mntptr_len)) < 0) { perror("read"); return -1; } mountpt[filesystem_trans.mntptr_len]='\0'; if (!cflg) { printf("\tDevice Name=%s\n\tMount Point=%s\n",devname,mountpt); printf("************************************************************\n"); } else { printf("dev_name=%s:mount_point=%s\n", devname,mountpt); } free(devname); free(mountpt); return(0); } int print_w_filesystem_trans(struct tran_w_filesystem w_filesystem_trans) { int ret_val ; char *devname,*mountpt; if (!cflg) { printf("\tFilesystem Transaction Instance\n") ; printf("\tNo. of bytes transferred=%llu\n\tNo. of read/write=%llu\n\tNo. of Opens=%llu\n", w_filesystem_trans.DbytesTrans, w_filesystem_trans.DnumRdWrs, w_filesystem_trans.DnumOpens) ; printf("\tNo. of creates=%llu\n\tNo. of locks=%llu\n\tFile system type=%u\n", w_filesystem_trans.DnumCreates, w_filesystem_trans.DnumLocks, w_filesystem_trans.Dfstype) ; printf("\tDevice name length=%d\n\tMount point length=%d\n", w_filesystem_trans.devname_len, w_filesystem_trans.mntptr_len); } else { printf("bytes_xfer=%llu:bytes_rw=%llu:num_opens=%llu:num_creates=%llu:num_locks=%llu" ":fs_type=%u:dev_len=%d:mount_pt_len=%d:", w_filesystem_trans.DbytesTrans, w_filesystem_trans.DnumRdWrs, w_filesystem_trans.DnumOpens, w_filesystem_trans.DnumCreates, w_filesystem_trans.DnumLocks, w_filesystem_trans.Dfstype, w_filesystem_trans.devname_len, w_filesystem_trans.mntptr_len); } devname=(char *)malloc((w_filesystem_trans.devname_len)+1); mountpt=(char *)malloc((w_filesystem_trans.mntptr_len)+1); if (devname == 0 || mountpt == 0) { perror("malloc"); return -1; } if ((read(filedesc,devname,w_filesystem_trans.devname_len)) < 0) { perror("read"); return -1; } devname[w_filesystem_trans.devname_len]='\0'; if ((read(filedesc,mountpt,w_filesystem_trans.mntptr_len)) < 0) { perror("read"); return -1; } mountpt[w_filesystem_trans.mntptr_len]='\0'; if (!cflg) { printf("\tDevice Name=%s\n\tMount Point=%s\n\twparname=%s\n",devname,mountpt,w_filesystem_trans.wparname); printf("************************************************************\n"); } else { printf("dev_name=%s:mount_point=%s:wparname=%s\n", devname,mountpt,w_filesystem_trans.wparname); } free(devname); free(mountpt); return(0); } int print_netif_trans_wrap(int printopt) { struct aacct_tran_header trans_header ; struct tran_netif netif_trans ; struct tran_w_netif w_netif_trans; int ret_val ; unsigned long long cur_file_offset ; if (tflg && (trid != TRID_netif)&& (trid != TRID_w_netif)) { return; } if (ret_val = skip_file_header()) return ret_val ; cur_file_offset = sizeof(struct acct_file_header) ; while(cur_file_offset < max_file_offset) { ret_val = read(filedesc, &trans_header, TRAN_HDR_SIZE) ; if (ret_val != TRAN_HDR_SIZE) { return(ret_val) ; } if ((trans_header.tran_id == TRID_netif) || (trans_header.tran_id == TRID_w_netif)) { if (bflg && begin_time > trans_header.tran_time) { if (ret_val = next_trans_record(&trans_header)) { return(ret_val) ; } cur_file_offset += trans_header.tran_size ; continue; } if (eflg && end_time < trans_header.tran_time) break; switch(printopt) { case PRINT_ALL_REC: case PRINT_GLOBAL_WPAR: if (trans_header.tran_id == TRID_netif) { if (tflg && trid != TRID_netif) { if (ret_val = next_trans_record(&trans_header)) { return(ret_val); } break; } ret_val = read(filedesc, &netif_trans, sizeof(struct tran_netif)) ; if (ret_val != (sizeof(struct tran_netif))) { return(ret_val) ; } if (trans_header.cor_flag) { /* Skip the ckey */ SKIP_CKEY_TO_NEXT_HEADER(trans_header, struct tran_netif); } print_trans_header(&trans_header); print_netif_trans(netif_trans); } else { if (printopt == PRINT_GLOBAL_WPAR) { if (ret_val = next_trans_record(&trans_header)) { return(ret_val); } break; } } case PRINT_WPAR: if (trans_header.tran_id == TRID_w_netif) { if (tflg && trid != TRID_w_netif) { if (ret_val = next_trans_record(&trans_header)) { return(ret_val); } break; } ret_val = read(filedesc, &w_netif_trans, sizeof(struct tran_w_netif)) ; if (ret_val != (sizeof(struct tran_w_netif))) { return(ret_val) ; } if (trans_header.cor_flag) { /* Skip the ckey */ SKIP_CKEY_TO_NEXT_HEADER(trans_header, struct tran_w_netif); } if(wparname[0] != '\0') { if (strcmp(w_netif_trans.wparname, wparname)) { cur_file_offset += trans_header.tran_size ; break; } } print_trans_header(&trans_header); print_w_netif_trans(w_netif_trans); } else { if (printopt == PRINT_WPAR) { if (ret_val = next_trans_record(&trans_header)) { return(ret_val); } } } break; } } else { if (ret_val = next_trans_record(&trans_header)) { return(ret_val) ; } } cur_file_offset += trans_header.tran_size ; } } void print_netif_trans(struct tran_netif netif_trans) { if (!cflg) { printf("\tNetwork Interface Transaction Instance\n") ; printf("\tInterface Name=%s\n\tNo. of I/Os=%lld\n\tNo. of bytes=%lld\n", netif_trans.netif_name, netif_trans.nios, netif_trans.nbytes) ; printf("************************************************************\n"); } else { printf("netif_name=%s:num_ios=%lld:num_bytes=%lld\n", netif_trans.netif_name, netif_trans.nios, netif_trans.nbytes); } } void print_w_netif_trans(struct tran_w_netif w_netif_trans) { if (!cflg) { printf("\tNetwork Interface Transaction Instance\n") ; printf("\tInterface Name=%s\n\tNo. of I/Os=%lld\n\tNo. of bytes=%lld\n\twparname=%s\n", w_netif_trans.netif_name, w_netif_trans.nios, w_netif_trans.nbytes, w_netif_trans.wparname) ; printf("************************************************************\n"); } else { printf("netif_name=%s:num_ios=%lld:num_bytes=%lld:wparname=%s\n", w_netif_trans.netif_name, w_netif_trans.nios, w_netif_trans.nbytes, w_netif_trans.wparname); } } int print_disk_trans() { struct aacct_tran_header trans_header ; struct tran_disk disk_trans ; int ret_val ; unsigned long long cur_file_offset ; if (tflg && trid != TRID_disk) return; if (ret_val = skip_file_header()) return ret_val ; cur_file_offset = sizeof(struct acct_file_header) ; while(cur_file_offset < max_file_offset) { ret_val = read(filedesc, &trans_header, TRAN_HDR_SIZE) ; if (ret_val != TRAN_HDR_SIZE) { return(ret_val) ; } if (trans_header.tran_id == TRID_disk) { if (bflg && begin_time > trans_header.tran_time) { if (ret_val = next_trans_record(&trans_header)) { return(ret_val) ; } cur_file_offset += trans_header.tran_size ; continue; } if (eflg && end_time < trans_header.tran_time) break; ret_val = read(filedesc, &disk_trans, sizeof(struct tran_disk)) ; if (ret_val != (sizeof(struct tran_disk))) { return(ret_val) ; } if (trans_header.cor_flag) { /* Skip the ckey */ SKIP_CKEY_TO_NEXT_HEADER(trans_header, struct tran_disk); } print_trans_header(&trans_header); if (!cflg) { printf("\tDisk Transaction Instance\n") ; printf("\tTotal transfers=%llu\n\tTotal read blocks=%llu\n\tTotal write blocks=%llu\n", disk_trans.total_xfers, disk_trans.total_rblks, disk_trans.total_wblks) ; printf("\tBlock size=%u\n\tDisk Name=%s\n", disk_trans.blk_size, disk_trans.diskname) ; printf("************************************************************\n"); } else { printf("xfers=%llu:rblks=%llu:wblks=%llu:blk_size=%u:disk_name=%s\n", disk_trans.total_xfers, disk_trans.total_rblks, disk_trans.total_wblks, disk_trans.blk_size, disk_trans.diskname); } } else { if (ret_val = next_trans_record(&trans_header)) return(ret_val) ; } cur_file_offset += trans_header.tran_size ; } } int print_lostdata_trans() { struct aacct_tran_header trans_header ; struct tran_lostdata lostdata_trans ; int ret_val ; unsigned long long cur_file_offset ; if (tflg && trid != TRID_lostdata) return; if (ret_val = skip_file_header()) return ret_val ; cur_file_offset = sizeof(struct acct_file_header) ; while(cur_file_offset < max_file_offset) { ret_val = read(filedesc, &trans_header, TRAN_HDR_SIZE) ; if (ret_val != TRAN_HDR_SIZE) { return(ret_val) ; } if (trans_header.tran_id == TRID_lostdata) { if (bflg && begin_time > trans_header.tran_time) { if (ret_val = next_trans_record(&trans_header)) { return(ret_val) ; } cur_file_offset += trans_header.tran_size ; continue; } if (eflg && end_time < trans_header.tran_time) break; ret_val = read(filedesc, &lostdata_trans, sizeof(struct tran_lostdata)) ; if (ret_val != (sizeof(struct tran_lostdata))) { return(ret_val) ; } if (trans_header.cor_flag) { /* Skip the ckey */ SKIP_CKEY_TO_NEXT_HEADER(trans_header, struct tran_lostdata); } print_trans_header(&trans_header); if (!cflg) { printf("\tLost Data Transaction Instance\n") ; printf("\tNo. of lost transactions=%d\n\tlost process CPU time=%8.6lf seconds\n" "\ttime data loss began=%8.6lf seconds\n" "\tLost kernel Ext CPU time=%8.6lf seconds\n", lostdata_trans.trl_lost_recs, lostdata_trans.trl_lost_cpu / 1000000, lostdata_trans.trl_lost_start / 1000000, lostdata_trans.trl_lost_KEcpu / 1000000); printf("************************************************************\n"); } else { printf("lost_recs=%d:lost_cpu=%8.6lf:lost_start=%8.6lf:lost_KEcpu=%8.16lf\n", lostdata_trans.trl_lost_recs, lostdata_trans.trl_lost_cpu, lostdata_trans.trl_lost_start, lostdata_trans.trl_lost_KEcpu); } } else { if (ret_val = next_trans_record(&trans_header)) return(ret_val) ; } cur_file_offset += trans_header.tran_size ; } } int print_agg_arm_trans() { struct aacct_tran_header trans_header ; struct tran_agg_arm tran ; int ret_val ; unsigned long long cur_file_offset ; off_t tran_start; if (tflg && trid != TRID_agg_arm) return; if (ret_val = skip_file_header()) return ret_val ; cur_file_offset = sizeof(struct acct_file_header) ; while(cur_file_offset < max_file_offset) { ret_val = read(filedesc, &trans_header, TRAN_HDR_SIZE) ; if (ret_val != TRAN_HDR_SIZE) { return(ret_val) ; } if (trans_header.tran_id == TRID_agg_arm) { if (bflg && begin_time > trans_header.tran_time) { if (ret_val = next_trans_record(&trans_header)) { return(ret_val) ; } cur_file_offset += trans_header.tran_size ; continue; } if (eflg && end_time < trans_header.tran_time) break; tran_start = lseek(filedesc, 0, SEEK_CUR); ret_val = read(filedesc, &tran, sizeof(tran)); if (ret_val != (sizeof(tran))) { return(ret_val) ; } if (trans_header.cor_flag) { /* Skip the ckey */ SKIP_CKEY_TO_NEXT_HEADER(trans_header, struct tran_agg_arm); } print_trans_header(&trans_header); if (!cflg) { printf("\tAggregated ARM Instance\n"); printf("\tVersion=%u\n", tran.ag_version) ; printf("\tCompletion Status=%x\n", tran.ag_rc) ; printf("\tStart Time in Seconds=%llu\n", tran.ag_start) ; printf("\tApplication Environment id=%llx\n", tran.ag_aeid) ; printf("\tTransaction Environment id=%llx\n", tran.ag_teid) ; } else { printf("version=%u:status=%x:stime=%llu:aeid=%x:teid=%x", tran.ag_version, tran.ag_rc, tran.ag_start, tran.ag_aeid, tran.ag_teid) ; } if (tran.ag_uid == 0) { if (!cflg) printf("\tUID Not Provided\n"); else printf(":uid=") ; } else { struct tran_arm_id tran_id; ret_val = lseek(filedesc, tran_start + tran.ag_uid, SEEK_SET); if (ret_val != (tran_start + tran.ag_uid)) return (ret_val) ; ret_val = read(filedesc, &tran_id, sizeof(struct tran_arm_id)); if (ret_val != sizeof(struct tran_arm_id)) return (ret_val) ; if (!cflg) printf("\tUser Identifier=%.16s\n", tran_id.id_u.c) ; else printf(":uid=%.16s", tran_id.id_u.c) ; } if (tran.ag_uname == 0) { if (!cflg) printf("\tUname Not Provided\n"); else printf(":uname=") ; } else { struct tran_arm_string tran_name; char uname[512]; int i, j; ret_val = lseek(filedesc, tran_start + tran.ag_uname, SEEK_SET); if (ret_val != (tran_start + tran.ag_uname)) return (ret_val) ; ret_val = read(filedesc, &tran_name, sizeof(struct tran_arm_string)); if (ret_val != sizeof(struct tran_arm_string)) return (ret_val) ; /* The string tran_name.ts_string has every alternate character * as '\0' starting from the very first character. We must get * rid of these extra characters before proceeding ahead. */ for (i = 0, j = 0; j < tran_name.ts_len; j++) if (tran_name.ts_string[j] != '\0') uname[i++] = tran_name.ts_string[j]; uname[i] = '\0'; if (!cflg) printf("\tUser Name=%s\n", uname) ; else printf(":uname=%s", uname) ; } if (tran.ag_acct == 0) { if (!cflg) printf("\tAcct Class Not Provided\n"); else printf(":acct_class=") ; } else { struct tran_arm_string tran_acct; char acct[512]; int i, j; ret_val = lseek(filedesc, tran_start + tran.ag_acct, SEEK_SET); if (ret_val != (tran_start + tran.ag_acct)) return (ret_val) ; ret_val = read(filedesc, &tran_acct, sizeof(struct tran_arm_string)); if (ret_val != sizeof(struct tran_arm_string)) return (ret_val) ; /* The string tran_acct.ts_string has every alternate character * as '\0' starting from the very first character. We must get * rid of these extra characters before proceeding ahead. */ for (i = 0, j = 0; j < tran_acct.ts_len; j++) if (tran_acct.ts_string[j] != '\0') acct[i++] = tran_acct.ts_string[j]; acct[i] = '\0'; if (!cflg) printf("\tAccount Class=%s\n", acct) ; else printf(":acct_class=%s", acct) ; } if (!cflg) { printf("\tResponse Time=%u(milliseconds)\n", tran.ag_response ) ; printf("\tQueued Time=%u(milliseconds)\n", tran.ag_queued) ; printf("\tNumber of Records Aggregated=%u\n", tran.ag_count) ; printf("\tCPU Time=%llu(uSeconds)\n ", tran.ag_util.tu_cpu) ; printf("************************************************************\n"); } else { printf(":res_time=%x:q_time=%x:count=%u:cpu_time=%llu\n", tran.ag_response, tran.ag_queued, tran.ag_count, tran.ag_util.tu_cpu) ; } ret_val = lseek(filedesc, cur_file_offset+trans_header.tran_size, SEEK_SET); if (ret_val != (cur_file_offset+trans_header.tran_size)) return (ret_val) ; } else { if (ret_val = next_trans_record(&trans_header)) return(ret_val) ; } cur_file_offset += trans_header.tran_size ; } } int print_arm_trans() { struct aacct_tran_header trans_header ; struct tran_arm_tran tran ; int ret_val ; unsigned long long cur_file_offset ; off_t tran_start; if (tflg && trid != TRID_arm_tran) return; if (ret_val = skip_file_header()) return ret_val ; cur_file_offset = sizeof(struct acct_file_header) ; while(cur_file_offset < max_file_offset) { ret_val = read(filedesc, &trans_header, TRAN_HDR_SIZE) ; if (ret_val != TRAN_HDR_SIZE) { return(ret_val) ; } if (trans_header.tran_id == TRID_arm_tran) { if (bflg && begin_time > trans_header.tran_time) { if (ret_val = next_trans_record(&trans_header)) { return(ret_val) ; } cur_file_offset += trans_header.tran_size ; continue; } if (eflg && end_time < trans_header.tran_time) break; tran_start = lseek(filedesc, 0, SEEK_CUR); ret_val = read(filedesc, &tran, sizeof(tran)); if (ret_val != (sizeof(tran))) { return(ret_val) ; } if (trans_header.cor_flag) { /* Skip the ckey */ SKIP_CKEY_TO_NEXT_HEADER(trans_header, struct tran_arm_tran); } print_trans_header(&trans_header); if (!cflg) { printf("\tARM Instance\n"); printf("\tVersion=%d\n", tran.tri_version) ; printf("\tCompletion Status=%x\n", tran.tri_rc) ; printf("\tApplication Environment id=%llx\n", tran.tri_aeid) ; printf("\tTransaction Environment id=%llx\n", tran.tri_teid) ; } else { printf("version=%d:status=%x:aeid=%x:teid=%x", tran.tri_version, tran.tri_rc, tran.tri_aeid, tran.tri_teid) ; } if (tran.tri_uid == 0) { if (!cflg) printf("\tUID Not Provided\n"); else printf(":uid=") ; } else { struct tran_arm_id tran_id; ret_val = lseek(filedesc, tran_start + tran.tri_uid, SEEK_SET); if (ret_val != (tran_start + tran.tri_uid)) return (ret_val) ; ret_val = read(filedesc, &tran_id, sizeof(struct tran_arm_id)); if (ret_val != sizeof(struct tran_arm_id)) return (ret_val) ; if (!cflg) printf("\tUID=%.16s\n", tran_id.id_u.c) ; else printf(":uid=%.16s", tran_id.id_u.c) ; } if (tran.tri_uname == 0) { if (!cflg) printf("\tUname Not Provided\n"); else printf(":uname=") ; } else { struct tran_arm_string tran_name; char uname[512]; int i, j; ret_val = lseek(filedesc, tran_start + tran.tri_uname, SEEK_SET); if (ret_val != (tran_start + tran.tri_uname)) return (ret_val) ; ret_val = read(filedesc, &tran_name, sizeof(struct tran_arm_string)); if (ret_val != sizeof(struct tran_arm_string)) return (ret_val) ; /* The string tran_name.ts_string has every alternate character * as '\0' starting from the very first character. We must get * rid of these extra characters before proceeding ahead. */ for (i = 0, j = 0; j < tran_name.ts_len; j++) if (tran_name.ts_string[j] != '\0') uname[i++] = tran_name.ts_string[j]; uname[i] = '\0'; if (!cflg) printf("\tUser Name=%s\n", uname) ; else printf(":uname=%s", uname) ; } if (tran.tri_acct == 0) { if (!cflg) printf("\tAcct Class Not Provided\n"); else printf(":acct_class=") ; } else { struct tran_arm_string tran_acct; char acct[512]; int i, j; ret_val = lseek(filedesc, tran_start + tran.tri_acct, SEEK_SET); if (ret_val != (tran_start + tran.tri_acct)) return (ret_val) ; ret_val = read(filedesc, &tran_acct, sizeof(struct tran_arm_string)); if (ret_val != sizeof(struct tran_arm_string)) return (ret_val) ; /* The string tran_acct.ts_string has every alternate character * as '\0' starting from the very first character. We must get * rid of these extra characters before proceeding ahead. */ for (i = 0, j = 0; j < tran_acct.ts_len; j++) if (tran_acct.ts_string[j] != '\0') acct[i++] = tran_acct.ts_string[j]; acct[i] = '\0'; if (!cflg) printf("\tAcct Class=%s\n", acct) ; else printf(":acct_class=%s", acct) ; } if (!cflg) { printf("\tResponse Time=%u Queue Time=%u (milliseconds)\n", tran.tri_response, tran.tri_queued) ; printf("\tCPU Time=%llu (uSeconds)\n ", tran.tri_util.tu_cpu) ; printf("************************************************************\n"); } else { printf(":res_time=%x:q_time=%x:cpu_time=%llu\n", tran.tri_response, tran.tri_queued, tran.tri_util.tu_cpu) ; } ret_val = lseek(filedesc, cur_file_offset+trans_header.tran_size, SEEK_SET); if (ret_val != (cur_file_offset+trans_header.tran_size)) return (ret_val) ; } else { if (ret_val = next_trans_record(&trans_header)) return(ret_val) ; } cur_file_offset += trans_header.tran_size ; } } int print_arm_trenv_trans() { struct aacct_tran_header trans_header ; struct tran_arm_trenv tran ; int ret_val ; unsigned long long cur_file_offset ; off_t tran_start; if (tflg && trid != TRID_arm_trenv) return; if (ret_val = skip_file_header()) return ret_val ; cur_file_offset = sizeof(struct acct_file_header) ; while(cur_file_offset < max_file_offset) { ret_val = read(filedesc, &trans_header, TRAN_HDR_SIZE) ; if (ret_val != TRAN_HDR_SIZE) { return(ret_val) ; } if (trans_header.tran_id == TRID_arm_trenv) { if (bflg && begin_time > trans_header.tran_time) { if (ret_val = next_trans_record(&trans_header)) { return(ret_val) ; } cur_file_offset += trans_header.tran_size ; continue; } if (eflg && end_time < trans_header.tran_time) break; tran_start = lseek(filedesc, 0, SEEK_CUR); ret_val = read(filedesc, &tran, sizeof(tran)); if (ret_val != (sizeof(tran))) { return(ret_val) ; } if (trans_header.cor_flag) { /* Skip the ckey */ SKIP_CKEY_TO_NEXT_HEADER(trans_header, struct tran_arm_trenv); } print_trans_header(&trans_header); if (!cflg) { printf("\tARM Transaction Environment\n"); printf("\tVersion=%d\n", tran.tr_version) ; printf("\tCharacter Set for Strings=%d\n", tran.tr_charset) ; printf("\tTransaction Environment id=%llx\n", tran.tr_id) ; } else { printf("version=%d:charset=%d:teid=%x", tran.tr_version, tran.tr_charset, tran.tr_id) ; } if (tran.tr_name == 0) { if (!cflg) printf("\tName Not Provided\n"); else printf(":tran_name=") ; } else { struct tran_arm_string tran_name; char tname[512]; int j; char c; ret_val = lseek(filedesc, tran_start + tran.tr_name, SEEK_SET); if (ret_val != (tran_start + tran.tr_name)) return (ret_val) ; if (tran.tr_charset == ACCT_ARM_ASCII || tran.tr_charset == ACCT_ARM_UTF8) { ret_val = read(filedesc, &tran_name, sizeof(struct tran_arm_string)); if (ret_val != sizeof(struct tran_arm_string)) return (ret_val) ; } else if (tran.tr_charset == ACCT_ARM_UTF16) { ret_val = read (filedesc, &tran_name.ts_len, sizeof(unsigned short)); if (ret_val != sizeof(unsigned short)) return (ret_val); for (j = 0; j < (tran_name.ts_len / 2); j++) { read (filedesc,(void *)&c,sizeof(char)); read (filedesc, (void *)&c, sizeof(char)); tran_name.ts_string[j] = (char)c; } tran_name.ts_string[tran_name.ts_len / 2] = '\0'; } snprintf(tname, tran_name.ts_len, "%s", tran_name.ts_string); if (!cflg) printf("\tTransaction Name=%s\n", tname) ; else printf(":tran_name=%s", tname) ; } if (tran.tr_iprop == 0) { if (!cflg) printf("\tIdentity Properties Not Provided\n"); else { printf(":id_prop=") ; printf(":id_pname=") ; printf(":id_pval=") ; } } else { struct tran_arm_properties props; char acct[512]; ret_val = lseek(filedesc, tran_start + tran.tr_iprop, SEEK_SET); if (ret_val != (tran_start + tran.tr_iprop)) return (ret_val) ; tran_start = ret_val; ret_val = read(filedesc, &props, sizeof(props)) ; if (ret_val != sizeof(props)) return (ret_val) ; if (!cflg) printf("\tTotal Identity Properties=%d\n", props.tp_cnt) ; else printf(":id_prop=%d", props.tp_cnt) ; if (props.tp_cnt) { struct tran_arm_string tnv; char nv[512]; int i; int j; char c; for (i=0; i trans_header.tran_time) { if (ret_val = next_trans_record(&trans_header)) { return(ret_val) ; } cur_file_offset += trans_header.tran_size ; continue; } if (eflg && end_time < trans_header.tran_time) break; tran_start = lseek(filedesc, 0, SEEK_CUR); ret_val = read(filedesc, &tran, sizeof(tran)); if (ret_val != (sizeof(tran))) { return(ret_val) ; } if (trans_header.cor_flag) { /* Skip the ckey */ SKIP_CKEY_TO_NEXT_HEADER(trans_header, struct tran_arm_applenv); } print_trans_header(&trans_header); if (!cflg) { printf("\tARM Application Environment\n"); printf("\tVersion=%d\n", tran.ap_version) ; printf("\tCharacter Set for Strings=%d\n", tran.ap_charset) ; printf("\tApplication Environment id=%llx\n", tran.ap_id) ; } else { printf("version=%d:charset=%d:aeid=%x", tran.ap_version, tran.ap_charset, tran.ap_id) ; } if (tran.ap_name == 0) { if (!cflg) printf("\tName Not Provided\n"); else printf(":appl_name=") ; } else { struct tran_arm_string tran_name; char tname[512]; int j; char c; ret_val = lseek(filedesc, tran_start + tran.ap_name, SEEK_SET); if (ret_val != (tran_start + tran.ap_name)) return (ret_val) ; /* * Check if the character set is ACCT_ARM_ASCII or * ACCT_ARM_UTF8 if so read tran_name directly * else if the character set is * ACCT_ARM_UTF16, striff off the null characteers * from the string to get the actual value. */ if (tran.ap_charset == ACCT_ARM_ASCII || tran.ap_charset == ACCT_ARM_UTF8) { ret_val = read(filedesc, &tran_name, sizeof(struct tran_arm_string)); if (ret_val != sizeof(struct tran_arm_string)) return (ret_val) ; } else if (tran.ap_charset == ACCT_ARM_UTF16) { ret_val = read (filedesc, &tran_name.ts_len, sizeof(unsigned short)); if (ret_val != sizeof(unsigned short)) return (ret_val); for (j = 0; j < (tran_name.ts_len / 2); j++) { read (filedesc,(void *)&c,sizeof(char)); read (filedesc, (void *)&c, sizeof(char)); tran_name.ts_string[j] = (char)c; } tran_name.ts_string[tran_name.ts_len / 2] = '\0'; } snprintf(tname, tran_name.ts_len, "%s", tran_name.ts_string); if (!cflg) printf("\tApplication Name=%s\n", tname) ; else printf(":appl_name=%s", tname) ; } if (tran.ap_group == 0) { if (!cflg) printf("\tGroup Name Not Provided\n"); else printf(":group_name=") ; } else { struct tran_arm_string tran_name; char tname[512]; int j; char c; ret_val = lseek(filedesc, tran_start + tran.ap_group, SEEK_SET); if (ret_val != (tran_start + tran.ap_group)) return (ret_val) ; if (tran.ap_charset == ACCT_ARM_ASCII || tran.ap_charset == ACCT_ARM_UTF8) { ret_val = read(filedesc, &tran_name, sizeof(struct tran_arm_string)); if (ret_val != sizeof(struct tran_arm_string)) return (ret_val) ; } else if (tran.ap_charset == ACCT_ARM_UTF16) { ret_val = read (filedesc, &tran_name.ts_len, sizeof(unsigned short)); if (ret_val != sizeof(unsigned short)) return (ret_val); for (j = 0; j < (tran_name.ts_len / 2); j++) { read (filedesc,(void *)&c,sizeof(char)); read (filedesc, (void *)&c, sizeof(char)); tran_name.ts_string[j] = (char)c; } tran_name.ts_string[tran_name.ts_len / 2] = '\0'; } snprintf(tname, tran_name.ts_len, "%s", tran_name.ts_string); if (!cflg) printf("\tGroup Name=%s\n", tname) ; else printf(":group_name=%s", tname) ; } if (tran.ap_iprop == 0) { if (!cflg) printf("\tIdentity Properties Not Provided\n"); else { printf(":id_prop=") ; printf(":id_pname=") ; printf(":id_pval=") ; } } else { struct tran_arm_properties props; char acct[512]; tran_start = lseek(filedesc, tran_start + tran.ap_iprop, SEEK_SET); ret_val = read(filedesc, &props, sizeof(props)); if (ret_val != sizeof(props)) return (ret_val) ; if (!cflg) printf("\tTotal Identity Properties=%d\n", props.tp_cnt) ; else printf(":id_prop=%d", props.tp_cnt) ; if (props.tp_cnt) { struct tran_arm_string tnv; char nv[512]; int i; int j; char c; for (i=0; i trans_header.tran_time) { if (ret_val = next_trans_record(&trans_header)) { return(ret_val) ; } cur_file_offset += trans_header.tran_size ; continue; } if (eflg && end_time < trans_header.tran_time) break; switch(printopt) { case PRINT_ALL_REC: case PRINT_GLOBAL_WPAR: if(trans_header.tran_id == TRID_agg_ke) { if (tflg && trid != TRID_agg_ke) { if (ret_val = next_trans_record(&trans_header)) { return(ret_val); } break; } ret_val = read(filedesc, &agg_ke_trans, sizeof(struct tran_agg_ke)) ; if (ret_val != (sizeof(struct tran_agg_ke))) { return(ret_val) ; } if (trans_header.cor_flag) { /* Skip the ckey */ SKIP_CKEY_TO_NEXT_HEADER(trans_header, struct tran_agg_ke); } print_trans_header(&trans_header) ; print_agg_ke_trans(agg_ke_trans); } else { if (printopt == PRINT_GLOBAL_WPAR) { if (ret_val = next_trans_record(&trans_header)) { return(ret_val); } break; } } case PRINT_WPAR: if(trans_header.tran_id == TRID_w_agg_ke) { if (tflg && trid != TRID_w_agg_ke) { if (ret_val = next_trans_record(&trans_header)) { return(ret_val); } break; } ret_val = read(filedesc, &w_agg_ke_trans, sizeof(struct tran_w_agg_ke)) ; if (ret_val != (sizeof(struct tran_w_agg_ke))) { return(ret_val) ; } if (trans_header.cor_flag) { /* Skip the ckey */ SKIP_CKEY_TO_NEXT_HEADER(trans_header, struct tran_w_agg_ke); } if(wparname[0] != '\0') { if (strcmp(w_agg_ke_trans.trp_wparname, wparname)) { cur_file_offset += trans_header.tran_size ; break; } } print_trans_header(&trans_header) ; print_w_agg_ke_trans(w_agg_ke_trans); } else { if (printopt == PRINT_WPAR) { if (ret_val = next_trans_record(&trans_header)) { return(ret_val); } } break; } } } else { if (ret_val = next_trans_record(&trans_header)) { return(ret_val) ; } } cur_file_offset += trans_header.tran_size ; } } void print_agg_ke_trans(struct tran_agg_ke agg_ke_trans) { if (!cflg ) { printf("\tAggregated Kernel Extension Instance\n"); printf("\tStart time=%llu\n\tTransaction ID=%u\n\tNo. of aggregated transctions=%u\n", agg_ke_trans.trp_start, agg_ke_trans.trp_trid, agg_ke_trans.trp_count) ; printf("\tKernel Extension=%s\n\tCPU usage=%llu\n", agg_ke_trans.trp_comm, agg_ke_trans.trp_usage.tu_cpu) ; printf("\tResource utilized=%llu\n", agg_ke_trans.trp_usage.tu_res1); printf("************************************************************\n"); } else { printf("time_start=%llu:trid=%u:count=%u:kernel_ext=%s:cpu=%llu:rec_util=%llu\n", agg_ke_trans.trp_start, agg_ke_trans.trp_trid, agg_ke_trans.trp_count, agg_ke_trans.trp_comm, agg_ke_trans.trp_usage.tu_cpu, agg_ke_trans.trp_usage.tu_res1); } } void print_w_agg_ke_trans(struct tran_w_agg_ke w_agg_ke_trans) { if (!cflg ) { printf("\tAggregated Kernel Extension Instance\n"); printf("\tStart time=%llu\n\tTransaction ID=%u\n\tNo. of aggregated transctions=%u\n", w_agg_ke_trans.trp_start, w_agg_ke_trans.trp_trid, w_agg_ke_trans.trp_count) ; printf("\tKernel Extension=%s\n\tCPU usage=%llu\n", w_agg_ke_trans.trp_comm, w_agg_ke_trans.trp_usage.tu_cpu) ; printf("\tResource utilized=%llu\n\twparname=%s", w_agg_ke_trans.trp_usage.tu_res1, w_agg_ke_trans.trp_wparname); printf("************************************************************\n"); } else { printf("time_start=%llu:trid=%u:count=%u:kernel_ext=%s:cpu=%llu:rec_util=%llu:wparname=%s\n", w_agg_ke_trans.trp_start, w_agg_ke_trans.trp_trid, w_agg_ke_trans.trp_count, w_agg_ke_trans.trp_comm, w_agg_ke_trans.trp_usage.tu_cpu, w_agg_ke_trans.trp_usage.tu_res1, w_agg_ke_trans.trp_wparname); } } int print_vscsi_target_trans() { struct aacct_tran_header trans_header ; struct tran_vscsi_target vscsi_target_trans ; int ret_val ; unsigned long long cur_file_offset ; if (tflg && trid != TRID_vscsi_target) return; if (ret_val = skip_file_header()) return ret_val ; cur_file_offset = sizeof(struct acct_file_header) ; while(cur_file_offset < max_file_offset) { ret_val = read(filedesc, &trans_header, TRAN_HDR_SIZE) ; if (ret_val != TRAN_HDR_SIZE) { return(ret_val) ; } if (trans_header.tran_id == TRID_vscsi_target) { if (bflg && begin_time > trans_header.tran_time) { if (ret_val = next_trans_record(&trans_header)) { return(ret_val) ; } cur_file_offset += trans_header.tran_size ; continue; } if (eflg && end_time < trans_header.tran_time) break; ret_val = read(filedesc, &vscsi_target_trans, sizeof(struct tran_vscsi_target)) ; if (ret_val != (sizeof(struct tran_vscsi_target))) { return(ret_val) ; } if (trans_header.cor_flag) { /* Skip the ckey */ SKIP_CKEY_TO_NEXT_HEADER(trans_header, struct tran_vscsi_target); } print_trans_header(&trans_header); if (!cflg) { printf("\tVSCSI Target Transaction Instance\n"); printf("\tPartition Name=%u\n\tServer Unit ID=%llu\n\tLogical Unit ID=%llu\n", vscsi_target_trans.client_partition_num, vscsi_target_trans.unit_id, vscsi_target_trans.lun_id) ; printf("\tNo. of byte ins=%llu\n\tNo. of byte outs=%llu\n", vscsi_target_trans.bytes_in, vscsi_target_trans.bytes_out) ; printf("************************************************************\n"); } else { printf("partition_num=%u:unit_id=%llu:logical_unit_id=%llu" ":bytes_in=%llu:bytes_out=%llu\n", vscsi_target_trans.client_partition_num, vscsi_target_trans.unit_id, vscsi_target_trans.lun_id, vscsi_target_trans.bytes_in, vscsi_target_trans.bytes_out); } } else { if (ret_val = next_trans_record(&trans_header)) return(ret_val) ; } cur_file_offset += trans_header.tran_size ; } } int print_vscsi_client_trans() { struct aacct_tran_header trans_header ; struct tran_vscsi_client vscsi_client_trans ; int ret_val ; unsigned long long cur_file_offset ; if (tflg && trid != TRID_vscsi_client) return; if (ret_val = skip_file_header()) return ret_val ; cur_file_offset = sizeof(struct acct_file_header) ; while(cur_file_offset < max_file_offset) { ret_val = read(filedesc, &trans_header, TRAN_HDR_SIZE) ; if (ret_val != TRAN_HDR_SIZE) { return(ret_val) ; } if (trans_header.tran_id == TRID_vscsi_client) { if (bflg && begin_time > trans_header.tran_time) { if (ret_val = next_trans_record(&trans_header)) { return(ret_val) ; } cur_file_offset += trans_header.tran_size ; continue; } if (eflg && end_time < trans_header.tran_time) break; ret_val = read(filedesc, &vscsi_client_trans, sizeof(struct tran_vscsi_client)) ; if (ret_val != (sizeof(struct tran_vscsi_client))) { return(ret_val) ; } if (trans_header.cor_flag) { /* Skip the ckey */ SKIP_CKEY_TO_NEXT_HEADER(trans_header, struct tran_vscsi_client); } print_trans_header(&trans_header); if (!cflg) { printf("\tVSCSI Client Transaction Instance\n"); printf("\tPartition Name=%u\n\tServer Unit ID=%llu\n\tLogical Unit ID=%llu\n", vscsi_client_trans.partition_num, vscsi_client_trans.unit_id, vscsi_client_trans.lun_id) ; printf("\tNo. of byte ins=%llu\n\tNo. of byte outs=%llu\n", vscsi_client_trans.bytes_in, vscsi_client_trans.bytes_out) ; printf("************************************************************\n"); } else { printf("partition_num=%u:unit_id=%llu:logical_unit_id=%llu" ":bytes_in=%llu:bytes_out=%llu\n", vscsi_client_trans.partition_num, vscsi_client_trans.unit_id, vscsi_client_trans.lun_id,vscsi_client_trans.bytes_in, vscsi_client_trans.bytes_out); } } else { if (ret_val = next_trans_record(&trans_header)) return(ret_val) ; } cur_file_offset += trans_header.tran_size ; } } int skip_file_header() { int ret_val ; ret_val = lseek(filedesc, sizeof(struct acct_file_header), SEEK_SET) ; if (ret_val < 0) return(ret_val) ; return 0 ; } int print_trans_header(struct aacct_tran_header *trans_header) { unsigned long long val; time_t tval; struct tm *tm; val = (unsigned long long)trans_header->tran_time/1000000; tval = (time_t)val; tm = localtime(&tval); if (!cflg) { printf("Transaction ID=%u\nFlags=%x\nTransaction Project=%u\n", trans_header->tran_id, trans_header->tran_flags, trans_header->tran_project) ; printf("Sub project ID=%llu\n", trans_header->tran_subproj) ; printf("Transaction start time=%d-%d-%d %d:%d:%d\n", tm->tm_mon+1, tm->tm_mday, tm->tm_year + 1900, tm->tm_hour, tm->tm_min, tm->tm_sec); } else { printf("tran_id=%u:tran_flags=%x:tran_project=%u:tran_subproj=%llu:", trans_header->tran_id, trans_header->tran_flags, trans_header->tran_project, trans_header->tran_subproj); printf("start_time=%d-%d-%d_%d.%d.%d:", tm->tm_mon+1, tm->tm_mday, tm->tm_year + 1900, tm->tm_hour, tm->tm_min, tm->tm_sec); } } int next_trans_record(struct aacct_tran_header *trans_header) { int nbytes, ret_val ; nbytes = trans_header->tran_size - TRAN_HDR_SIZE ; ret_val = lseek(filedesc, nbytes, SEEK_CUR) ; if (ret_val < 0) return(ret_val) ; return 0 ; } /* This is a sample function to shows how to get ckey from the * Transaction header. * ckey is of type ckey_t and it resides at the end of * aacct_tran_header. "cor_flag" bit in the transaction header * Indicates the presence of ckey. * filedesc is assumed to be pointed to tran_data * filedesc is restored back to tran_data after retrieving ckey. */ int get_corral_key(struct aacct_tran_header *trans_header, ckey_t *ckey) { int nbytes; /* if (!trans_header->cor_flag) { *ckey = 0; return 0; }*/ nbytes = trans_header->tran_size - TRAN_HDR_SIZE - sizeof (ckey_t); if (lseek(filedesc, nbytes, SEEK_CUR) < 0) return -1; else { if ((read(filedesc, ckey, sizeof(ckey_t)) != sizeof(ckey_t))) return -1; else { if (lseek(filedesc, -(nbytes +sizeof(ckey_t)), SEEK_CUR) < 0) return -1; else return 0; } } } /* * This routine converts the input date string to seconds format, from EPOCH. * */ unsigned long long parse_string(char *str) { int i, j; int num[NUM_SIZE]; int dot = FALSE; int yy,cc,yyyy; int offset,year_format=0; time_t tbuf, timbuf; unsigned long long retval; struct tm *tim, tmset; /*** Initialize num array ***/ for ( i=0; itm_sec; offset = tim->tm_year; /*** Determine format type ***/ if ( dot ) { /*** Format is mmddHHMM.SS[[cc]yy] ***/ if ( num[j] == UNDEFINED ) return(-1); tmset.tm_sec = num[j++]; } if ( num[j] != UNDEFINED && num[j+1] != UNDEFINED ) { /*** Format is mmddHHMMccyy***/ year_format = FOURDIGIT; if ( num[j] != 19 && num[j] != 20 ) { printf("Invalid date/time format.\n"); exit(1); } cc = num[j++]; yy = num[j++]; yyyy = cc * 100 + yy; } if ( year_format != FOURDIGIT && num[j] != UNDEFINED ) { /*** Format is mmddHHMMyy***/ year_format = TWODIGIT; yy = num[j++]; } if ( year_format != FOURDIGIT && year_format != TWODIGIT && !dot && num[j] == UNDEFINED && num[j+1] == UNDEFINED ) { /*** Format is mmddHHMM ***/ yy = tim->tm_year + 1900; } if (num[j] != UNDEFINED) { printf("Invalid date/time format.\n"); exit(1); } /***Translate the 4digit or 2digit year into offset from 1900 for time_t format***/ if ( year_format == FOURDIGIT ) { if (( yyyy >= MIN_yyyy ) && (yyyy <= MAX_yyyy )) { offset = yyyy - 1900; } else return(-1); } else if ( year_format == TWODIGIT ) { if ( (yy >= MIN_yy) && (yy < 69) ) offset = yy + 100; else if ( (yy >= 69) && (yy <= MAX_yy) ) offset = yy; else return(-1); } /** if offset translates to be more than 137 exit error, since currently time_t can support only upto year 2037 **/ if ( offset > 137 ) { printf("Invalid date/time format.\n"); exit(1); } tmset.tm_year = offset; /**initailise the tmset structure with the offset calculated **/ /*** Check range of each value ***/ if ( tmset.tm_mon < MIN_mm || tmset.tm_mon > MAX_mm ) return(-1); if ( tmset.tm_mday < MIN_dd || tmset.tm_mday > MAX_dd[tmset.tm_mon] ) return(-1); if ( tmset.tm_hour < MIN_HH || tmset.tm_hour > MAX_HH ) return(-1); if ( tmset.tm_min < MIN_MM || tmset.tm_min > MAX_MM ) return(-1); if ( tmset.tm_sec < MIN_SS || tmset.tm_sec > MAX_SS ) return(-1); /* If month is February, days > 28 and not leap year, then return. */ if (tmset.tm_mon == 1 && tmset.tm_mday > 28 && !leapyr(yy)) return(-1); tmset.tm_isdst = -1; if ((timbuf = mktime(&tmset)) == (time_t) -1) return(-1); retval = (unsigned long long)timbuf; return(retval * NANO_SEC ); }