/* * Copyright (c) 2014-2015 Red Hat, Inc. All Rights Reserved. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. */ /* * Test fetch group instance domain consistency for metrics in * the same fetch group that share an instance domain. */ #include #include #include #include #define MAXINST 1000 void FAIL(char *m) { fprintf(stderr, "FAIL %s\n", m); abort(); } int main () { pmFG fg; pmAtomValue rssvals[MAXINST]; pmAtomValue vssvals[MAXINST]; pmAtomValue pidvals[MAXINST]; int inst_rss[MAXINST], inst_vss[MAXINST]; char *names_rss[MAXINST], *names_vss[MAXINST]; int errs[MAXINST]; int i, j; unsigned nrss, nvss, npid; int sts, out_sts; int c = pmNewContext(PM_CONTEXT_HOST, "local:"); if (c < 0) FAIL("pmNewContext"); sts = pmCreateFetchGroup(&fg); if (sts != 0) FAIL("pmCreateFetchGroup"); sts = pmExtendFetchGroup_indom(fg, "proc.psinfo.rss", NULL, inst_rss, names_rss, rssvals, PM_TYPE_U64, errs, MAXINST, &nrss, &out_sts); if (sts != 0) FAIL("pmExtendFetchGroup_indom(proc.psinfo.rss)"); sts = pmExtendFetchGroup_indom(fg, "proc.psinfo.vsize", NULL, inst_vss, names_vss, vssvals, PM_TYPE_U64, errs, MAXINST, &nvss, &out_sts); if (sts != 0) FAIL("pmExtendFetchGroup_indom(proc.psinfo.vsize)"); /* * For proc.psinfo.pid, inst and names are NULL * - so we can check against rss and vss indoms */ sts = pmExtendFetchGroup_indom(fg, "proc.psinfo.pid", NULL, NULL, NULL, pidvals, PM_TYPE_U32, NULL, MAXINST, &npid, NULL); if (sts != 0) FAIL("pmExtendFetchGroup_indom(proc.psinfo.pid)"); for (j=0; j < 100; j++) { sts = pmFetchGroup(fg); /* instance domains should be the same */ if (nrss != nvss) FAIL("nrss != nvss"); if (nrss != npid) FAIL("nrss != npid"); for (i=0; i < npid; i++) { /* proc.psinfo.{rss,vsize} share an instance domain */ if (inst_rss[i] != inst_vss[i]) FAIL("inst_rss != inst_vss"); /* proc.psinfo.pid value should match the instance */ if (pidvals[i].ul != inst_rss[i]) FAIL("proc.psinfo.pid inst != value"); } } sts = pmDestroyFetchGroup(fg); if (sts != 0) FAIL("pmDestroyFetchGroup"); pmDestroyContext (c); }