/ src / libnml / nml / nmldiag.cc
nmldiag.cc
  1  /********************************************************************
  2  * Description: nmldiag.cc
  3  *
  4  *   Derived from a work by Fred Proctor & Will Shackleford
  5  *
  6  * Author:
  7  * License: LGPL Version 2
  8  * System: Linux
  9  *    
 10  * Copyright (c) 2004 All rights reserved.
 11  *
 12  * Last change: 
 13  ********************************************************************/
 14  
 15  #include "nml.hh"		// NML_MAIN_Channel_List
 16  #include "nmldiag.hh"
 17  #include "rcs_print.hh"
 18  #include "linklist.hh"
 19  #include <time.h>
 20  
 21  static char access_name[9][40] = {
 22      "ZERO",
 23      "READ",
 24      "CHECK_IF_READ",
 25      "PEEK",
 26      "WRITE",
 27      "WRITE_IF_READ",
 28      "CLEAR",
 29      "GET_MSG_COUNT",
 30      "GET_DIAG_INFO"
 31  };
 32  
 33  void NML_DIAGNOSTICS_INFO::print()
 34  {
 35      if (NULL != last_writer_dpi) {
 36  	rcs_print("Last writer = %ld (%s)\n", last_writer,
 37  	    last_writer_dpi->name);
 38      }
 39      if (NULL != last_reader_dpi) {
 40  	rcs_print("Last reader = %ld (%s)\n", last_reader,
 41  	    last_reader_dpi->name);
 42      }
 43      if (NULL == dpis) {
 44  	return;
 45      }
 46      CMS_DIAG_PROC_INFO *dpi = (CMS_DIAG_PROC_INFO *) dpis->get_head();
 47      while (NULL != dpi) {
 48  	rcs_print("\n");
 49  	rcs_print("Info for process %s:\n", dpi->name);
 50  	rcs_print("\t Host and system info: %s\n", dpi->host_sysinfo);
 51  	rcs_print("\t Process Id: %ld\n", dpi->pid);
 52  	rcs_print("\t RCS Library Version: %f\n", dpi->rcslib_ver);
 53  	if (dpi->access_type >= 0 && dpi->access_type <= 9) {
 54  	    rcs_print("\t Last operation:  %d (%s)\n", dpi->access_type,
 55  		access_name[dpi->access_type]);
 56  	}
 57  	rcs_print("\t msg_id: %ld\n", dpi->msg_id);
 58  	rcs_print("\t msg_size: %ld\n", dpi->msg_size);
 59  	rcs_print("\t msg_type: %ld\n", dpi->msg_type);
 60  	rcs_print("\t number_of_accesses: %ld\n", dpi->number_of_accesses);
 61  	rcs_print("\t number_of_new_messages: %ld\n",
 62  	    dpi->number_of_new_messages);
 63  	rcs_print("\t bytes_moved: %f\n", dpi->bytes_moved);
 64  	time_t t = 0;
 65  	const char *ctime_ret = "";
 66  	if (dpi->first_access_time > 0.0) {
 67  	    t = (time_t) dpi->first_access_time;
 68  	    ctime_ret = ctime(&t);
 69  	    if (NULL == ctime_ret) {
 70  		ctime_ret = "";
 71  	    }
 72  	}
 73  	rcs_print("\t first_access_time: %f :  %s\n", dpi->first_access_time,
 74  	    ctime_ret);
 75  	ctime_ret = "";
 76  	if (dpi->last_access_time > 0.0) {
 77  	    t = (time_t) dpi->last_access_time;
 78  	    ctime_ret = ctime(&t);
 79  	    if (NULL == ctime_ret) {
 80  		ctime_ret = "";
 81  	    }
 82  	}
 83  	rcs_print("\t last_access_time: %f  : %s\n", dpi->last_access_time,
 84  	    ctime_ret);
 85  
 86  	if (dpi->max_difference >= dpi->min_difference) {
 87  	    rcs_print("\t Maximum time between accesses: %f\n",
 88  		dpi->max_difference);
 89  	    rcs_print("\t Minimum time between accesses: %f\n",
 90  		dpi->min_difference);
 91  	}
 92  	double total_time = dpi->last_access_time - dpi->first_access_time;
 93  	if (total_time > 0) {
 94  	    int h, m, s;
 95  	    h = ((int) total_time) / 3600;
 96  	    m = ((int) total_time - h * 60) / 60;
 97  	    s = ((int) total_time - h * 3600 - m * 60);
 98  	    rcs_print
 99  		("\t Time between first and last access: %f -- %02d:%02d:%02d\n",
100  		total_time, h, m, s);
101  	    if (dpi->number_of_accesses > 0) {
102  		rcs_print("\t Average time between accesses: %f\n",
103  		    (total_time) / dpi->number_of_accesses);
104  	    }
105  	    if (dpi->number_of_new_messages > 0) {
106  		rcs_print("\t Average time between new messages: %f\n",
107  		    (total_time) / dpi->number_of_new_messages);
108  	    }
109  	    if (dpi->bytes_moved > 0) {
110  		rcs_print("\t Average bytes moved per second: %f\n",
111  		    dpi->bytes_moved / (total_time));
112  	    }
113  	}
114  	if (dpi->bytes_moved > 0 && dpi->number_of_new_messages > 0) {
115  	    rcs_print("\t Average bytes moved per message: %f\n",
116  		dpi->bytes_moved / (dpi->number_of_new_messages));
117  	}
118  	dpi = (CMS_DIAG_PROC_INFO *) dpis->get_next();
119      }
120  }
121  
122  int nml_print_diag_list()
123  {
124      if (NULL != NML_Main_Channel_List) {
125  	NML *nml = (NML *) NML_Main_Channel_List->get_head();
126  	while (NULL != nml) {
127  	    if (NULL != nml->cms) {
128  		if (!nml->cms->enable_diagnostics) {
129  		    nml = (NML *) NML_Main_Channel_List->get_next();
130  		    continue;
131  		}
132  		rcs_print
133  		    ("\n*********************************************\n");
134  		if (NULL != nml->cms->BufferName) {
135  		    rcs_print("* Buffer Name: %s\n", nml->cms->BufferName);
136  		}
137  		NML_DIAGNOSTICS_INFO *ndi = nml->get_diagnostics_info();
138  		if (NULL != ndi) {
139  		    ndi->print();
140  		}
141  		rcs_print
142  		    ("*********************************************\n\n");
143  	    }
144  	    nml = (NML *) NML_Main_Channel_List->get_next();
145  	}
146      }
147      return (0);
148  }