Esempio n. 1
0
int
machine_init(struct statics * statics)

{
	ulong		ptr;

	if ((kmem = open(KMEM, O_RDONLY)) == -1)
	{
		perror(KMEM);
		return -1;
	}
	if ((mem = open(MEM, O_RDONLY)) == -1)
	{
		perror(MEM);
		return -1;
	}

	/* get the list of symbols we want to access in the kernel */
	if (nlist(VMUNIX, nlst) == -1)
	{
		fprintf(stderr, "pg_top: nlist failed\n");
		return -1;
	}
	/* make sure they were all found */

	/*
	 * ZZ if (check_nlist(nlst) > 0) return -1;
	 */

	proca = nlst[X_PROC].n_value;

	/* get the symbol values out of kmem */
	(void) getkval(nlst[X_CUR_CPU].n_value, (int *) (&cur_cpu), sizeof(cur_cpu),
				   nlst[X_CUR_CPU].n_name);
	(void) getkval(nlst[X_HZ].n_value, (int *) (&Hz), sizeof(Hz),
				   nlst[X_HZ].n_name);
	(void) getkval(nlst[X_V].n_value, (int *) (&v), sizeof(v),
				   nlst[X_V].n_name);

	/* this is used in calculating WCPU -- calculate it ahead of time */
	logcpu = log(fabs(loaddouble(cur_cpu)));

	/* allocate space for proc structure array and array of pointers */
	bytes = v.v_proc * sizeof(struct proc);
	pbase = (struct proc *) malloc(bytes);
	pref = (struct proc **) malloc(v.v_proc * sizeof(struct proc *));
	if (pbase == (struct proc *) NULL || pref == (struct proc **) NULL)
	{
		fprintf(stderr, "pg_top: cannot allocate sufficient memory\n");
		return -1;
	}

	/* fill in the statics information */
	statics->procstate_names = procstatenames;
	statics->cpustate_names = cpustatenames;
	statics->memory_names = memorynames;
	statics->order_names = ordernames;	/* hops */

	return 0;
}
Esempio n. 2
0
void
glibtop_get_loadavg_p (glibtop *server, glibtop_loadavg *buf)
{
	load_avg avenrun [3];
	int i;

	glibtop_init_p (server, (1 << GLIBTOP_SYSDEPS_LOADAVG), 0);

	memset (buf, 0, sizeof (glibtop_loadavg));

	/* !!! THE FOLLOWING CODE RUNS SGID KMEM - CHANGE WITH CAUTION !!! */

	setregid (server->machine->gid, server->machine->egid);

	/* get the load average array */

	(void) _glibtop_getkval (server, _glibtop_nlist [X_AVENRUN].n_value,
				 (int *) avenrun, sizeof (avenrun),
				 _glibtop_nlist [X_AVENRUN].n_name);

	if (setregid (server->machine->egid, server->machine->gid))
		_exit (1);

	/* !!! END OF SGID KMEM PART !!! */

	for (i = 0; i < 3; i++) {
		/* Calculate loadavg values from avenrun. */
		buf->loadavg [i] = loaddouble (avenrun [i]);
	}

	/* Now we can set the flags. */

	buf->flags = _glibtop_sysdeps_loadavg;
}
Esempio n. 3
0
void
get_system_info(struct system_info * si)

{
	int			i;
	int			avenrun[3];
	struct rminfo realmem;
	struct sysinfo sysinfo;
	static time_t cp_old[CPU_STATES];
	static time_t cp_diff[CPU_STATES];	/* for cpu state percentages */
	off_t		fswap;			/* current free swap in blocks */
	off_t		tswap;			/* total swap in blocks */

	(void) getkval(avenrun_offset, (int *) avenrun, sizeof(avenrun), "avenrun");

	for (i = 0; i < 3; i++)
	{
		si->load_avg[i] = loaddouble(avenrun[i]);
		si->load_avg[i] /= 1024.0;
	}

	if ((numcpus = sysmp(MP_NPROCS)) == -1)
	{
		perror("sysmp(MP_NPROCS)");
		return;
	}

	if (sysmp(MP_SAGET, MPSA_RMINFO, &realmem, sizeof(realmem)) == -1)
	{
		perror("sysmp(MP_SAGET,MPSA_RMINFO, ...)");
		return;
	}

	swapctl(SC_GETFREESWAP, &fswap);
	swapctl(SC_GETSWAPTOT, &tswap);

	memory_stats[0] = pagetok(realmem.physmem);
	memory_stats[1] = pagetok(realmem.availrmem);
	memory_stats[2] = pagetok(realmem.freemem);
	memory_stats[3] = tswap / 2;
	memory_stats[4] = fswap / 2;

	if (sysmp(MP_SAGET, MPSA_SINFO, &sysinfo, sizeof(struct sysinfo)) == -1)
	{
		perror("sysmp(MP_SAGET,MPSA_SINFO)");
		return;
	}
	(void) percentages(CPU_STATES, cpu_states, sysinfo.cpu, cp_old, cp_diff);

	si->cpustates = cpu_states;
	si->memory = memory_stats;
	si->last_pid = -1;

	return;
}
Esempio n. 4
0
void
get_system_info (struct system_info *si)
{
  long avenrun[3];
  struct sysinfo sysinfo;
  struct vmtotal total;
  struct anoninfo anoninfo;
  static time_t cp_old[CPUSTATES];
  static time_t cp_diff[CPUSTATES];	/* for cpu state percentages */
  register int i;

  getsysinfo(&sysinfo);

  /* convert cp_time counts to percentages */
  (void) percentages (CPUSTATES, cpu_states, sysinfo.cpu, cp_old, cp_diff);

  /* Find total CPU utilization, as a fraction of 1. */
  total_cpu = (cpu_states[CPU_USER] + cpu_states[CPU_KERNEL]) / 1000.0;

  /* get mpid -- process id of last process */
  (void) getkval (mpid_offset, &(si->last_pid), sizeof (si->last_pid),
		  "mpid");

  /* get load average array */
  (void) getkval (avenrun_offset, (int *) avenrun, sizeof (avenrun), "avenrun");

  /* convert load averages to doubles */
  for (i = 0; i < 3; i++)
    si->load_avg[i] = loaddouble (avenrun[i]);

  /* get total -- systemwide main memory usage structure */
  (void) getkval (total_offset, (int *) (&total), sizeof (total), "total");
  /* convert memory stats to Kbytes */
  memory_stats[0] = pagetok (total.t_rm);
  memory_stats[1] = pagetok (total.t_arm);
  memory_stats[2] = pagetok (total.t_free);
  (void) getkval (anoninfo_offset, (int *) (&anoninfo), sizeof (anoninfo),
		  "anoninfo");
  memory_stats[3] = pagetok (anoninfo.ani_max - anoninfo.ani_free);
  memory_stats[4] = pagetok (anoninfo.ani_max - anoninfo.ani_resv);

  /* set arrays and strings */
  si->cpustates = cpu_states;
  si->memory = memory_stats;
}
Esempio n. 5
0
void
get_system_info(struct system_info * si)
{
	long		avenrun[3];
	struct sysinfo sysinfo;
	static struct sysinfo *mpinfo = NULL;		/* array, per-processor
												 * sysinfo structures. */
	struct vmtotal total;
	struct anoninfo anoninfo;
	static long cp_old[CPUSTATES];
	static long cp_diff[CPUSTATES];		/* for cpu state percentages */
	static int	num_cpus;
	static int	fd_cpu = 0;
	register int i;

	if (use_stats == 1)
	{
		if (fd_cpu == 0)
		{
			if ((fd_cpu = open("/stats/cpuinfo", O_RDONLY)) == -1)
			{
				(void) fprintf(stderr, "%s: Open of /stats/cpuinfo failed\n", myname);
				quit(2);
			}
			if (read(fd_cpu, &num_cpus, sizeof(int)) != sizeof(int))
			{
				(void) fprintf(stderr, "%s: Read of /stats/cpuinfo failed\n", myname);
				quit(2);
			}
			close(fd_cpu);
		}
		if (mpinfo == NULL)
		{
			mpinfo = (struct sysinfo *) calloc(num_cpus, sizeof(mpinfo[0]));
			if (mpinfo == NULL)
			{
				(void) fprintf(stderr, "%s: can't allocate space for per-processor sysinfos\n", myname);
				quit(12);
			}
		}
		/* Read the per cpu sysinfo structures into mpinfo struct. */
		read_sysinfos(num_cpus, mpinfo);
		/* Add up all of the percpu sysinfos to get global sysinfo */
		sysinfo_data(num_cpus, &sysinfo, mpinfo);
	}
	else
	{
		(void) getkval(sysinfo_offset, &sysinfo, sizeof(struct sysinfo), "sysinfo");
	}

	/* convert cp_time counts to percentages */
	(void) percentages(CPUSTATES, cpu_states, sysinfo.cpu, cp_old, cp_diff);

	/* get mpid -- process id of last process */
	(void) getkval(mpid_offset, &(si->last_pid), sizeof(si->last_pid),
				   "mpid");

	/* get load average array */
	(void) getkval(avenrun_offset, (int *) avenrun, sizeof(avenrun), "avenrun");

	/* convert load averages to doubles */
	for (i = 0; i < 3; i++)
		si->load_avg[i] = loaddouble(avenrun[i]);

	/* get total -- systemwide main memory usage structure */
	(void) getkval(total_offset, (int *) (&total), sizeof(total), "total");
	/* convert memory stats to Kbytes */
	memory_stats[0] = pagetok(total.t_rm);
	memory_stats[1] = pagetok(total.t_arm);
	memory_stats[2] = pagetok(total.t_free);
	(void) getkval(anoninfo_offset, (int *) (&anoninfo), sizeof(anoninfo),
				   "anoninfo");
	memory_stats[3] = pagetok(anoninfo.ani_max - anoninfo.ani_free);
	memory_stats[4] = pagetok(anoninfo.ani_max - anoninfo.ani_resv);

	/* set arrays and strings */
	si->cpustates = cpu_states;
	si->memory = memory_stats;
}