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

📄 gui.c

📁 opensolaris下列出top进程
💻 C
字号:
#include "gui.h"/** * init curses */voidinit_gui (){  initscr ();  cbreak ();  noecho ();  nodelay (stdscr, TRUE);}/** * end gui */voidquit_gui (){  endwin ();}/** * create dim object */dimension *create_dim (int x, int y, int height, int width){  dimension *neu = malloc (sizeof (dimension));  neu->x = x;  neu->y = y;  neu->height = height;  neu->width = width;  return neu;}/** * draw functions *//** * draw a sysmeter of the given length */voiddraw_meter (float value, int width, char *name, char *str){  int i = 0;  while (name[i] != '\0')    {      str[i] = name[i];      i++;    }  int stop = (int) ((width - (i + 1)) * value) + i;  // this should never happen  if (stop >= width - 1)    {      stop = width - 1;    }  str[i] = '|';  i++;  while (i < stop)    {      str[i] = 'x';      i++;    }  while (i < width - 2)    {      str[i] = ' ';      i++;    }  str[width - 2] = '|';  // always zero-terminate strings!  str[width - 1] = '\0';}voiddraw_cpu (database * data, dimension * dim){  char str[dim->width];  int i;  i = 0;  snprintf (str, dim->width, "CPU:");  mvaddnstr (dim->y, dim->x, str, dim->width);  i++;  if (i < dim->height)    {      //snprintf(str,dim->width,"User: %3.2f",data->Lcpu->user);      draw_meter (data->Lcpu->user, dim->width, "User:", str);      mvaddnstr (dim->y + i, dim->x, str, dim->width);      i++;    }  if (i < dim->height)    {      //snprintf(str,dim->width,"Nice: %3.2f",data->Lcpu->nice);      draw_meter (data->Lcpu->nice, dim->width, "Nice:", str);      mvaddnstr (dim->y + i, dim->x, str, dim->width);      i++;    }  if (i < dim->height)    {      //snprintf(str,dim->width,"Sys:  %3.2f",data->Lcpu->sys);      draw_meter (data->Lcpu->sys, dim->width, "Sys: ", str);      mvaddnstr (dim->y + i, dim->x, str, dim->width);      i++;    }  if (i < dim->height)    {      //snprintf(str,dim->width,"Idle: %3.2f",data->Lcpu->idle);      draw_meter (data->Lcpu->idle, dim->width, "Idle:", str);      mvaddnstr (dim->y + i, dim->x, str, dim->width);      i++;    }  cpuusage *temp;  int y;  temp = data->Lcpu->next;  y = 0;  while (temp != 0)    {      snprintf (str, dim->width, "CPU %d:", y);      if (i < dim->height)        {          mvaddnstr (dim->y + i, dim->x, str, dim->width);          i++;        }      if (i < dim->height)        {          //snprintf(str,dim->width,"User: %3.2f",data->Lcpu->user);          draw_meter (temp->user, dim->width, "User:", str);          mvaddnstr (dim->y + i, dim->x, str, dim->width);          i++;        }      if (i < dim->height)        {          //snprintf(str,dim->width,"Nice: %3.2f",data->Lcpu->nice);          draw_meter (temp->nice, dim->width, "Nice:", str);          mvaddnstr (dim->y + i, dim->x, str, dim->width);          i++;        }      if (i < dim->height)        {          //snprintf(str,dim->width,"Sys:  %3.2f",data->Lcpu->sys);          draw_meter (temp->sys, dim->width, "Sys: ", str);          mvaddnstr (dim->y + i, dim->x, str, dim->width);          i++;        }      if (i < dim->height)        {          //snprintf(str,dim->width,"Idle: %3.2f",data->Lcpu->idle);          draw_meter (temp->idle, dim->width, "Idle:", str);          mvaddnstr (dim->y + i, dim->x, str, dim->width);          i++;        }      y++;      temp = temp->next;    }  free (dim);  dim = 0;}voiddraw_mem (database * data, dimension * dim, int unit){  char str[dim->width];  int divisor;  switch (unit)    {    case BYTES:      divisor = 1;      break;    case KBYTES:      divisor = 1024;      break;    case MBYTES:      divisor = 1024 * 1024;      break;    case GBYTES:      divisor = 1024 * 1024 * 1024;      break;    default:      divisor = 1;      break;    }  int i;  i = 0;  snprintf (str, dim->width, "Memory:");  mvaddnstr (dim->y, dim->x, str, dim->width);  i++;  if (i < dim->height)    {      snprintf (str, dim->width, "Total: %12d",                (int) data->memoryusage->total / divisor);      mvaddnstr (dim->y + i, dim->x, str, dim->width);      i++;    }  if (i < dim->height)    {      snprintf (str, dim->width, "Used:  %12d",                (int) data->memoryusage->used / divisor);      mvaddnstr (dim->y + i, dim->x, str, dim->width);      i++;    }  if (i < dim->height)    {      snprintf (str, dim->width, "Free:  %12d",                (int) data->memoryusage->free / divisor);      mvaddnstr (dim->y + i, dim->x, str, dim->width);      i++;    }  if (i < dim->height)    {      snprintf (str, dim->width, "Shared:%12d",                (int) data->memoryusage->shared / divisor);      mvaddnstr (dim->y + i, dim->x, str, dim->width);      i++;    }  if (i < dim->height)    {      snprintf (str, dim->width, "Buffer:%12d",                (int) data->memoryusage->buffer / divisor);      mvaddnstr (dim->y + i, dim->x, str, dim->width);      i++;    }  if (i < dim->height)    {      snprintf (str, dim->width, "Cached:%12d",                (int) data->memoryusage->cached / divisor);      mvaddnstr (dim->y + i, dim->x, str, dim->width);      i++;    }  if (i < dim->height)    {      snprintf (str, dim->width, "user:  %12d",                (int) data->memoryusage->user / divisor);      mvaddnstr (dim->y + i, dim->x, str, dim->width);      i++;    }  if (i < dim->height)    {      snprintf (str, dim->width, "Locked:%12d",                (int) data->memoryusage->locked / divisor);      mvaddnstr (dim->y + i, dim->x, str, dim->width);      i++;    }  free (dim);  dim = 0;}voiddraw_net (database * data, dimension * dim, int unit){  netload *temp = data->Lnetload;  char str[dim->width];  int i;  i = 0;  while (temp != NULL && i < dim->height)    {      snprintf (str, dim->width, "%s", temp->device);      mvaddnstr (dim->y + i, dim->x, str, dim->width);      i++;      if (i < dim->height)        {          snprintf (str, dim->width, "bytes_in: %9d", temp->bytes_in);          mvaddnstr (dim->y + i, dim->x, str, dim->width);          i++;        }      if (i < dim->height)        {          snprintf (str, dim->width, "bytes_out:%9d", temp->bytes_out);          mvaddnstr (dim->y + i, dim->x, str, dim->width);          i++;        }      if (i < dim->height)        {          snprintf (str, dim->width, "packets_in: %7d", temp->packets_in);          mvaddnstr (dim->y + i, dim->x, str, dim->width);          i++;        }      if (i < dim->height)        {          snprintf (str, dim->width, "packets_out:%7d", temp->packets_out);          mvaddnstr (dim->y + i, dim->x, str, dim->width);          i++;        }      if (i < dim->height)        {          snprintf (str, dim->width, "errors_in: %8d", temp->errors_in);          mvaddnstr (dim->y + i, dim->x, str, dim->width);          i++;        }      if (i < dim->height)        {          snprintf (str, dim->width, "errors_out:%8d", temp->errors_out);          mvaddnstr (dim->y + i, dim->x, str, dim->width);          i++;        }      if (i < dim->height)        {          snprintf (str, dim->width, "collisions:%8d", temp->collisions);          mvaddnstr (dim->y + i, dim->x, str, dim->width);          i++;        }      temp = temp->next;    }  free (dim);}voiddraw_top_processes (database * data, dimension * dim){  int i;  for (i = 0; i < NUMBER_PROCESSES; i++)    {      if (i < dim->height)        {          mvaddnstr (dim->y + i, dim->x, "                    ", dim->width);          if (data->Tprocess[i] != NULL)            mvaddnstr (dim->y + i, dim->x, data->Tprocess[i]->cmd,                       dim->width);        }    }  free (dim);}voiddraw_disk (database * data, dimension * dim, int unit){  char str[dim->width];  int divisor, adjust;  adjust = 512 * 8;             // glibtop_fsusage gives blocks in 512 _bits_ (not bytes as the documentation suggests)  switch (unit)    {    case BYTES:      divisor = 1;      break;    case KBYTES:      divisor = 1024;      break;    case MBYTES:      divisor = 1024 * 1024;      break;    case GBYTES:      divisor = 1024 * 1024 * 1024;      break;    default:      divisor = 1;      break;    }  int i;  i = 0;  csm_fsinfo *temp = data->fsinfo;  while (temp != NULL)    {      if (i < dim->height)        {          snprintf (str, dim->width, "Mount: %s", temp->mountdir);          mvaddnstr (dim->y + i, dim->x, str, dim->width);          i++;        }      if (i < dim->height)        {          snprintf (str, dim->width, "Type: %s", temp->type);          mvaddnstr (dim->y + i, dim->x, str, dim->width);          i++;        }      if (i < dim->height)        {          snprintf (str, dim->width, "Blocks:%12.2f",                    ((float) temp->fsusage->blocks * adjust) / divisor);          mvaddnstr (dim->y + i, dim->x, str, dim->width);          i++;        }      if (i < dim->height)        {          snprintf (str, dim->width, "Bfree: %12.2f",                    ((float) temp->fsusage->bfree * adjust) / divisor);          mvaddnstr (dim->y + i, dim->x, str, dim->width);          i++;        }      if (i < dim->height && temp->fsusage->bavail != temp->fsusage->bfree)        {          snprintf (str, dim->width, "Bavail:%12.2f",                    ((float) temp->fsusage->bavail * adjust) / divisor);          mvaddnstr (dim->y + i, dim->x, str, dim->width);          i++;        }      if (i < dim->height && temp->fsusage->files > 0)        {          snprintf (str, dim->width, "Files: %12d",                    (int) temp->fsusage->files);          mvaddnstr (dim->y + i, dim->x, str, dim->width);          i++;        }      if (i < dim->height && temp->fsusage->ffree > 0)        {          snprintf (str, dim->width, "Ffree: %12d",                    (int) temp->fsusage->ffree);          mvaddnstr (dim->y + i, dim->x, str, dim->width);          i++;        }      temp = temp->next;    }  // XXX: hack!  //      there has to be a better way!  while (i < dim->height)    {      mvaddstr (dim->y + i, dim->x, "                           ");      i++;    }  free (dim);}

⌨️ 快捷键说明

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