Example #1
0
SPDP dtime(void)
{
 SPDP q;
 int secs, msecs;
 u32_t system_hz;
 times(&tms);
 getsysinfo_up(PM_PROC_NR, SIU_SYSTEMHZ, sizeof(system_hz), &system_hz);
 secs = tms.tms_utime / system_hz;
 q = secs;
 tms.tms_utime -= secs * system_hz;
 msecs = tms.tms_utime * 100 / system_hz;
 q += (float) msecs * 0.01;
 return q;
}
Example #2
0
int main(int argc, char *argv[])
{
	int r, c, s = 0, orig;

	getsysinfo_up(PM_PROC_NR, SIU_SYSTEMHZ, sizeof(system_hz), &system_hz);

	init(&r);

	while((c=getopt(argc, argv, "s:B")) != EOF) {
		switch(c) {
			case 's':
				s = atoi(optarg);
				break;
			case 'B':
				blockedverbose = 1;
				break;
			default:
				fprintf(stderr,
					"Usage: %s [-s<secdelay>] [-B]\n",
						argv[0]);
				return 1;
		}
	}

	if(s < 1) 
		s = 2;

	/* Catch window size changes so display is updated properly
	 * right away.
	 */
	signal(SIGWINCH, sigwinch);

	while(1) {
		fd_set fds;
		int ns;
		struct timeval tv;
		showtop(r);
		tv.tv_sec = s;
		tv.tv_usec = 0;

		FD_ZERO(&fds);
		FD_SET(STDIN_FILENO, &fds);
		if((ns=select(STDIN_FILENO+1, &fds, NULL, NULL, &tv)) < 0
			&& errno != EINTR) {
			perror("select");
			sleep(1);
		}

		if(ns > 0 && FD_ISSET(STDIN_FILENO, &fds)) {
			char c;
			if(read(STDIN_FILENO, &c, 1) == 1) {
				switch(c) {
					case 'q':
						return 0;
						break;
				}
			}
		}
	}

	return 0;
}
Example #3
0
/* Retrieve system load average information. */
int getloadavg(double *loadavg, int nelem)
{
  struct loadinfo loadinfo;
  static u32_t system_hz = 0;
  int h, p, unfilled_ticks;
#define PERIODS 3
  int minutes[3] = { 1, 5, 15 };
  size_t loadsize;
  ssize_t l;

  if(nelem < 1) {
	errno = ENOSPC;
	return -1;
  }

  if(system_hz == 0) {
  	if((getsysinfo_up(PM_PROC_NR, SIU_SYSTEMHZ,
	  sizeof(system_hz), &system_hz)) < 0) {
		system_hz = DEFAULT_HZ;
	}
  }

  loadsize = sizeof(loadinfo);
  if((l=getsysinfo_up(PM_PROC_NR, SIU_LOADINFO, loadsize, &loadinfo)) < 0)
	return -1;
  if(l != sizeof(loadinfo))
	return -1;
  if(nelem > PERIODS)
	nelem = PERIODS;

  /* How many ticks are missing from the newest-filled slot? */
#define TICKSPERSLOT (_LOAD_UNIT_SECS * system_hz)
  unfilled_ticks = TICKSPERSLOT - (loadinfo.last_clock % TICKSPERSLOT);

  for(p = 0; p < nelem; p++) {
    int h, offset, slots;
    double l = 0.0;
    int latest = loadinfo.proc_last_slot;
    slots = minutes[p] * 60 / _LOAD_UNIT_SECS;

    /* Add up the total number of process ticks for this number
     * of minutes (minutes[p]). Start with the newest slot, which
     * is latest, and count back for the number of slots that 
     * correspond to the right number of minutes. Take wraparound
     * into account by calculating the index modulo _LOAD_HISTORY,
     * which is the number of slots of history kept.
     */
    for(h = 0; h < slots; h++) {
       int slot;
       slot = (latest - h + _LOAD_HISTORY) % _LOAD_HISTORY;
       l += (double) loadinfo.proc_load_history[slot];
    }

    /* The load average over this number of minutes is the number of
     * process-ticks divided by the number of ticks, not counting the
     * number of ticks the last slot hasn't been around yet.
     */
    loadavg[p] = l / (slots * TICKSPERSLOT - unfilled_ticks);
  }

  return nelem;
}
Example #4
0
int main(int argc, char*argv[])
{
	char *ipstat_device;
	int fd, i, r;
	char *query, *pval;
	size_t len;
	struct timeval uptime;
	clock_t now;
	int fl;
	int a_flag, n_flag, v_flag;
	struct tms tmsbuf;

	getsysinfo_up(PM_PROC_NR, SIU_SYSTEMHZ, sizeof(system_hz), &system_hz);

	(prog_name=strrchr(argv[0], '/')) ? prog_name++ : (prog_name=argv[0]);

	a_flag= 0;
	n_flag= 0;
	v_flag= 0;
	while ((fl= getopt(argc, argv, "?anv")) != -1)
	{
		switch(fl)
		{
		case '?':
			usage();
		case 'a':
			a_flag= 1;
			break;
		case 'n':
			n_flag= 1;
			break;
		case 'v':
			v_flag= 1;
			break;
		default:
			fprintf(stderr, "%s: getopt failed: '%c'\n", 
				prog_name, fl);
			exit(1);
		}
	}
	inclListen= !!a_flag;
	numerical= !!n_flag;
	verbose= !!v_flag;

	ipstat_device= IPSTAT_DEVICE;
	if ((fd= open(ipstat_device, O_RDWR)) == -1)
	{
		fprintf(stderr, "%s: unable to open '%s': %s\n", prog_name,
			ipstat_device, strerror(errno));
		exit(1);
	}

	query= "tcp_conn_table";
	len= strlen(query);
	r= write(fd, query, len);
	if (r != len)
	{
		fprintf(stderr, "%s: write to %s failed: %s\n",
			prog_name, ipstat_device, r < 0 ? strerror(errno) :
			"short write");
		exit(1);
	}
	r= read(fd, values, sizeof(values));
	if (r == -1)
	{
		fprintf(stderr, "%s: read from %s failed: %s\n", prog_name,
			ipstat_device, strerror(errno));
		exit(1);
	}
	pval= values;
	if (paramvalue(&pval, tcp_conn_table, sizeof(tcp_conn_table)) !=
		sizeof(tcp_conn_table))
	{
		fprintf(stderr,
			"%s: unable to decode the results from queryparam\n",
			prog_name);
		exit(1);
	}

#ifdef __minix_vmd
	/* Get the uptime in clock ticks. */
	if (sysutime(UTIME_UPTIME, &uptime) == -1)
	{
		fprintf(stderr, "%s: sysutime failed: %s\n", prog_name,
			strerror(errno));
		exit(1);
	}
	now= uptime.tv_sec * HZ + (uptime.tv_usec*HZ/1000000);
#else	/* Minix 3 */
	now= times(&tmsbuf);
#endif

	for (i= 0; i<TCP_CONN_NR; i++)
		print_conn(i, now);
	exit(0);
}