Exemplo n.º 1
0
QmcMetric *
QmcGroup::addMetric(pmMetricSpec *theMetric, double theScale, bool active)
{
    QmcMetric *metric = new QmcMetric(this, theMetric, theScale, active);
    if (metric->status() >= 0)
	metric->context()->addMetric(metric);
    return metric;
}
Exemplo n.º 2
0
QmcMetric *
QmcGroup::addMetric(char const *string, double theScale, bool active)
{
    QmcMetric *metric = new QmcMetric(this, string, theScale, active);
    if (metric->status() >= 0)
	metric->context()->addMetric(metric);
    return metric;
}
Exemplo n.º 3
0
static int
traverse(const char *str, double scale)
{
    pmMetricSpec	*theMetric;
    char		*msg;
    int			sts = 0;

    sts = pmParseMetricSpec((char *)str, 0, (char *)0, &theMetric, &msg);
    if (sts < 0) {
	pmprintf("%s: Error: Unable to parse metric spec:\n%s\n", 
		 pmProgname, msg);
	free(msg);
	return sts;
    }

    // If the metric has instances, then it cannot be traversed
    if (theMetric->ninst) {
	QmcMetric *metric = group->addMetric(theMetric, scale);
	if (metric->status() >= 0) {
	    checkUnits(metric);
	    metrics.append(metric);
	    numValues += metric->numValues();
	}
	else
	    sts = -1;
    }
    else {
	if (theMetric->isarch == 0)
	    doMetricType = PM_CONTEXT_HOST;
	else if (theMetric->isarch == 1)
	    doMetricType = PM_CONTEXT_ARCHIVE;
	else if (theMetric->isarch == 2)
	    doMetricType = PM_CONTEXT_LOCAL;
	else {
	    pmprintf("%s: Error: invalid metric source (%d): %s\n",
			 pmProgname, theMetric->isarch, theMetric->metric);
	    sts = -1;
	}
	doMetricSource = theMetric->source;
	if (sts >= 0)
	   sts = group->use(doMetricType, doMetricSource);
	if (sts >= 0) {
	    doMetricScale = scale;
	    sts = pmTraversePMNS(theMetric->metric, dometric);
	    if (sts >= 0 && doMetricFlag == false)
		sts = -1;
	    else if (sts < 0) {
		pmprintf("%s: Error: %s: %s\n",
			 pmProgname, theMetric->metric, pmErrStr(sts));
	    }
	}
    }

    free(theMetric);

    return sts;
}
Exemplo n.º 4
0
static void
dometric(const char *name)
{
    QString	fullname = doMetricSource;

    if (fullname.length()) {
	if (doMetricType == PM_CONTEXT_ARCHIVE)
	    fullname.append(QChar('/'));
	else
	    fullname.append(QChar(':'));
    }
    fullname.append(name);

    QmcMetric* metric = group->addMetric((const char *)fullname.toAscii(),
						doMetricScale);
    if (metric->status() >= 0) {
	checkUnits(metric);
	metrics.append(metric);
	numValues += metric->numValues();
    }
    else
	doMetricFlag = false;
}
Exemplo n.º 5
0
int
QmcContext::fetch(bool update)
{
    int i, sts;
    pmResult *result;

    for (i = 0; i < my.metrics.size(); i++) {
        QmcMetric *metric = my.metrics[i];
        if (metric->status() < 0)
            continue;
        metric->shiftValues();
    }

    // Inform each indom that we are about to do a new fetch so any
    // indom changes are now irrelevant
    for (i = 0; i < my.indoms.size(); i++)
        my.indoms[i]->newFetch();

    sts = pmUseContext(my.context);
    if (sts >= 0) {
        for (i = 0; i < my.indoms.size(); i++) {
            if (my.indoms[i]->diffProfile())
                sts = my.indoms[i]->genProfile();
        }
    }
    else if (pmDebug & DBG_TRACE_OPTFETCH) {
        QTextStream cerr(stderr);
        cerr << "QmcContext::fetch: Unable to switch to this context: "
             << pmErrStr(sts) << endl;
    }

    if (sts >= 0 && my.needReconnect) {
        sts = pmReconnectContext(my.context);
        if (sts >= 0) {
            my.needReconnect = false;
            if (pmDebug & DBG_TRACE_PMC) {
                QTextStream cerr(stderr);
                cerr << "QmcContext::fetch: Reconnected context \""
                     << *my.source << endl;
            }
        }
        else if (pmDebug & DBG_TRACE_PMC) {
            QTextStream cerr(stderr);
            cerr << "QmcContext::fetch: Reconnect failed: "
                 << pmErrStr(sts) << endl;
        }
    }

    if (sts >= 0 && my.pmids.size()) {
        if (pmDebug & DBG_TRACE_OPTFETCH) {
            QTextStream cerr(stderr);
            cerr << "QmcContext::fetch: fetching context " << *this << endl;
        }

        sts = pmFetch(my.pmids.size(),
                      (pmID *)(my.pmids.toVector().data()), &result);
        if (sts >= 0) {
            my.previousTime = my.currentTime;
            my.currentTime = result->timestamp;
            my.delta = __pmtimevalSub(&my.currentTime, &my.previousTime);
            for (i = 0; i < my.metrics.size(); i++) {
                QmcMetric *metric = my.metrics[i];
                if (metric->status() < 0)
                    continue;
                Q_ASSERT((int)metric->idIndex() < result->numpmid);
                metric->extractValues(result->vset[metric->idIndex()]);
            }
            pmFreeResult(result);
        }
        else {
            if (pmDebug & DBG_TRACE_OPTFETCH) {
                QTextStream cerr(stderr);
                cerr << "QmcContext::fetch: pmFetch: " << pmErrStr(sts) << endl;
            }
            for (i = 0; i < my.metrics.size(); i++) {
                QmcMetric *metric = my.metrics[i];
                if (metric->status() < 0)
                    continue;
                metric->setError(sts);
            }
            if (sts == PM_ERR_IPC || sts == PM_ERR_TIMEOUT)
                my.needReconnect = true;
        }

        if (update) {
            if (pmDebug & DBG_TRACE_OPTFETCH) {
                QTextStream cerr(stderr);
                cerr << "QmcContext::fetch: Updating metrics" << endl;
            }
            for (i = 0; i < my.metrics.size(); i++) {
                QmcMetric *metric = my.metrics[i];
                if (metric->status() < 0)
                    continue;
                metric->update();
            }
        }
    }
    else if (pmDebug & DBG_TRACE_OPTFETCH) {
        QTextStream cerr(stderr);
        cerr << "QmcContext::fetch: nothing to fetch" << endl;
    }

    return sts;
}