⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mosmon.c

📁 OpenMosix工具
💻 C
📖 第 1 页 / 共 3 页
字号:
	  for (i = base / 2 - n; *fmt; i += 2)	    {	      move (i, 0);	      addch ((chtype) * fmt++);	    }	}      else if (item == D_GETSPEED)	{	  fmt = "SPEED";	  for (i = base / 2 - 4; *fmt; i += 2)	    {	      move (i, 0);	      addch ((chtype) * fmt++);	    }	}      else	{	  fmt = "Utilizability";	  for (i = base / 2 - 7; *fmt; i++)	    {	      move (i, 0);	      addch ((chtype) * fmt++);	    }	}      for (i = 0; i < base; i++)	{	  move (i, COL_FROM_0);	  addch ('|');	}      move (base, COL_FROM_0);      for (i = screen_width * (wid + 1) + 1; i > 0; i--)	addch ('-');      j = (COLS - COL_FROM_0 - 8) / 2;      if (j < COL_FROM_0)	j = COL_FROM_0;      else if (j > 27)	j = 27;      move (LINES - 2, 0);      addstr ("Node #");      if (tflg)	{	  move (LINES - 1, 0);	  if (tot_display)	    printw ("[Total %d] [CPUs %d]", tot_display, cpus_display);	  else	    printw ("[OpenMosix Not Configured]");	}      max = 0;      dead = 0;      turns++;      if (!tflg)	(void) lseek (ifd, first - 1, SEEK_SET);      for (i = first; (i < (first + screen_width + dead)) && (i <= npe); i++)	{	  /* if we receive 0 we don't remove the load of	     the process completely: only divide it by two */	  if (!((i >= first_read) && (i < first_read + nread)))	    {	      /*try to compute optimal read-ahead (not easy) */	      if (!nread)		first_read = i;	      /* guess same # of dead as already found */	      j = first + screen_width + dead + dead - i;	      if (j > npe - i + 1)		j = npe - i + 1;	      j = readstruct (ifd, &info[i], j);	      if (j <= 0)		{		  npe = i - 1;		  break;		}	      nread += j;	    }	  if (info[i].status & DS_MOSIX_UP)	    {	      valid[i] = 1;	      switch (item)		{		case D_GETLOAD:#ifdef USE_LOG_LOAD		  load[i] = (log_load)		    ? ((info[i].load > 0) ? log10 (info[i].load) : 0)		    : (info[i].load / 100.0);#else		  load[i] = info[i].load / 100.0;#endif /* USE_LOG_LOAD */		  other[i] = info[i].ncpus;		  break;		case D_GETMEM:		  load[i] = info[i].tmem / 1048576.0;		  other[i] = load[i] - info[i].mem / 1048576.0;		  break;		case D_GETBMEM:		  load[i] = info[i].tmem / 1048576.0;		  other[i] = load[i] - info[i].rmem / 1048576.0;		  break;		case D_GETSPEED:		  load[i] = info[i].speed;		  other[i] = info[i].ncpus;		  break;		case D_GETUTIL:		  load[i] = info[i].util / info[i].ncpus;		  break;		}	    }	  else if (!(info[i].status & DS_MOSIX_DEF))	    load[i] = valid[i] = VERY_DEAD;	  else if (valid[i] <= MAX_SILENT + 1)	    load[i] = valid[i] = MAX_SILENT;	  else	    {	      valid[i]--;	      if (load[i] < 0)		load[i] = 0;	    }	  if (load[i] < 0)	    {	      load[i] = (valid[i] < 0) ? valid[i] : -1;	      if (load[i] <= (dflg ? VERY_DEAD : MAX_SILENT))		dead++;	    }#ifdef USE_LOG_LOAD# if 0	  if (load[i] > max)	    {	      if (log_load && item == D_GETLOAD)		max = 4;	      else		max = load[i];	    }# else	  if (log_load && item == D_GETLOAD)	    max = 4;		// when log_load max must be always 4	  else if (load[i] > max)	    max = load[i];# endif#else	  if (load[i] > max)	    max = load[i];#endif /* USE_LOG_LOAD */	}      if (tflg)	{	  for (; i <= npe; i++)	    if (!(info[i].status & DS_MOSIX_DEF))	      valid[i] = VERY_DEAD;	    else if (valid[i] > MAX_SILENT && !(info[i].status & DS_MOSIX_UP))	      valid[i]--;	  for (i = first - 1; i > 0; i--)	    if (!(info[i].status & DS_MOSIX_DEF))	      valid[i] = VERY_DEAD;	    else if (valid[i] > MAX_SILENT && !(info[i].status & DS_MOSIX_UP))	      valid[i]--;	}      if (max < 1)	{	  if (max == 0 && item == D_GETLOAD)	/* idle */	    {	      standout ();	      move (base - 1, 2);	      addstr ("IDLE");	      standend ();	    }	  max = 1;	}      if (max >= curmax)	{	  curmax = max;	  cool = 0;	}      else	{	  if (cool++ >= 3)	    curmax = max;	  max = curmax;	}      if (item == D_GETMEM)	{	  /* typical values are very close to 1MB multiples,	   * but not quite, causing distortions:	   */	}      switch (item)	{	case D_GETLOAD:	  fmt = "%5.2f";	  break;	case D_GETSPEED:	  fmt = "%5.0f";	  break;	case D_GETUTIL:	  fmt = "%4.0f%%";	  break;	case D_GETMEM:	case D_GETBMEM:	  fmt = (max >= 999.0) ? "%5.0f" : "%5.3g";	  break;	}      if (max > 0)	{	  move (0, 1);	  printw (fmt, max);	}      /*if ( max >= 3 ) */      {	move (base / 4, 1);	printw (fmt, max * 3 / 4);	move (base / 2, 1);	printw (fmt, max / 2);	move (base * 3 / 4, 1);	printw (fmt, max / 4);      }      move (base, 5);      addch ('0');      last = first + screen_width + dead - 1;      if (npe < last)	last = npe;      if (wid == 0 && 2 * (last - first + 1 - dead) <= screen_width)	wid = 1;      if (wid == 0)	{	  space = '|';	  rev = 0;	}      else	{	  space = ' ';	  rev = 1;	}      if (rev)	standout ();      dead = 0;			/* number of not responding machines */      if (max)	{	  for (i = first; i <= last; i++)	    {	      if (load[i] > 0)		{		  col = COL_FROM_0 + 1 + (wid != 0) + wid / 2 +		    (wid + 1) * (i - first - dead);		  l = base - (load[i] * base) / max + 0.5;		  if (item == D_GETMEM || item == D_GETBMEM)		    {		      k = base - (other[i] * base) / max + 0.5;		      if (rev)			standend ();		      for (; l < k; l++)			{			  move (l, col);			  addch ((chtype) (valid[i] > 0 ? '+' : '?'));			}		      if (rev)			standout ();		    }		  ospace = space;		  if (item == D_GETSPEED && other[i] > 1)		    space = '0' + other[i];		  for (; l < base; l++)		    {		      move (l, col);		      addch ((chtype) (valid[i] > 0 ? space : '?'));		    }		  space = ospace;		}	      else if (load[i] < 0)		{		  if (load[i] <= (dflg ? VERY_DEAD : MAX_SILENT))		    {		      dead++;		      continue;		    }		  col = COL_FROM_0 + 1 + (wid != 0) + wid / 2 +		    (wid + 1) * (i - first - dead);		  if (rev)		    standend ();		  move (base - 4, col);		  addch ('D');		  move (base - 3, col);		  addch ('E');		  move (base - 2, col);		  addch ('A');		  move (base - 1, col);		  addch ('D');		  if (rev)		    standout ();		}	    }	}      if (rev)	standend ();      if (ver)	{	  for (j = 10, k = LINES - 2; k > base; k--, j *= 10)	    {	      move (k, COL_FROM_0 + 1);	      for (i = first; i < (first + screen_width + dead) && i <= npe;		   i++)		{		  if (load[i] > (dflg ? VERY_DEAD : MAX_SILENT))		    {		      if (wid)			addch (' ');		      addch ((chtype) ('0' + i % j / (j / 10)));		    }		}	    }	}      else	{	  move (base + 1, COL_FROM_0 + 1);	  for (i = first; i < (first + screen_width + dead) && i <= npe; i++)	    {	      if (load[i] > (dflg ? VERY_DEAD : MAX_SILENT))		{		  if (i <= 9 && wid % 2 == 0)		    printw ("%*s%d%*s", 1 + wid / 2, "", i, wid / 2 - 1, "");		  else if (i >= 100 && i <= 999 && wid % 2 == 0)		    printw ("%*s%d%*s", wid / 2, "", i, wid / 2 - 2, "");		  else		    {		      j =			wid - (1 + (i > 9) + (i > 99) + (i > 999) +			       (i > 9999));		      printw ("%*s%d%*s", j / 2 + 1, "", i, (j + 1) / 2, "");		    }		}	    }	}      move (base, 79);      refresh ();      if (turns % 60 == 0)	get_npe ();      /*       ** screen's out, check for interactive keys       */      sleep_or_input (1);      if (is_input ())	{	  switch (my_getch ())	    {	      //-- - -- - -- - -- - -- - -- -	    case '\2':	    case KEY_HOME://#define __CB(m) cb(m,4,9)#define __CB(m) cb_ctr(m)	      __CB ("The OpenMosix Group");	      __CB ("     presents...   ");	      __CB (PROGNAME " version " PROGVER "!");#undef __CB	      break;	    case 'q':	    case 'Q':	      onint (0);	    case '\14':	    case '\r':	    case '\n':	      clear ();	      refresh ();	      break;	    case '?':	    case 'h':	    case 'H':	      help ();	      break;	      //-- - -- - -- - -- - -- - -- -	    case 'a':	    case 'A':	      wflg = vflg = 0;	      need_count = 1;	      break;	    case 'v':	      vflg = 1;	      wflg = 0;	      break;	    case 'V':	      vflg = 2;	      wflg = 0;	      break;	    case 'w':	    case 'W':	      vflg = 0;	      wflg = 1;	      break;	      //-- - -- - -- - -- - -- - -- -	    case 't':	      tflg = !tflg;	      break;	    case 'd':	    case 'D':	      dflg = !dflg;	      break;	    case 'y':	    case 'Y':	      yardstick ();	      break;	      //-- - -- - -- - -- - -- - -- -	    case 's':	    case 'S':	      curmax = 0;	      set_mode (D_GETSPEED);	      break;	    case 'm':	    case 'M':	      curmax = 0;	      set_mode (D_GETMEM);	      break;#ifdef USE_LOG_LOAD	    case 'L':	      log_load = !log_load;	      // fall through#endif /* USE_LOG_LOAD */	    case 'l':	      curmax = 0;	      set_mode (D_GETLOAD);	      break;	    case 'u':	    case 'U':	      curmax = 0;	      set_mode (D_GETUTIL);	      break;	    case 'r':	    case 'R':	      curmax = 0;	      set_mode (D_GETBMEM);	      break;	      //-- - -- - -- - -- - -- - -- -	    case '+':	    case KEY_RIGHT:	      if (first + screen_width - 1 < npe)		first++;	      break;	    case '-':	    case KEY_LEFT:	      if (first > 1)		{		  need_count = 1;		  first--;		}	      break;	    case 'n':		//next	    case 'N':	      first += screen_width;	      if (first + screen_width - 1 > npe)		{		  first = npe + 1 - screen_width;		  if (first < 1)		    first = 1;		}	      break;	    case 'p':		//previous	    case 'P':	    case 'b':		//back?	    case 'B':	      if (first)		need_count = 1;	      if (first > screen_width)		first -= screen_width;	      else		first = 1;	      break;	      //-- - -- - -- - -- - -- - -- -	    case KEY_IC:	      DBGprint ("interactive key INSERT, force update");	      vernum = guess_by_recsz (ifd), get_npe ();	      break;	      //-- - -- - -- - -- - -- - -- -	    default:	      write (STDOUT_FILENO, "\a", 1);	    }	}			/* is_input */    }				/* neverending loop */}				/* main *//******************************************************************** *_____________________________  USAGE _____________________________* ********************************************************************//*** ...does something useful** should fit on 80x24 screen (error + help + prompt)*/#define BELL { if ( isatty( STDERR_FILENO ) ) putc( '\a' , stderr ); }voidusage (const char *errmsg, ...){  if (errmsg && *errmsg)    {      va_list args;      BELL;      fprintf (stderr, "*** Usage error: ");      va_start (args, errmsg);      vfprintf (stderr, errmsg, args);      va_end (args);      putc ('\n', stderr);    }  fprintf (stderr,	   "\n"	   "Usage: %s [options]\n"	   "\n"	   "   -w            horizontal (wide) numbering\n"	   "   -v            vertical numbering\n"	   "   -V            super-vertical (tight) numbering\n"	   "   -a            automatic selection of numbering (default)\n"	   "\n"	   "   -s            show CPU speed (10,000 = 400MHz Pentium-2)\n"	   "   -m            show memory (used out of total)\n"	   "   -r            show memory (raw used/free out of total)\n"	   "   -u            show utilizability (%%)\n"	   "   -l            show load (default, 1.0 = 100%% standard CPU)\n"#ifdef USE_LOG_LOAD	   "   -L            show load (log scale, 2.0 = 100%% standard CPU)\n"#endif /* USE_LOG_LOAD *///             "\n"	   "   -d            show dead nodes (configured but not-responding)\n"	   "   -t            show total number of operational nodes\n"//             "                 (not recommended on very large clusters, will\n"//             "                 be very slow)\n"//             "\n"	   "   +NODE_NUMBER  begin the display at a particular node-number\n"	   "\n"	   "   -F KVER       force kernel version instead of guessing record size\n"//             "                 (KVER = [2416|...|2419|2420|2421|2422|2423|...])\n"	   "\n" "   -h|-H         display this message\n"//             "\n"//             "Try 'man %s' for details.\n"	   "\n", PROGNAME//           , PROGNAME    );

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -