Monitor Core utilization in Solaris Sparc

I am trying to read the Sparc HW counter using the following command:

cpustat -c Instr_cnt .1

This command will be running forever (for some time until interrupted by user). Sample output is:

   time  cpu   event      pic1      
  1.011   0      tick      6450    
  1.011   1       tick      9681   
  1.011   2       tick      2015  
  1.012   3       tick       535 
  1.012   4       tick       615   
   1.012   5      tick      7513  
   1.012   6      tick       615 
   1.013   7      tick      5187 
   1.013   8      tick       615 
   1.013   9      tick       615  
  1.013  10       tick       615   
   1.014  11      tick     60077  
  1.014  12       tick       438  
  1.014  13       tick       615  
  1.014  14       tick       615  
  1.015  15       tick       615
   1.015  16      tick       615 
   1.015  17       tick       438  
   1.016  18       tick       615  
   1.016  19       tick       615
  ^C  

\

I am trying to get every 4 cpu's in a core (each core has 4 cpus), add the number in pic1 and average them. Once the average reaches some threshold number, I want to do some load balancing. I think the logic is: put all the elements from line 2 in an array, and then add every 4 of them. Looking for an output like:

**Core#      Average# of Inst    Utilization (#ofInst/cpu_cycle_perSec)**
   Core_0         xxxxxxxx             10%
   Core_1         xxxxxxxx             20%  
   and so on....

I am novice in coding and if anyone could help me with some simple direction to do this, that would be great. This can be done in shell/python.
Thanks in advance.

This should give the first two columns. It is unclear how you want to compute the third one.

nawk '
BEGIN {
  printf("%-8s %-8s\n","Core_#", "Inst avg");
}
{
  c=($2+1)%4;
  s+=$4
  if(c==0)
  {
    printf("Core_%03d %8d\n", (($2+1)/4)-1, s);
    s=0
  }
}
' 

Thanks.
What if i wnated to run the cpustat command for every .1 second but make the average core utilization every secind and make decision accordingly?

Use SAR for that.

And I do wonder what the point of this is. CPUs are bought to be used.

I don't think SAR is available for Solaris SPARC.
The CPU pooling is for a work that I am trying to do, thus utilizing a part of the total available.
:slight_smile:

What's the point of a 100 ms sampling rate if you look for a 1 second average anyway?

Note that sar is available for Solaris and has always been regardless of the architecture but it is quite outdated with modern hardware and is unsuitable to per core monitoring.

I am trying to read the average of 100ms sampling every 1 second and see what sort of average utilization we are seeing per core. so after 1 second I can make decision that whether I add another CPU to the pool or not (for example).

[not sure whether this answers the question, but feel free to provide your opinions...:-)]

You cannot parameter cpustat to sample 100 ms and do nothing for 900 ms, if it is what you mean.

so "cpustat" would keep on continuing getting samples every 100ms. I want to get the 10 sets of samples (i.e. worth of 1 second) for each core and average that and see on average what is the utilization of the Core.

Then just sample with a one second interval. There is no point getting ten consecutive 100 ms samples if only to sum them.

Yes it most certainly is.