~vcs-imports/procps/main

« back to all changes in this revision

Viewing changes to top.c

  • Committer: albert
  • Date: 2006-06-25 02:15:35 UTC
  • Revision ID: Arch-1:procps@products.ubuntu.com%procps--MAIN--0--patch-500
top: show CPU time stolen from a virtual machine

Show diffs side-by-side

added added

removed removed

Lines of Context:
934
934
   if (!fgets(buf, sizeof(buf), fp)) std_err("failed /proc/stat read");
935
935
   cpus[Cpu_tot].x = 0;  // FIXME: can't tell by kernel version number
936
936
   cpus[Cpu_tot].y = 0;  // FIXME: can't tell by kernel version number
937
 
   num = sscanf(buf, "cpu %Lu %Lu %Lu %Lu %Lu %Lu %Lu",
 
937
   cpus[Cpu_tot].z = 0;  // FIXME: can't tell by kernel version number
 
938
   num = sscanf(buf, "cpu %Lu %Lu %Lu %Lu %Lu %Lu %Lu %Lu",
938
939
      &cpus[Cpu_tot].u,
939
940
      &cpus[Cpu_tot].n,
940
941
      &cpus[Cpu_tot].s,
941
942
      &cpus[Cpu_tot].i,
942
943
      &cpus[Cpu_tot].w,
943
944
      &cpus[Cpu_tot].x,
944
 
      &cpus[Cpu_tot].y
 
945
      &cpus[Cpu_tot].y,
 
946
      &cpus[Cpu_tot].z
945
947
   );
946
948
   if (num < 4)
947
949
         std_err("failed /proc/stat read");
957
959
      if (!fgets(buf, sizeof(buf), fp)) std_err("failed /proc/stat read");
958
960
      cpus[i].x = 0;  // FIXME: can't tell by kernel version number
959
961
      cpus[i].y = 0;  // FIXME: can't tell by kernel version number
960
 
      num = sscanf(buf, "cpu%u %Lu %Lu %Lu %Lu %Lu %Lu %Lu",
 
962
      cpus[i].z = 0;  // FIXME: can't tell by kernel version number
 
963
      num = sscanf(buf, "cpu%u %Lu %Lu %Lu %Lu %Lu %Lu %Lu %Lu",
961
964
         &cpus[i].id,
962
 
         &cpus[i].u, &cpus[i].n, &cpus[i].s, &cpus[i].i, &cpus[i].w, &cpus[i].x, &cpus[i].y
 
965
         &cpus[i].u, &cpus[i].n, &cpus[i].s, &cpus[i].i, &cpus[i].w, &cpus[i].x, &cpus[i].y, &cpus[i].z
963
966
      );
964
967
      if (num < 4)
965
968
            std_err("failed /proc/stat read");
1601
1604
      States_fmts = STATES_line2x5;
1602
1605
   if (linux_version_code >= LINUX_VERSION(2, 6, 0))  // grrr... only some 2.6.0-testX :-(
1603
1606
      States_fmts = STATES_line2x6;
 
1607
   if (linux_version_code >= LINUX_VERSION(2, 6, 11))
 
1608
      States_fmts = STATES_line2x7;
1604
1609
 
1605
1610
      /* get virtual page size -- nearing huge! */
1606
1611
   Page_size = getpagesize();
2874
2879
   // we'll trim to zero if we get negative time ticks,
2875
2880
   // which has happened with some SMP kernels (pre-2.4?)
2876
2881
#define TRIMz(x)  ((tz = (SIC_t)(x)) < 0 ? 0 : tz)
2877
 
   SIC_t u_frme, s_frme, n_frme, i_frme, w_frme, x_frme, y_frme, tot_frme, tz;
 
2882
   SIC_t u_frme, s_frme, n_frme, i_frme, w_frme, x_frme, y_frme, z_frme, tot_frme, tz;
2878
2883
   float scale;
2879
2884
 
2880
2885
   u_frme = cpu->u - cpu->u_sav;
2884
2889
   w_frme = cpu->w - cpu->w_sav;
2885
2890
   x_frme = cpu->x - cpu->x_sav;
2886
2891
   y_frme = cpu->y - cpu->y_sav;
2887
 
   tot_frme = u_frme + s_frme + n_frme + i_frme + w_frme + x_frme + y_frme;
 
2892
   z_frme = cpu->z - cpu->z_sav;
 
2893
   tot_frme = u_frme + s_frme + n_frme + i_frme + w_frme + x_frme + y_frme + z_frme;
2888
2894
   if (tot_frme < 1) tot_frme = 1;
2889
2895
   scale = 100.0 / (float)tot_frme;
2890
2896
 
2901
2907
         (float)i_frme * scale,
2902
2908
         (float)w_frme * scale,
2903
2909
         (float)x_frme * scale,
2904
 
         (float)y_frme * scale
 
2910
         (float)y_frme * scale,
 
2911
         (float)z_frme * scale
2905
2912
      )
2906
2913
   );
2907
2914
   Msg_row += 1;
2914
2921
   cpu->w_sav = cpu->w;
2915
2922
   cpu->x_sav = cpu->x;
2916
2923
   cpu->y_sav = cpu->y;
 
2924
   cpu->z_sav = cpu->z;
2917
2925
 
2918
2926
#undef TRIMz
2919
2927
}