Example #1
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);
	}
    }
}
Example #2
0
void
QmcMetric::removeInst(uint index)
{
    Q_ASSERT(hasInstances());
    indom()->removeRef(my.values[index].instance());
    my.values.removeAt(index);
}
Example #3
0
void
QmcMetric::dumpEventMetric(QTextStream &os, bool srcFlag, uint instance) const
{
    Q_ASSERT(event());

    for (int i = 0; i < my.values.size(); i++) {
	int instID;

	if (srcFlag == true)
	    dumpSource(os);
	os << name();

	instID = PM_IN_NULL;
	if (hasInstances()) {
	    if (instance != UINT_MAX)
		instID = (int)instance;
	    else
		instID = my.values[i].instance();

	    QString inst = instName(instID);
	    if (inst == QString::null)
		os << "[" << instID << "]";
	    else
		os << "[\"" << inst << "\"]";
	}
	os << ": ";
	my.values[i].dumpEventRecords(os, instID);
    }
}
Example #4
0
QString
QmcMetric::spec(bool srcFlag, bool instFlag, uint instance) const
{
    QString str;
    int i, len = 4;

    if (srcFlag)
	len += context()->source().source().size();
    len += name().size();
    if (hasInstances() && instFlag) {
	if (instance != UINT_MAX)
	    len += instName(instance).size() + 2;
	else
	    for (i = 0; i < numInst(); i++)
		len += instName(i).size() + 4;
    }

    if (srcFlag) {
	str.append(context()->source().source());
	if (context()->source().type() == PM_CONTEXT_ARCHIVE)
	    str.append(QChar('/'));
	else
	    str.append(QChar(':'));
    }
    str.append(name());
    if (hasInstances() && instFlag) {
	str.append(QChar('['));
	str.append(QChar('\"'));
	if (instance != UINT_MAX)
	    str.append(instName(instance));
	else if (numInst()) {
	    str.append(instName(0));
	    for (i = 1; i < numInst(); i++) {
		str.append("\", \"");
		str.append(instName(i));
	    }
	}
	str.append("\"]");
    }

    return str;
}
Example #5
0
void Mesh::draw() const
{
	glCheck(glBindVertexArray(mVAO));

	if (mType == Mesh::Elements) {
		if (hasInstances()) {
			glCheck(glDrawElementsInstanced(GL_TRIANGLES, mIndices.size(), GL_UNSIGNED_INT, 0, mAmount));
		}
		else {
			glCheck(glDrawElements(GL_TRIANGLES, mIndices.size(), GL_UNSIGNED_INT, 0));
		}
	}
	else {
		if (hasInstances()) {
			glCheck(glDrawArraysInstanced(GL_TRIANGLE_STRIP, 0, mVertices.size(), mAmount));
		}
		else {
			glCheck(glDrawArrays(GL_TRIANGLE_STRIP, 0, mVertices.size()));
		}
	}

	glCheck(glBindVertexArray(0));
}
Example #6
0
int
QmcMetric::addInst(QString const& name)
{
    if (my.status < 0)
	return my.status;

    if (!hasInstances())
	return PM_ERR_INDOM;

    int i = indom()->lookup(name);
    if (i >= 0) {
	setupValues(my.values.size() + 1);
	my.values.last().setInstance(i);
    }

    return i;
}
Example #7
0
void
QmcMetric::dumpSampledMetric(QTextStream &stream, bool srcFlag, uint instance) const
{
    Q_ASSERT(!event());

    stream << name();

    if (srcFlag == true)
	dumpSource(stream);

    if (my.status < 0)
	stream << ": " << pmErrStr(my.status) << endl;
    else if (hasInstances()) {
	if (instance == UINT_MAX) {
	    if (numInst() == 1)
		stream << ": 1 instance";
	    else
		stream << ": " << numInst() << " instances";
	    if (indom()->changed())
		stream << " (indom has changed)";
	    stream << endl;

	    for (int i = 0; i < numInst(); i++) {
		stream << "  [" << instID(i) << " or \"" << instName(i)
		       << "\" (" << my.values[i].instance() << ")] = ";
		dumpValue(stream, i);
		stream << endl;
	    }
	}
	else {
	    stream << '[' << instID(instance) << " or \"" << instName(instance) 
		   << "\" (" << my.values[instance].instance() << ")] = ";
	    dumpValue(stream, instance);
	    stream << endl;
	}
    }
    else {
	stream << " = ";
	dumpValue(stream, 0);
	stream << endl;
    }
}
Example #8
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();
    }
}
Example #9
0
QmcMetric::~QmcMetric()
{
    if (hasInstances())
	for (int i = 0; i < my.values.size(); i++)
	    indom()->removeRef(my.values[i].instance());
}