Ejemplo n.º 1
0
char *
format_next_process(caddr_t handle, char *(*get_userid) ())

{
	struct prpsinfo *pp;
	struct handle *hp;
	long		cputime;

	/* find and remember the next proc structure */
	hp = (struct handle *) handle;
	pp = *(hp->next_proc++);
	hp->remaining--;

	/* get the process cpu usage since startup */
	cputime = pp->pr_time.tv_sec;

	/* format this entry */
	sprintf(fmt,
			Proc_format,
			pp->pr_pid,
			pp->pr_pgrp,
			(*get_userid) (pp->pr_uid),
			format_prio(pp),
			format_k(pagetok(pp->pr_size)),
			format_k(pagetok(pp->pr_rssize)),
			format_state(pp),
			format_time(cputime),
			clip_percent(weighted_cpu(pp)),
			clip_percent(percent_cpu(pp)),
			printable(pp->pr_fname));

	/* return the result */
	return (fmt);
}
Ejemplo n.º 2
0
char *
format_next_process(caddr_t handle, char *(*get_userid)(uid_t))
{
	char *p_wait, waddr[sizeof(void *) * 2 + 3];	/* Hexify void pointer */
	struct kinfo_proc2 *pp;
	struct handle *hp;
	int cputime;
	double pct;

	/* find and remember the next proc structure */
	hp = (struct handle *) handle;
	pp = *(hp->next_proc++);
	hp->remaining--;

	cputime = (pp->p_uticks + pp->p_sticks + pp->p_iticks) / stathz;

	/* calculate the base for cpu percentages */
	pct = pctdouble(pp->p_pctcpu);

	if (pp->p_wchan) {
		if (pp->p_wmesg)
			p_wait = pp->p_wmesg;
		else {
			snprintf(waddr, sizeof(waddr), "%llx",
			    (unsigned long long)(pp->p_wchan & ~KERNBASE));
			p_wait = waddr;
		}
	} else
		p_wait = "-";

	/* format this entry */
	snprintf(fmt, sizeof fmt, Proc_format,
	    pp->p_pid, (*get_userid)(pp->p_ruid),
	    pp->p_priority - PZERO, pp->p_nice - NZERO,
	    format_k(pagetok(PROCSIZE(pp))),
	    format_k(pagetok(pp->p_vm_rssize)),
	    (pp->p_stat == SSLEEP && pp->p_slptime > maxslp) ?
	    "idle" : state_abbr(pp),
	    p_wait, format_time(cputime), 100.0 * pct,
	    printable(format_comm(pp)));

	/* return the result */
	return (fmt);
}
Ejemplo n.º 3
0
char *
format_next_process(caddr_t handle, char *(*get_userid) (uid_t))
{
	static char fmt[MAX_COLS];	/* static area where result is built */
	struct top_proc *p = *nextactive++;

	snprintf(fmt, sizeof(fmt),
			 "%5d %-8.8s %3d %4d %5s %5s %-5s %6s %5.2f%% %5.2f%% %s",
			 p->pid,
			 (*get_userid) (p->uid),
			 p->pri < -99 ? -99 : p->pri,
			 p->nice,
			 format_k(p->size),
			 format_k(p->rss),
			 state_abbrev[p->state],
			 format_time(p->time / HZ),
			 p->wcpu * 100.0,
			 p->pcpu * 100.0,
			 p->name);

	/* return the result */
	return (fmt);
}
Ejemplo n.º 4
0
char *
format_next_process(
					caddr_t handle,
					char *(*get_userid) ())
{
	register struct prpsinfo *pp;
	struct handle *hp;
	register long cputime;
	register double pctcpu;

	/* find and remember the next proc structure */
	hp = (struct handle *) handle;
	pp = *(hp->next_proc++);
	hp->remaining--;

	/* get the cpu usage and calculate the cpu percentages */
	cputime = pp->pr_time.tv_sec;
	pctcpu = percent_cpu(pp);

	/* format this entry */
	(void) sprintf(fmt,
				   Proc_format,
				   pp->pr_pid,
				   (*get_userid) (pp->pr_uid),
				   pp->pr_pri - PZERO,
				   pp->pr_nice - NZERO,
				   format_k(pagetok(pp->pr_size)),
				   format_k(pagetok(pp->pr_rssize)),
				   state_abbrev[pp->pr_state],
				   format_time(cputime),
				   (pp->pr_cpu & 0377),
				   100.0 * pctcpu,
				   printable(pp->pr_fname));

	/* return the result */
	return (fmt);
}
Ejemplo n.º 5
0
static void
summary_format(char *buf, size_t left, int *numbers, char **names)
{
	char *p, *thisname;
	size_t len;
	int num;

	/* format each number followed by its string */
	p = buf;
	while ((thisname = *names++) != NULL) {
		/* get the number to format */
		num = *numbers++;

		if (num >= 0) {
			/* is this number in kilobytes? */
			if (thisname[0] == 'K') {
				/* yes: format it as a memory value */
				COPYLEFT(p, format_k(num));

				/*
				 * skip over the K, since it was included by
				 * format_k
				 */
				COPYLEFT(p, thisname + 1);
			} else if (num > 0) {
				len = snprintf(p, left, "%d%s", num, thisname);
				if (len == (size_t)-1 || len >= left)
					return;
				p += len;
				left -= len;
			}
		} else {
			/*
			 * Ignore negative numbers, but display corresponding
			 * string.
			 */
			COPYLEFT(p, thisname);
		}
	}

	/* if the last two characters in the string are ", ", delete them */
	p -= 2;
	if (p >= buf && p[0] == ',' && p[1] == ' ')
		*p = '\0';
}
Ejemplo n.º 6
0
char *
format_next_process(caddr_t handle, char *(*getuserid) ())
{
	register struct macos_proc *pp;
	register long cputime;
	register double pct;
	struct handle *hp;
	char *command; /* text outputted to describe the command */
	int show_cmd_local = show_fullcmd;

	/*
	 * we need to keep track of the next proc structure.
	 */

	hp = (struct handle *) handle;
	pp = *(hp->next_proc++);
	hp->remaining--;

	/*
	 * get the process structure and take care of the cputime
	 */

	if ((MPP(pp, p_flag) & P_INMEM) == 0)
	{
		/* we want to print swapped processes as <pname> */
		char *comm = MPP(pp, p_comm);

#define COMSIZ	sizeof(MPP(pp, p_comm))
		char		buf[COMSIZ];

		strncpy(buf, comm, COMSIZ);
		comm[0] = '<';
		strncpy(&comm[1], buf, COMSIZ - 2);
		comm[COMSIZ - 2] = '\0';
		strncat(comm, ">", COMSIZ - 1);
		comm[COMSIZ - 1] = '\0';
		command = comm;
	}

	/*
	 * count the cpu time, but ignore the interrupts
	 *
	 * At the present time (DR2 8/1998), MacOS X doesn't correctly report this
	 * information through the kinfo_proc structure.  We need to get it from
	 * the task threads.
	 *
	 * cputime = PP(pp, p_rtime).tv_sec;
	 */

	cputime = RP(pp, user_time).seconds + RP(pp, system_time).seconds;

	/*
	 * calculate the base cpu percentages
	 *
	 * Again, at the present time, MacOS X doesn't report this information
	 * through the kinfo_proc.	We need to talk to the threads.
	 */

	pct = (double) (RP(pp, cpu_usage)) / TH_USAGE_SCALE;

	/* get the process's command name in to "cmd" */
	if (show_fullcmd)
 		if (get_fullcmd(MPP(pp, p_pid), pp->fullcmd) < 0)
			show_cmd_local = 0; /* Don't show if full command not found. */

	/*
	 * format the entry
	 */

	/*
	 * In the final version, I would expect this to work correctly, but it
	 * seems that not all of the fields in the proc structure are being used.
	 *
	 * For now, we'll attempt to get some of the things we need from the mach
	 * task info.
	 */

	sprintf(fmt,
			Proc_format,
			MPP(pp, p_pid),
			(*getuserid) (MEP(pp, e_pcred.p_ruid)),
			0,
			pp->thread_count,
			format_k(TASKSIZE(pp) / 1024),
			format_k(pagetok(RSSIZE(pp))),
			state_abbrev[(u_char) MPP(pp, p_stat)],
			format_time(cputime),
			100.0 * TP(pp, resident_size) / maxmem,
			100.0 * pct,
			(show_cmd_local == 0 ? command : pp->fullcmd));

	return (fmt);
}
Ejemplo n.º 7
0
char *format_next_process(caddr_t handle, char *(*get_userid)())
{
    register struct proc *pp;
    register long cputime;
    register double pct, wcpu, pctmem;
    int where;
    struct user u;
    struct handle *hp;
    register int p_pctcpu;
    register int rm_size;
    register int vm_size;
    register int run_state;
    register int flags;
    register int nthreads;
    register int cur_priority;
    char state_str[10];

    /* find and remember the next proc structure */
    hp = (struct handle *)handle;
    pp = hp->list[hp->current].p_self;
    p_pctcpu = hp->list[hp->current].p_pctcpu;
    cputime = hp->list[hp->current].p_cptime;
    rm_size = hp->list[hp->current].p_rsize;
    vm_size = hp->list[hp->current].p_vsize;
    run_state = hp->list[hp->current].run_state;
    flags = hp->list[hp->current].flags;
    nthreads = hp->list[hp->current].nthreads;
    cur_priority = hp->list[hp->current].cur_priority;
    hp->current++;
    hp->count--;

    /* get the process's user struct and set cputime */
    where = getu(pp, &u);
    if (where == -1)
    {
        (void) strcpy(u.u_comm, "<swapped>");
        cputime = 0;
    }
    else
    {
        /* set u_comm for system processes */
        if (u.u_comm[0] == '\0')
        {
            if (pp->p_pid == 0)
            {
                (void) strcpy(u.u_comm, "Swapper");
            }
            else if (pp->p_pid == 2)
            {
                (void) strcpy(u.u_comm, "Pager");
            }
        }
        if (where == 1) {
            /*
            * Print swapped processes as <pname>
            */
            char buf[sizeof(u.u_comm)];
            (void) strncpy(buf, u.u_comm, sizeof(u.u_comm));
            u.u_comm[0] = '<';
            (void) strncpy(&u.u_comm[1], buf, sizeof(u.u_comm) - 2);
            u.u_comm[sizeof(u.u_comm) - 2] = '\0';
            (void) strncat(u.u_comm, ">", sizeof(u.u_comm) - 1);
            u.u_comm[sizeof(u.u_comm) - 1] = '\0';
        }
        /*	User structure does not work.  Use Thread Info to get cputime for process. */
        /*		cputime = u.u_ru.ru_utime.tv_sec + u.u_ru.ru_stime.tv_sec; */
    }


    /* calculate the base for cpu percentages */
    pct = (double)(p_pctcpu)/TH_USAGE_SCALE;
    /*	wcpu = weighted_cpu(pct, pp);
     */
    pctmem = (double)(rm_size*1024.) / (double)(host_stats.memory_size);

    /* Get process state description */
    if(run_state)
    {
        strcpy(state_str, mach_state[run_state]);
        strcat(state_str, flags_state[flags]);
    } else {
        strcpy(state_str, state_abbrev[pp->p_stat]);
    }

    /* format this entry */
    sprintf(fmt,
            Proc_format,
            pp->p_pid,
            (*get_userid)(pp->p_uid),
            state_str,
            cur_priority,
            /*	    pp->p_pri - PZERO, */
            pp->p_nice - NZERO,
            nthreads,
            format_k(vm_size),
            format_k(rm_size),
            100.0 * pctmem,
            /*	    100.0 * wcpu, */
            100.0 * pct,
            format_time(cputime),
            printable(u.u_comm));

    /* return the result */
    return(fmt);
}
Ejemplo n.º 8
0
char *
format_next_process(caddr_t handle, char *(*get_userid) ())

{
	register struct proc *pp;
	register time_t cputime;
	register double pct;
	int			where;
	struct user u;
	struct handle *hp;
	char		command[29];
	char	   *process;
	char	   *process2;

	/* find and remember the next proc structure */
	hp = (struct handle *) handle;
	pp = *(hp->next_proc++);
	hp->remaining--;

	/* get the process's user struct and set cputime */
	if ((where = sysi86(RDUBLK, pp->p_pid, &u, sizeof(struct user))) != -1)
		where = (pp->p_flag & SLOAD) ? 0 : 1;
	if (where == -1)
	{
		strcpy(command, "<swapped>");
		cputime = 0;
	}
	else
	{
		/* set u_comm for system processes */
		if (u.u_comm[0] == '\0')
		{
			if (pp->p_pid == 0)
				strcpy(command, "Swapper");
			else if (pp->p_pid == 2)
				strcpy(command, "Pager");
			else if (pp->p_pid == 3)
				strcpy(command, "Sync'er");
		}
		else if (where == 1)
		{
			/* print swapped processes as <pname> */
			register char *s1;

			u.u_psargs[28 - 3] = '\0';
			strcpy(command, "<");
			strcat(command, strtok(u.u_psargs, " "));
			strcat(command, ">");
			while (s1 = (char *) strtok(NULL, " "))
				strcat(command, s1);
		}
		else
		{
			sprintf(command, "%s", u.u_psargs);
		}
		cputime = u.u_utime + u.u_stime;
/*	   cputime = pp->p_utime + pp->p_stime;  */
	}
	/* calculate the base for cpu percentages */
	pct = pctdouble(pp->p_cpu);

	/*
	 * psargs gives the absolute path of the process... strip it to only the
	 * command - [Changes by D. Currie & M. Muldner Aitt NS Canada]
	 */
	process = printable(command);
#if NO_COMMAND_ARGS
	strtok(process, " ");
#endif
	process2 = strrchr(process, '/');
	if (process2)
	{
		process = process2;
		process++;
	}


	/* format this entry */
	sprintf(fmt,
			Proc_format,
			pp->p_pid,
			(*get_userid) (pp->p_uid),
			pp->p_pri - PZERO,
			pp->p_nice - NZERO,
			format_k(PROCSIZE(&u)),		/* same as	pp->p_size * 4 */
			proc_residentsize(pp),
			state_abbrev[pp->p_stat],
			format_time(cputime / Hz),
			printable(process));

	return (fmt);
}