Thursday, February 5, 2009

Drawing CPU part of boot chart

I'm using kstat for drawing CPU part of boot chart (see my previous posts). I need cpu values for "user","nice","system","idle","iowait" in such order (sample output):
cpu 8 0 141 313 230 0 0 

I've written the small kstat utility and added its call in a bootchartd script (utility writes /var/log/bootchart/proc_stat.log):
#include <kstat.h>
#include <sys/sysinfo.h>
#include <stdio.h>
#include <string.h>

static kstat_ctl_t *kc;
static kstat_t *ksp;

static unsigned int cpu_user, cpu_system, cpu_nice, cpu_idle, cpu_iowait;

int main(int argc, char **argv) {
cpu_stat_t *cpu_stat;

kc = kstat_open();

if (kc != NULL) {

ksp = kstat_lookup(kc, "cpu_stat", 0, "cpu_stat0");
if (ksp != NULL && ksp->ks_type == KSTAT_TYPE_RAW)
if (kstat_read(kc, ksp, NULL) != -1 &&  
ksp->ks_data_size == sizeof(cpu_stat_t))
  cpu_stat = (cpu_stat_t *)ksp->ks_data;
  cpu_system = cpu_stat->cpu_sysinfo.cpu[CPU_KERNEL] ;

 printf("cpu  %d %d %d %d %d 0 0\n",

Sample boot chart for MilaX:


Andre Lue said...

Really good stuff Alex. Keep up the good work. It's inspirational.

I would like to make one of EON but I'm a bit short on time.

Andre Lue said...

Would you mind sharing the kstat script?

.:: AuroraUX ::. said...

Hey Alex,

Great innovation, I'm following your work in my holiday time.
Not sure if I emailed you yet. However, we have test ISO's of AuroraUX for downloads. I hope we can work togther more to share our work for the greater good as soon as I get back to a workstation :)

Best Regards,
Edward O'Callaghan.

alhazred said...

Utility source added

Andre Lue said...

Alex can you take it further and get the /proc linux 2.6 kernel specific data somehow?

Unknown said...

How easy would it be to get some of this work made up into a package that anyone could install on OpenSolaris though IPS to get info about what's taking up all the time during boot process?

I'm currently taking 2 mins to boot, which I thought was bad but it's not far off some of your example charts, so I'm relieved! Still, with linux now on a sub 30 second boot time, there is lots of room for improvement!

Keep up the good work!

How to determine PXE mac address when booting illumos via PXELinux/iPXE

In illumos, if you need to determine the interface which was used for booting via PXE then it's possible to use "boot-mac" pro...