Пример #1
0
int
QmcContext::lookupInDom(QmcDesc *descPtr, uint_t& indom)
{
    int i, sts;
    QmcIndom *indomPtr;

    if ((sts = pmUseContext(my.context)) < 0)
        return sts;

    indom = UINT_MAX;
    if (descPtr->desc().indom != PM_INDOM_NULL) {
        for (i = 0; i < my.indoms.size(); i++)
            if (my.indoms[i]->id() == (int)descPtr->desc().indom)
                break;
        if (i == my.indoms.size()) {
            indomPtr = new QmcIndom(my.source->type(), *descPtr);
            if (indomPtr->status() < 0) {
                sts = indomPtr->status();
                delete indomPtr;
                return sts;
            }
            my.indoms.append(indomPtr);
            indom = my.indoms.size() - 1;
            if (pmDebug & DBG_TRACE_PMC) {
                QTextStream cerr(stderr);
                cerr << "QmcContext::lookupInDom: Add indom for "
                     << pmInDomStr(indomPtr->id()) << endl;
            }
        }
        else {
            indomPtr = my.indoms[i];
            indom = i;
            if (pmDebug & DBG_TRACE_PMC) {
                QTextStream cerr(stderr);
                cerr << "QmcContext::lookupInDom: Reusing indom "
                     << pmInDomStr(indomPtr->id()) << endl;
            }
        }
    }
    return 0;
}
Пример #2
0
void
QmcMetric::extractValues(pmValueSet const* set)
{
    int i, j, index, inst;
    pmValue const *value = NULL;
    bool found;
    QmcIndom *indomPtr = indom();

    Q_ASSERT(set->pmid == desc().id());

    if (set->numval > 0) {
	if (hasIndom()) {
	    // If the number of instances are not the expected number
	    // then mark the indom as changed
	    if (!my.explicitInst && (my.values.size() != set->numval)) {
		if (pmDebug & DBG_TRACE_INDOM) {
		    QTextStream cerr(stderr);
		    cerr << "QmcMetric::extractValues: implicit indom "
			 << pmInDomStr(indomPtr->id()) << " changed ("
			 << set->numval << " != " << my.values.size() << ')'
			 << endl;
		}
		indomPtr->hasChanged();
		updateIndom();
	    }

	    for (i = 0; i < numInst(); i++) {
		QmcMetricValue &valueRef = my.values[i];
		inst = my.values[i].instance();
		index = indomPtr->index(inst);
		found = false;

		// If the index is within range, try it first
		if (index >= 0 && index < set->numval) {
		    value = &(set->vlist[index]);

		    // Found it in the same spot as last time
		    if (value->inst == indomPtr->inst(inst))
			found = true;
		}

		// Search for it from the top
		for (j = 0; found == false && j < set->numval; j++) {
		    if (set->vlist[j].inst == indomPtr->inst(inst)) {
			index = j;
			value = &(set->vlist[j]);
			indomPtr->setIndex(inst, j);
			found = true;
		    }
		}

		if (found) {
		    if (real())
			extractNumericMetric(set, value, valueRef);
		    else if (!event())
			extractArrayMetric(set, value, valueRef);
		    else
			extractEventMetric(set, index, valueRef);
		}
		else {	// Cannot find it
		    if (pmDebug & DBG_TRACE_OPTFETCH) {
			QTextStream cerr(stderr);
			cerr << "QmcMetric::extractValues: "
			     << spec(true, true, i) << ": "
			     << pmErrStr(PM_ERR_VALUE) << endl;
		    }

		    if (valueRef.previousError() != PM_ERR_VALUE)
			indomPtr->hasChanged();

		    valueRef.setCurrentError(PM_ERR_VALUE);
		}
	    }
	}
	else if (set->numval == 1) {
	    // We have no instances at this point in time
	    if (my.values.size() == 0 && hasInstances())
		indomPtr->hasChanged();
	    else {
		QmcMetricValue &valueRef = my.values[0];
		value = &(set->vlist[0]);

		if (real())
		    extractNumericMetric(set, value, valueRef);
		else if (!event())
		    extractArrayMetric(set, value, valueRef);
		else
		    extractEventMetric(set, 0, valueRef);
	    }
	}
	else {	// Did not expect any instances
	    if (pmDebug & DBG_TRACE_OPTFETCH) {
		QTextStream cerr(stderr);
		cerr << "QmcMetric::extractValues: " << spec(true) 
		     << " is a singular metric but result contained "
		     << set->numval << " values" << endl;
	    }
	    setError(PM_ERR_VALUE);
	}
    }
    else if (set->numval == 0) {
	if (!(hasInstances() && numInst() == 0)) {
	    if (pmDebug & DBG_TRACE_OPTFETCH) {
		QTextStream cerr(stderr);
		cerr << "QmcMetric::extractValues: numval == 0: "
		     << spec(true, false) << ": " << pmErrStr(PM_ERR_VALUE)
		     << endl;
	    }
	    setError(PM_ERR_VALUE);
	    if (hasInstances())
		indomPtr->hasChanged();
	}
    }
    else {
	if (pmDebug & DBG_TRACE_OPTFETCH) {
	    QTextStream cerr(stderr);
	    cerr << "QmcMetric::extractValues: numval < 0: "
		 << spec(true, false)
		 << ": " << pmErrStr(set->numval) << endl;
	}
	setError(set->numval);
	if (hasInstances())
	    indomPtr->hasChanged();
    }
}
Пример #3
0
void
QmcMetric::setupIndom(pmMetricSpec *metricSpec)
{
    int i, j;
    QmcIndom *indomPtr = indom();
    
    if (!hasIndom()) {
	if (metricSpec->ninst > 0) {
	    my.status = PM_ERR_INST;
	    dumpErr(metricSpec->inst[0]);
	}
	else
	    setupValues(1);
    }
    else if (metricSpec->ninst) {
	Q_ASSERT(hasInstances());
	setupValues(metricSpec->ninst);

	for (i = 0 ; i < metricSpec->ninst && my.status >= 0; i++) {
	    j = indomPtr->lookup(metricSpec->inst[i]);
	    if (j >= 0)
		my.values[i].setInstance(j);
	    else {
		my.status = PM_ERR_INST;
		my.values[i].setInstance(PM_ERR_INST);
		dumpErr(metricSpec->inst[i]);
	    }
	}
	my.explicitInst = true;
    }
    else {
	Q_ASSERT(hasInstances());

	if (my.active) {
	    setupValues(indomPtr->numActiveInsts());
	    indomPtr->refAll(my.active);

	    for (i = 0, j = 0; i < indomPtr->listLen(); i++)
		if (!indomPtr->nullInst(i) && indomPtr->activeInst(i))
		    my.values[j++].setInstance(i);
	}
	else {
	    setupValues(indomPtr->numInsts());
	    indomPtr->refAll(my.active);
  
	    for (i = 0, j = 0; i < indomPtr->listLen(); i++)
		if (!indomPtr->nullInst(i))
		    my.values[j++].setInstance(i);
	}
    }
}
Пример #4
0
bool
QmcMetric::updateIndom(void)
{
    int i = 0, j, oldNum = numInst(), newNum, newInst;
    QmcIndom *indomPtr = indom();

    if (status() < 0 || !hasIndom())
	return false;

    if (indomPtr->changed())
	indomPtr->update();

    my.explicitInst = false;

    newNum = my.active ? indomPtr->numActiveInsts() : indomPtr->numInsts();

    // If the number of instances are the same then we know that no
    // modifications to the metric instance list is required as these
    // instances are all referenced in the indom
    //
    // If the instance list is only active instances, then we need to
    // check all the instances as the number may be the same
    //
    if (newNum == oldNum) {
	if (my.active) {
	    for (i = 0; i < my.values.size(); i++)
		if (!indomPtr->activeInst(my.values[i].instance()))
		    break;
	}
	if (!my.active || i == my.values.size()) {
	    if (pmDebug & DBG_TRACE_INDOM) {
		QTextStream cerr(stderr);
		cerr << "QmcMetric::updateIndom: No change required" << endl;
	    }
	    return false;
	}
    }

    // Duplicate the current values
    // Replace the old index into the indom instance list with the
    // internal instance identifiers so that these can be correlated
    // if the order of instances changes
    QList<QmcMetricValue> oldValues = my.values;
    for (i = 0; i < oldNum; i++) {
	oldValues[i].setInstance(indomPtr->inst(my.values[i].instance()));
	indomPtr->removeRef(my.values[i].instance());
    }

    setupValues(newNum);
    indomPtr->refAll(my.active);

    if (my.active) {
	for (i = 0, j = 0; i < indomPtr->listLen(); i++)
	    if (!indomPtr->nullInst(i) && indomPtr->activeInst(i))
		my.values[j++].setInstance(i);
    }
    else {
	for (i = 0, j = 0; i < indomPtr->listLen(); i++)
	    if (!indomPtr->nullInst(i))
		my.values[j++].setInstance(i);
    }

    // Copy values of instances that have not gone away
    // Note that their position may have changed
    for (i = 0; i < my.values.size(); i++) {
	if (i < oldValues.size() &&
	    indomPtr->inst(my.values[i].instance()) ==
					oldValues[i].instance()) {
	    newInst = my.values[i].instance();
	    my.values[i] = oldValues[i];
	    my.values[i].setInstance(newInst);
	    continue;
	}
	for (j = 0; j < oldValues.size(); j++)
	    if (indomPtr->inst(my.values[i].instance()) ==
					oldValues[j].instance()) {
		newInst = my.values[i].instance();
		my.values[i] = oldValues[j];
		my.values[i].setInstance(newInst);
		break;
	    }

	// Need to set all error flags to avoid problems with rate conversion
	if (j == oldValues.size())
	    my.values[i].setAllErrors(PM_ERR_VALUE);
    }

    if (pmDebug & DBG_TRACE_PMC) {
	QTextStream cerr(stderr);
	cerr << "QmcMetric::updateIndom: " << spec(true) << ": Had " 
	     << oldNum << " instances, now have " << numInst() << endl;
    }

    indomPtr->update();

    return true;
}
Пример #5
0
int
main(int argc, char* argv[])
{
    int		fail = 0, sts = 0;
    int		c;
    char	buf[MAXHOSTNAMELEN];
    QString	source;

    pmSetProgname(argv[0]);

    while ((c = getopt(argc, argv, "D:?")) != EOF) {
	switch (c) {
	case 'D':
	    sts = pmSetDebug(optarg);
            if (sts < 0) {
		pmprintf("%s: unrecognized debug options specification (%s)\n",
			 pmGetProgname(), optarg);
                fail = 1;
            }
            break;
	case '?':
	default:
	    sts = 1;
	    break;
	}
    }

    if (fail) {
	pmprintf("Usage: %s\n", pmGetProgname());
	pmflush();
	exit(1);
    }

    (void)gethostname(buf, MAXHOSTNAMELEN);
    buf[MAXHOSTNAMELEN-1] = '\0';

    fprintf(stderr, "*** Simple connection ***\n");
    source = QString("oview-short");

    QmcSource *src1 = QmcSource::getSource(PM_CONTEXT_ARCHIVE, source, false);
    if (src1->status() < 0) {
	pmprintf("%s: Error: Unable to create context to \"%s\": %s\n",
		pmGetProgname(), (const char *)source.toLatin1(),
		pmErrStr(src1->status()));
	pmflush();
	fail = 1;
    }

    QmcContext context1(src1);
    if (context1.handle() < 0) {
	pmflush();
	fail = 1;
    }

    context1.dump(cout);

    pmID pmid;
    uint32_t indomIndex;

    fprintf(stderr, "\n*** Cacheing of descriptors and indoms ***\n");
    QmcDesc *desc;
    QmcIndom *indom = NULL;

    sts = context1.lookupInDom("hinv.ncpu", indomIndex);
    if (sts < 0) {
	pmprintf("%s: Error: hinv.ncpu: %s\n",
		 pmGetProgname(), pmErrStr(sts));
	pmflush();
	fail = 1;
    }
    else {
	sts = context1.lookupPMID("hinv.ncpu", pmid);
	if (sts < 0) {
	    pmprintf("%s: Error: hinv.ncpu PMID: %s\n",
		 pmGetProgname(), pmErrStr(sts));
	    pmflush();
	    fail = 1;
	}
	desc = &context1.desc(pmid);
	if (desc->status() < 0) {
	    pmprintf("%s: Error: hinv.ncpu descriptor: %s\n",
		     pmGetProgname(), pmErrStr(desc->status()));
	    pmflush();
	    fail = 1;
	}
	else if (indomIndex < UINT_MAX) {
	    pmprintf("%s: Error: hinv.ncpu indom is not NULL\n",
		     pmGetProgname());
	    pmflush();
	    fail = 1;
	}
    }

    sts = context1.lookupInDom("hinv.cputype", indomIndex);
    if (sts < 0) {
	pmprintf("%s: Error: hinv.cputype: %s\n",
		 pmGetProgname(), pmErrStr(sts));
	pmflush();
	fail = 1;
    }
    else {
	sts = context1.lookupPMID("hinv.cputype", pmid);
	if (sts < 0) {
	    pmprintf("%s: Error: hinv.cputype PMID: %s\n",
		pmGetProgname(), pmErrStr(sts));
	    pmflush();
	    fail = 1;
	}
	desc = &context1.desc(pmid);
	indom = &context1.indom(indomIndex);
	if (desc->status() < 0) {
	    pmprintf("%s: Error: hinv.cputype descriptor: %s\n",
		     pmGetProgname(), pmErrStr(desc->status()));
	    pmflush();
	    fail = 1;
	}
	else if (indom->status() < 0) {
	    pmprintf("%s: Error: hinv.cputype indom: %s\n",
		     pmGetProgname(), pmErrStr(indom->status()));
	    pmflush();
	    fail = 1;
	}
    }

    QmcIndom *indom2;

    sts = context1.lookupInDom("hinv.map.cpu", indomIndex);
    if (sts < 0) {
	pmprintf("%s: Error: hinv.map.cpu: %s\n",
		 pmGetProgname(), pmErrStr(sts));
	pmflush();
	fail = 1;
    }
    else {
	sts = context1.lookupPMID("hinv.map.cpu", pmid);
	if (sts < 0) {
	    pmprintf("%s: Error: hinv.map.cpu PMID: %s\n",
		pmGetProgname(), pmErrStr(sts));
	    pmflush();
	    fail = 1;
	}

	desc = &context1.desc(pmid);
	indom2 = &context1.indom(indomIndex);

	if (desc->status() < 0) {
	    pmprintf("%s: Error: hinv.map.cpu descriptor: %s\n",
		     pmGetProgname(), pmErrStr(desc->status()));
	    pmflush();
	    fail = 1;
	}
	else if (indom2->status() < 0) {
	    pmprintf("%s: Error: hinv.map.cpu indom: %s\n",
		     pmGetProgname(), pmErrStr(indom2->status()));
	    pmflush();
	    fail = 1;
	}
	else if (indom != indom2) {
	    pmprintf("%s: Error: hinv.cputype and hinv.map.cpu indoms are not the same\n",
		     pmGetProgname());
	    pmflush();
	    fail = 1;
	}
    }

    sts = context1.lookupInDom("hinv.ncpu", indomIndex);
    if (sts < 0) {
	pmprintf("%s: Error: hinv.ncpu: %s\n",
		 pmGetProgname(), pmErrStr(sts));
	pmflush();
	fail = 1;
    }
    else {
	sts = context1.lookupPMID("hinv.ncpu", pmid);
	if (sts < 0) {
	    pmprintf("%s: Error: hinv.ncpu PMID: %s\n",
		pmGetProgname(), pmErrStr(sts));
	    pmflush();
	    fail = 1;
	}

	desc = &context1.desc(pmid);

	if (desc->status() < 0) {
	    pmprintf("%s: Error: hinv.ncpu descriptor: %s\n",
		     pmGetProgname(), pmErrStr(desc->status()));
	    pmflush();
	    fail = 1;
	}
	else if (indomIndex < UINT_MAX) {
	    pmprintf("%s: Error: hinv.ncpu indom is not NULL\n",
		     pmGetProgname());
	    pmflush();
	    fail = 1;
	}
    }

    context1.dump(cout);

    fprintf(stderr, "\n*** Bad Context ***\n");
    source = QString("no-such-host");
    QmcSource *src2 = QmcSource::getSource(PM_CONTEXT_HOST, source);

    if (src2->status() >= 0) {
	pmprintf("%s: Error: Able to create context to \"%s\": %s\n",
		pmGetProgname(), (const char *)source.toLatin1(),
		pmErrStr(src1->status()));
	pmflush();
	fail = 1;
    }

    QmcContext context2(src2);

    if (context2.handle() >= 0) {
	pmprintf("%s: Error: Created a valid context to an invalid host\n",
		 pmGetProgname());
	fail = 1;
    }

    pmflush();

    context2.dump(cout);

    fprintf(stderr, "\n*** Exiting ***\n");
    
    pmflush();
    return fail;
}