--- openmosix-tools-0.3.6-2-orig/mps/mtop.c Sun Nov 30 12:19:06 2003 +++ openmosix-tools-0.3.6-2/mps/mtop.c Wed Sep 29 12:13:23 2004 @@ -75,6 +75,15 @@ ** The "Shared Library Pages used (kb)" field (LIB) was replaced with ** "where" info by Mathieu Cousin . */ +/* +** Modified on 27 Sep 2004 by Moreno 'baro' Baricevic +** - merged patch by Jozef Ivanecky (P_NODE display fix, automatic adjustment +** of "N#" column width); +** - P_NMIGS display fix, automatic adjustment of "MGS" column width (suggested +** by Jozef Ivanecky); +** - 'H' interactive key added to force header update ('\n', unhandled +** before, has (now) the same effect). +*/ #include #include @@ -95,6 +104,7 @@ #include #include #include +#include #include "proc/sysinfo.h" #include "proc/ps.h" @@ -117,7 +127,18 @@ static int preferednodenumber = 0; /* OMINFO { */ + int oMout = 0; /* mtop doesn't need openMosix "lock" and "cantmove" */ + +/* +** P_NODE and P_NMIGS width adjustment +*/ +#define OM_DIR_NODES "/proc/hpc/nodes" +#define OM_FMT_LEN 6 // '%' 'N' ['N'] 'd' ' ' '\0' +static char nodename_fmt[OM_FMT_LEN]; +static char nmigs_fmt[OM_FMT_LEN]; +static int max_nmigs_len = -1 , oldmax_nmigs_len = -1 ; + /* } OMINFO */ #define PUTP(x) (tputs(x,1,putchar)) @@ -533,8 +554,20 @@ } } strcpy(Header, ""); +/* OMINFO { */ for (i = 0; i < j; i++) - strcat(Header, headers[pflags[i]]); + { + if ( pflags[i] == P_NODE ) /* Adjusting N# column width to the number of nodes ... */ + { + adjust_nodename( Header ); + } + else if ( pflags[i] == P_NMIGS ) /* Adjusting MGS column width to the number of migrations ... */ + { + adjust_nmigs( Header ); + } + strcat( Header , headers[pflags[i]] ); + } +/* } OMINFO */ /* readjust window size ... */ Maxcmd = Cols - strlen(Header) + 7; Maxlines = Display_procs ? Display_procs : Lines - header_lines; @@ -556,8 +589,8 @@ sprintf(filename, "/proc/%d/goto", pid); sprintf(buffer, "%d", nodenumber); - if ((fd = open(filename, O_WRONLY, 0)) == -1 ) return -1; - if ((num_write = write(fd, buffer, strlen(buffer))) <= 0 ) + if ( (fd = open(filename, O_WRONLY, 0)) == -1 ) return -1; + if ( (num_write = write(fd, buffer, strlen(buffer))) <= 0 ) { close(fd); return -1; @@ -1041,7 +1074,9 @@ break; /* Modified for Node Number Information */ case P_NODE: - sprintf(tmp, "%2d ", task->where); +/* OMINFO { */ + sprintf( tmp , nodename_fmt , task->where ); +/* } OMINFO */ break; /* End of Modifications */ @@ -1053,7 +1088,8 @@ break; #else /* new "nmigs" */ case P_NMIGS: - sprintf(tmp, "%3d ", task->nmigs); + sprintf( tmp , nmigs_fmt , task->nmigs ); + nmigs_len( task->nmigs ); break; #endif @@ -1156,6 +1192,15 @@ } count++; } + +/* OMINFO { */ + if ( max_nmigs_len != oldmax_nmigs_len ) + { + oldmax_nmigs_len = max_nmigs_len; + Numfields = make_header(); + } +/* } OMINFO */ + PUTP(top_clrtobot); PUTP(tgoto(cm, 0, header_lines - 2)); fflush(stdout); @@ -1607,6 +1652,13 @@ break; #endif + /* force header update (re-read max nodename length) */ + case 'H': + case '\n': // unhandled before +// SHOWMESSAGE(("Updating header")); + Numfields = make_header(); + break; + /* } OMINFO */ case 'f': @@ -1729,3 +1781,85 @@ return tab; } + +/* OMINFO { */ +/*############################################## + *####### Find the max node name length ##### + *############################################## + */ +int max_node_nlen( void ) +{ + DIR * dirhpc; + struct dirent * dir_info; + int max_nlen = -1; + + dirhpc = opendir( OM_DIR_NODES ); + if ( dirhpc != NULL ) + { + while ( ( dir_info = readdir( dirhpc ) ) != NULL ) + { + if ( ! strchr( dir_info->d_name , '.' ) ) + { + int cnlen = strlen( dir_info->d_name ); + if ( cnlen > max_nlen ) + max_nlen = cnlen; + } + } + closedir( dirhpc ); + } + return max_nlen; +} + +void nmigs_len( int nmigs ) +{ + char dummy[8] ; + int cval = snprintf( dummy , 8 , "%d" , nmigs ); + if ( cval > max_nmigs_len ) + max_nmigs_len = cval; +} + +void adjust_nodename( char * h ) +{ + int max_nodename_len = max_node_nlen(); + if ( max_nodename_len > 2 ) + { + if ( max_nodename_len > 99 ) // should never happen, max node == 65534, len 5 + max_nodename_len = 99; // avoid segfault on nodename_fmt + + // set nodename output format accordingly to nodename length + snprintf( nodename_fmt , OM_FMT_LEN , "%%" "%d" "d " , max_nodename_len ); + + // pad left side of P_NODE label with spaces + while ( max_nodename_len-- > strlen( headers[P_NODE] )-1 ) // -1 ignores trailing space + strcat( h , " " ); + + } /* End of adjust */ + else + strncpy( nodename_fmt , "%2d " , OM_FMT_LEN-1 ) , + nodename_fmt[OM_FMT_LEN-1] = '\0'; +} + +void adjust_nmigs( char * h ) +{ + int mnl = max_nmigs_len; + if ( mnl > 3 ) + { +#if 0 + if ( mnl > 99 ) // can't happen since nmigs_len() returns 8 as max value. + mnl = 99; // avoid segfault on nmigs_fmt +#endif + + // set nodename output format accordingly to nmigs length + snprintf( nmigs_fmt , OM_FMT_LEN , "%%" "%d" "d " , mnl ); + + // pad left side of P_NMIGS label with spaces + while ( mnl-- > strlen( headers[P_NMIGS] )-1 ) // -1 ignores trailing space + strcat( h , " " ); + + } /* End of adjust */ + else + strncpy( nmigs_fmt , "%3d " , OM_FMT_LEN-1 ) , + nmigs_fmt[OM_FMT_LEN-1] = '\0'; +} + +/* } OMINFO */ --- openmosix-tools-0.3.6-2-orig/mps/mtop.h Sun Nov 30 12:19:06 2003 +++ openmosix-tools-0.3.6-2/mps/mtop.h Wed Sep 29 11:09:31 2004 @@ -15,6 +15,11 @@ ** The "Shared Library Pages used (kb)" field (LIB) was replaced with ** "where" info by Mathieu Cousin . */ +/* +** Modified on 27 Sep 2004 by Moreno 'baro' Baricevic +** - declaration of P_NODE and P_NMIGS width-handling functions; +** - added 'H' interactive key description on HELP_SCREENs. +*/ proc_t** readproctab2(int flags, proc_t** tab, ...); void parse_options(char *Options, int secure); @@ -44,6 +49,12 @@ unsigned show_meminfo(void); void do_stats(proc_t** p, float elapsed_time, int pass); void do_key(char c); +/* OMINFO { */ +int max_node_nlen(void); +void nmigs_len( int nmigs ); +void adjust_nodename( char * header ); +void adjust_nmigs( char * header ); +/* } OMINFO */ /* configurable field display support */ @@ -256,6 +267,7 @@ a\tAutomatic Migration of non-root Process\n\ N\tSort by openMosix Node Number\n\ #\tSort by openMosix Number of Migrations\n\ +H\t(force) Header update\n\ q\tQuit" #define SECURE_HELP_SCREEN "\ @@ -280,6 +292,7 @@ a\tAutomatic Migration of non-root Process\n\ N\tSort by openMosix Node Number\n\ #\tSort by openMosix Number of Migrations\n\ +H\t(force) Header update\n\ q\tQuit" /* Number of lines needed to display the header information. */