예제 #1
0
파일: event.c 프로젝트: DundalkIT/pcp
static void
myvaluesetdump(pmValueSet *xvsp, int idx, int *flagsp)
{
    int			sts, flags = *flagsp;
    DescHash		*hp;
    __pmHashNode	*hnp;
    static __pmHashCtl	hash =  { 0, 0, NULL };

    if ((hnp = __pmHashSearch((unsigned int)xvsp->pmid, &hash)) == NULL) {
	/* first time for this pmid */
	hp = (DescHash *)malloc(sizeof(DescHash));
	if (hp == NULL) {
	    __pmNoMem("DescHash", sizeof(DescHash), PM_FATAL_ERR);
	    /*NOTREACHED*/
	}
	if ((sts = pmNameID(xvsp->pmid, &hp->name)) < 0) {
	    printf("	%s: pmNameID: %s\n", pmIDStr(xvsp->pmid), pmErrStr(sts));
	    free(hp);
	    return;
	}
	else {
	    if (xvsp->pmid != pmid_flags &&
		xvsp->pmid != pmid_missed &&
		(sts = pmLookupDesc(xvsp->pmid, &hp->desc)) < 0) {
		printf("	%s: pmLookupDesc: %s\n", hp->name, pmErrStr(sts));
		free(hp->name);
		free(hp);
		return;
	    }
	    if ((sts = __pmHashAdd((unsigned int)xvsp->pmid, (void *)hp, &hash)) < 0) {
		printf("	%s: __pmHashAdd: %s\n", hp->name, pmErrStr(sts));
		free(hp->name);
		free(hp);
		return;
	    }
	}
    }
    else
	hp = (DescHash *)hnp->data;

    if (idx == 0) {
	if (xvsp->pmid == pmid_flags) {
	    flags = *flagsp = xvsp->vlist[0].value.lval;
	    printf(" flags 0x%x", flags);
	    printf(" (%s) ---\n", pmEventFlagsStr(flags));
	    return;
	}
	else
	    printf(" ---\n");
    }
    if ((flags & PM_EVENT_FLAG_MISSED) &&
	(idx == 1) &&
	(xvsp->pmid == pmid_missed)) {
	printf("    ==> %d missed event records\n",
		    xvsp->vlist[0].value.lval);
	return;
    }
    mydump(hp->name, &hp->desc, xvsp);
}
예제 #2
0
파일: pminfo.c 프로젝트: rwongone/pcp
static void
dump_parameter(pmValueSet *xvsp, int index, int *flagsp)
{
    int		sts, flags = *flagsp;
    pmDesc	desc;
    char	**names;

    if ((sts = pmNameAll(xvsp->pmid, &names)) >= 0) {
        if (index == 0) {
            if (xvsp->pmid == pmid_flags) {
                flags = *flagsp = xvsp->vlist[0].value.lval;
                printf(" flags 0x%x", flags);
                printf(" (%s) ---\n", pmEventFlagsStr(flags));
                free(names);
                return;
            }
            else
                printf(" ---\n");
        }
        if ((flags & PM_EVENT_FLAG_MISSED) &&
                (index == 1) &&
                (xvsp->pmid == pmid_missed)) {
            printf("        ==> %d missed event records\n",
                   xvsp->vlist[0].value.lval);
            free(names);
            return;
        }
        printf("    ");
        __pmPrintMetricNames(stdout, sts, names, " or ");
        printf(" (%s)\n", pmIDStr(xvsp->pmid));
        free(names);
    }
    else
        printf("	PMID: %s\n", pmIDStr(xvsp->pmid));
    if ((sts = pmLookupDesc(xvsp->pmid, &desc)) < 0)
        printf("	pmLookupDesc: %s\n", pmErrStr(sts));
    else
        mydump(&desc, xvsp, "    ");
}
예제 #3
0
파일: pminfo.c 프로젝트: rwongone/pcp
static void
report(void)
{
    int		i;
    int		sts;
    pmDesc	desc;
    pmResult	*result = NULL;
    pmResult	*xresult = NULL;
    pmValueSet	*vsp = NULL;
    char	*buffer;
    int		all_count;
    int		*all_inst;
    char	**all_names;

    if (batchidx == 0)
        return;

    /* Lookup names.
     * Cull out names that were unsuccessfully looked up.
     * However, it is unlikely to fail because names come from a traverse PMNS.
     */
    if (need_pmid) {
        if ((sts = pmLookupName(batchidx, namelist, pmidlist)) < 0) {
            int j = 0;
            for (i = 0; i < batchidx; i++) {
                if (pmidlist[i] == PM_ID_NULL) {
                    printf("%s: pmLookupName: %s\n", namelist[i], pmErrStr(sts));
                    free(namelist[i]);
                }
                else {
                    /* assert(j <= i); */
                    pmidlist[j] = pmidlist[i];
                    namelist[j] = namelist[i];
                    j++;
                }
            }
            batchidx = j;
        }
    }

    if (p_value || verify) {
        if (opts.context == PM_CONTEXT_ARCHIVE) {
            if ((sts = pmSetMode(PM_MODE_FORW, &opts.origin, 0)) < 0) {
                fprintf(stderr, "%s: pmSetMode failed: %s\n", pmProgname, pmErrStr(sts));
                exit(1);
            }
        }
        if ((sts = pmFetch(batchidx, pmidlist, &result)) < 0) {
            for (i = 0; i < batchidx; i++)
                printf("%s: pmFetch: %s\n", namelist[i], pmErrStr(sts));
            goto done;
        }
    }

    for (i = 0; i < batchidx; i++) {

        if (p_desc || p_value || verify) {
            if ((sts = pmLookupDesc(pmidlist[i], &desc)) < 0) {
                printf("%s: pmLookupDesc: %s\n", namelist[i], pmErrStr(sts));
                continue;
            }
        }

        if (p_desc || p_help || p_value)
            /* Not doing verify, output separator  */
            putchar('\n');


        if (p_value || verify) {
            vsp = result->vset[i];
            if (p_force) {
                if (result->vset[i]->numval == PM_ERR_PROFILE) {
                    /* indom is non-enumerable; try harder */
                    if ((all_count = pmGetInDom(desc.indom, &all_inst, &all_names)) > 0) {
                        pmDelProfile(desc.indom, 0, NULL);
                        pmAddProfile(desc.indom, all_count, all_inst);
                        if (xresult != NULL) {
                            pmFreeResult(xresult);
                            xresult = NULL;
                        }
                        if (opts.context == PM_CONTEXT_ARCHIVE) {
                            if ((sts = pmSetMode(PM_MODE_FORW, &opts.origin, 0)) < 0) {
                                fprintf(stderr, "%s: pmSetMode failed: %s\n", pmProgname, pmErrStr(sts));
                                exit(1);
                            }
                        }
                        if ((sts = pmFetch(1, &pmidlist[i], &xresult)) < 0) {
                            printf("%s: pmFetch: %s\n", namelist[i], pmErrStr(sts));
                            continue;
                        }
                        vsp = xresult->vset[0];
                        /* leave the profile in the default state */
                        free(all_inst);
                        free(all_names);
                        pmDelProfile(desc.indom, 0, NULL);
                        pmAddProfile(desc.indom, 0, NULL);
                    }
                    else if (all_count == 0) {
                        printf("%s: pmGetIndom: No instances?\n", namelist[i]);
                        continue;
                    }
                    else {
                        printf("%s: pmGetIndom: %s\n", namelist[i], pmErrStr(all_count));
                        continue;
                    }
                }
            }
        }

        if (verify) {
            if (desc.type == PM_TYPE_NOSUPPORT)
                printf("%s: Not Supported\n", namelist[i]);
            else if (vsp->numval < 0)
                printf("%s: %s\n", namelist[i], pmErrStr(vsp->numval));
            else if (vsp->numval == 0)
                printf("%s: No value(s) available\n", namelist[i]);
            continue;
        }
        else
            /* not verify */
            printf("%s", namelist[i]);

        if (p_mid)
            printf(" PMID: %s", pmIDStr(pmidlist[i]));
        if (p_fullmid)
            printf(" = %d = 0x%x", pmidlist[i], pmidlist[i]);

        if (p_oneline) {
            if ((sts = pmLookupText(pmidlist[i], PM_TEXT_ONELINE, &buffer)) == 0) {
                if (p_fullmid)
                    printf("\n    ");
                else
                    putchar(' ');
                printf("[%s]", buffer);
                free(buffer);
            }
            else
                printf(" One-line Help: Error: %s\n", pmErrStr(sts));
        }
        putchar('\n');

        if (p_desc)
            __pmPrintDesc(stdout, &desc);

        if (p_help) {
            if ((sts = pmLookupText(pmidlist[i], PM_TEXT_HELP, &buffer)) == 0) {
                char	*p;
                for (p = buffer; *p; p++)
                    ;
                while (p > buffer && p[-1] == '\n') {
                    p--;
                    *p = '\0';
                }
                if (*buffer != '\0') {
                    printf("Help:\n");
                    printf("%s", buffer);
                    putchar('\n');
                }
                else
                    printf("Help: <empty entry>\n");
                free(buffer);
            }
            else
                printf("Full Help: Error: %s\n", pmErrStr(sts));
        }

        if (p_value) {
            mydump(&desc, vsp, NULL);
        }
    }

    if (result != NULL) {
        pmFreeResult(result);
        result = NULL;
    }
    if (xresult != NULL) {
        pmFreeResult(xresult);
        xresult = NULL;
    }

done:
    for (i = 0; i < batchidx; i++)
        free(namelist[i]);
    batchidx = 0;
}