I'm trying to duplicate the following kstat code in jkstat:

# kstat -p cpu_stat:::execpgin
cpu_stat:0:cpu_stat0:execpgin   57553
cpu_stat:1:cpu_stat1:execpgin   53963
.
.

It doesn't look like you can use a filter to directly gather the kstat 
information using jkstat.  The filter's "getKstats()" method returns a Set of 
Kstats, with the module, instance, and name variables populated, but the actual 
Map of statistics is empty.  So, in order to actually get the statistics, I had 
to create the filter, get the Set of "empty" Kstats, then run "getKstat()" on 
each of them to actually get the statistic data.

Is there a better way to do this?  My java code is below:
<pre>
// Initialize JKstat and filter
JKstat jkstat = new JKstat();
KstatFilter ksf = new KstatFilter(jkstat);
ksf.addFilter("cpu_stat:::");
        
// Get the list of empty Kstats
Set <Kstat> vfilter = ksf.getKstats();

// Now iterate through them
Iterator kItr = vfilter.iterator();
while(kItr.hasNext()) {

    Kstat kstat = (Kstat)kItr.next();   

    // Use empty Kstat module, instance, and name data to get the statistic 
information
    Kstat kstat2 = 
jkstat.getKstat(kstat.getModule(),kstat.getInst(),kstat.getName());
    Map <String, KstatData> kstat2Map = kstat2.getMap();
    KstatData execpgin2Data = kstat2Map.get("execpgin");
    System.out.println(kstat2.getTriplet() + ":execpgin: " + 
        (Long)execpginData2.getData());

}
</pre>
 
 
--
This messages posted from opensolaris.org

Reply via email to