Adding Statistics to the Statset

[01] int addstat(int ix, struct SpmiStatSet *ssp, char *path, char *txt)
[02] {
[03]    cx_handle   *cxh;
[04]    int     i = ix;
[05]    char     tmp[128];
[06]    struct SpmiStatLink *statlink;
[07]
[08]    if (!(cxh = RSiPathGetCxx(rsh, path)))
[09]    {
[10]       fprintf(stderr, “RSiPathGetCxx can\'t access host %s (path %s)\n”, host, path);
[11]       exit(61);
[12]    }
[13]
[14]    if ((statlink = RSiFirstStatx(rsh, cxh, navn, desc)))
[15]    {
[16]       while (statlink)
[17]       {
[18]          if (i > 23)
[19]              break;
[20]          strcpy(head1[i], txt);
[21]          strcpy(head2[i], *navn);
[22]          strcpy(tmp, path);
[23]          strcat(tmp, “/”);
[24]          strcat(tmp, *navn);
[25]          if (!(svp[i] = RSiPathAddSetStatx(rsh, ssp, tmp)))
[26]             return(-1);
[27]          i++;
[28]          statlink = RSiNextStatx(rsh, cxh, statlink, navn, desc);
[29]       }
[30]    }
[31]  return(i);
[32] }

The use of RSiPathGetCxx by the sample program is shown in lines 8 through 12. Following that, in lines 14 through 30, two subroutines are used to get all the statistics values defined for the CPU context. This is done by using RSiFirstStatx and RSiNextStatx subroutines.

In lines 20-21, the short name of the context (“cpu0”) and the short name of the statistic are saved in two arrays for use when printing the column headings. Lines 22-24 construct the full path name of the statistics value by concatenating the full context path name and the short name of the value. This is necessary to proceed with adding the value to the SpmiStatSet with the RSiPathAddSetStatx. The value is added by using the lines 25 and 26.