fold java CurrentProcessSummary metric into sigar_proc_stat_t
This commit is contained in:
1 parent
578b7607db
commit
9a04924df3
5 files changed
+79
-98
No files matched your search
@@ -381,6 +381,31 @@ my %classes = (
|
||||
desc => 'Total number of processes',
|
||||
plat => '*'
|
||||
},
|
||||
{
|
||||
name => 'idle', type => 'Long',
|
||||
desc => 'Total number of processes in idle state',
|
||||
plat => '*'
|
||||
},
|
||||
{
|
||||
name => 'running', type => 'Long',
|
||||
desc => 'Total number of processes in run state',
|
||||
plat => '*'
|
||||
},
|
||||
{
|
||||
name => 'sleeping', type => 'Long',
|
||||
desc => 'Total number of processes in sleep state',
|
||||
plat => '*'
|
||||
},
|
||||
{
|
||||
name => 'stopped', type => 'Long',
|
||||
desc => 'Total number of processes in stop state',
|
||||
plat => '*'
|
||||
},
|
||||
{
|
||||
name => 'zombie', type => 'Long',
|
||||
desc => 'Total number of processes in zombie state',
|
||||
plat => '*'
|
||||
},
|
||||
],
|
||||
ProcExe => [
|
||||
{
|
||||
|
||||
@@ -1,95 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) [2004, 2005, 2006], Hyperic, Inc.
|
||||
* This file is part of SIGAR.
|
||||
*
|
||||
* SIGAR is free software; you can redistribute it and/or modify
|
||||
* it under the terms version 2 of the GNU General Public License as
|
||||
* published by the Free Software Foundation. This program is distributed
|
||||
* in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
|
||||
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA.
|
||||
*/
|
||||
|
||||
package org.hyperic.sigar;
|
||||
|
||||
/**
|
||||
* This class provides a summary of current process states.
|
||||
* @see org.hyperic.sigar.cmd.Top
|
||||
*/
|
||||
public class CurrentProcessSummary {
|
||||
private int total=0, sleeping=0, running=0, zombie=0, stopped=0;
|
||||
|
||||
private CurrentProcessSummary() { }
|
||||
|
||||
public static CurrentProcessSummary get(SigarProxy sigar)
|
||||
throws SigarException {
|
||||
|
||||
long[] pids = sigar.getProcList();
|
||||
CurrentProcessSummary summary =
|
||||
new CurrentProcessSummary();
|
||||
|
||||
for (int i=0; i<pids.length; i++) {
|
||||
ProcState state;
|
||||
|
||||
try {
|
||||
state = sigar.getProcState(pids[i]);
|
||||
} catch (SigarException e) {
|
||||
continue; //e.g. stale pid
|
||||
}
|
||||
|
||||
summary.total++;
|
||||
|
||||
switch (state.getState()) {
|
||||
case ProcState.RUN:
|
||||
summary.running++;
|
||||
break;
|
||||
case ProcState.STOP:
|
||||
summary.stopped++;
|
||||
break;
|
||||
case ProcState.SLEEP:
|
||||
summary.sleeping++;
|
||||
break;
|
||||
case ProcState.ZOMBIE:
|
||||
summary.zombie++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return summary;
|
||||
}
|
||||
|
||||
public int getTotal() {
|
||||
return this.total;
|
||||
}
|
||||
|
||||
public int getSleeping() {
|
||||
return this.sleeping;
|
||||
}
|
||||
|
||||
public int getRunning() {
|
||||
return this.running;
|
||||
}
|
||||
|
||||
public int getZombie() {
|
||||
return this.zombie;
|
||||
}
|
||||
|
||||
public int getStopped() {
|
||||
return this.stopped;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return
|
||||
this.total + " processes: " +
|
||||
this.sleeping + " sleeping, " +
|
||||
this.running + " running, " +
|
||||
this.zombie + " zombie, " +
|
||||
this.stopped + " stopped";
|
||||
}
|
||||
}
|
||||
@@ -26,7 +26,7 @@ import org.hyperic.sigar.SigarProxy;
|
||||
import org.hyperic.sigar.CpuPerc;
|
||||
import org.hyperic.sigar.SigarProxyCache;
|
||||
import org.hyperic.sigar.ProcCpu;
|
||||
import org.hyperic.sigar.CurrentProcessSummary;
|
||||
import org.hyperic.sigar.ProcStat;
|
||||
|
||||
/**
|
||||
* Display system resource utilization summaries and process information.
|
||||
@@ -45,6 +45,15 @@ public class Top {
|
||||
private static final String HEADER =
|
||||
"PID\tUSER\tSTIME\tSIZE\tRSS\tSHARE\tSTATE\tTIME\t%CPU\tCOMMAND";
|
||||
|
||||
private static String toString(ProcStat stat) {
|
||||
return
|
||||
stat.getTotal() + " processes: " +
|
||||
stat.getSleeping() + " sleeping, " +
|
||||
stat.getRunning() + " running, " +
|
||||
stat.getZombie() + " zombie, " +
|
||||
stat.getStopped() + " stopped";
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
Sigar sigarImpl = new Sigar();
|
||||
|
||||
@@ -56,7 +65,7 @@ public class Top {
|
||||
|
||||
System.out.println(Uptime.getInfo(sigar));
|
||||
|
||||
System.out.println(CurrentProcessSummary.get(sigar));
|
||||
System.out.println(toString(sigar.getProcStat()));
|
||||
|
||||
System.out.println(sigar.getCpuPerc());
|
||||
|
||||
|
||||
Reference in new issue
Block a user