Traversing contexts
The
adddisk
function in the following
list shows how the RSiFirstCxx
, RSiNextCx
x,
and the RSiInstantiatex
subroutines are combined
with RSiPathGetCxx
to make sure all subcontexts are
accessed. The sample program's addstat internal
function is used to add the statistics of each subcontext to the SpmiStatSet
structure.
A programmer who wanted to traverse all levels of subcontexts below
a start context could easily create a recursive function to do this.01] int adddisk(int ix, struct SpmiStatSet *ssp, char *path)
[02] {
[03] int i = ix;
[04] char tmp[128];
[05] cx_handle *cxh;
[06] struct SpmiStatLink *statlink;
[07] struct SpmiCxLink *cxlink;
[08]
[09] cxh = RSiPathGetCxx(rsh, path);
[10] if ((!cxh) || (!cxh->cxt))
[11] {
[12] if (strlen(RSiEMsg))
[13] fprintf(stderr, “%s”, RSiEMsg);
[14] fprintf(stderr, “RSiPathGetCxx can\'t access host %s (path %s)\n”,
[15] host, path);
[16] exit(64);
[17] }
[18] if (rsh->pi->data.getcx.context.inst_freq == SiContInst)
[19] {
[20] if ((i = RSiInstantiatex(rsh, cxh)))
[21] return(-1);
[22] }
[23] if ((cxlink = RSiFirstCxx(rsh, cxh, navn, desc)))
[24] {
[25] while (cxlink)
[26] {
[27] strcpy(tmp, path);
[28] if (strlen(tmp))
[29] strcat(tmp, “/”);
[30] if (*navn)
[31] strcat(tmp, *navn);
[32] if ((i = addstat(i, ssp, tmp, *navn)) == -1)
[33] {
[34] if (strlen(RSiEMsg))
[35] fprintf(stderr, “%s”, RSiEMsg);
[36] exit(63);
[37] }
[38] cxlink = RSiNextCxx(rsh, cxh, cxlink, navn, desc);
[39] }
[40] }
[41] return(i);
[42] }
The output from the
RsiCons
program
when run on the xmtopas daemon on an AIX operating
system host is shown in the following example.$ RsiCons encee
CPU CPU CPU CPU hdisk3 hdisk1 hdisk0 cd0
uticks kticks wticks iticks xfer xfer xfer xfer
19.6 10.0 4.1 67.1 2.7 4.1 0.0 0.0
10.9 15.3 8.2 65.3 0.0 8.2 0.0 0.0
0.5 2.0 0.0 97.5 0.0 0.0 0.0 0.0
10.5 4.0 0.0 85.5 0.0 0.0 0.0 0.0
55.4 8.9 0.0 35.4 2.4 0.0 0.0 0.0
19.0 5.5 0.0 75.5 0.0 0.0 0.0 0.0
5.9 6.4 0.0 87.4 0.0 0.0 0.0 0.0
10.5 7.0 0.0 82.5 0.0 0.0 0.0 0.0
7.9 7.4 0.0 84.4 0.0 0.0 0.0 0.0
88.5 8.5 3.0 0.0 9.5 4.5 0.0 0.0
89.4 8.9 1.4 0.0 5.9 0.0 0.0 0.0
92.5 5.5 2.0 0.0 9.0 8.5 0.0 0.0
71.0 6.0 23.0 0.0 44.0 41.0 0.0 0.0
37.9 2.4 58.9 0.4 67.9 61.4 0.0 0.0
17.5 4.5 0.0 78.0 1.5 3.0 0.0 0.0
0.5 1.5 10.0 88.0 7.5 1.5 0.0 0.0
$