Ejemplo n.º 1
0
void Profile::time(std::string name)
{
	assert(!CHECKERROR);
	
	if (ready)
	{
		//create query struct for "name" if there isn't one
		QueryMap::iterator q = queries.find(name);
		if (q == queries.end())
		{
			std::pair<QueryMap::iterator, bool> ret;
			ret = queries.insert(make_pair(name, Query()));
			q = ret.first;
		}
		
		//if "name" has already been set after begin(), ignore this call
		if (q->second.timeDiff > 0)
			return;
		
		//attach this timediff to "name"
		q->second.timeDiff = current;
		queryOrder.push_back(q->first);
		
		//move to the next query
		CHECKERROR;
		glQueryCounter(getNextQuery(), GL_TIMESTAMP);
		//NOTE: if this causes an error it's probably because you're using AMD
		//my guess is AMD won't allow two querys at the same time even of differing types
		CHECKERROR;
	}
}
Ejemplo n.º 2
0
DnsQuery* DnsLayer::addQuery(const std::string& name, DnsType dnsType, DnsClass dnsClass)
{
	// create new query on temporary buffer
	uint8_t newQueryRawData[256];
	DnsQuery* newQuery = new DnsQuery(newQueryRawData);

	newQuery->setDnsClass(dnsClass);
	newQuery->setDnsType(dnsType);

	// cannot return false since layer shouldn't be extended or shortened in this stage
	newQuery->setName(name);


	// find the offset in the layer to insert the new query
	size_t newQueryOffsetInLayer = sizeof(dnshdr);
	DnsQuery* curQuery = getFirstQuery();
	while (curQuery != NULL)
	{
		newQueryOffsetInLayer += curQuery->getSize();
		DnsQuery* nextQuery = getNextQuery(curQuery);
		if (nextQuery == NULL)
			break;
		curQuery = nextQuery;

	}

	// set next resource for new query. This must happen here for extendLayer to succeed
	if (curQuery != NULL)
		newQuery->setNexResource(curQuery->getNextResource());
	else
		newQuery->setNexResource(m_ResourceList);

	// extend layer to make room for the new query
	if (!extendLayer(newQueryOffsetInLayer, newQuery->getSize(), newQuery))
	{
		LOG_ERROR("Couldn't extend DNS layer, addQuery failed");
		delete newQuery;
		return NULL;
	}

	// connect the new query to layer
	newQuery->setDnsLayer(this, newQueryOffsetInLayer);

	// connect the new query to the layer's resource list
	if (curQuery != NULL)
		curQuery->setNexResource(newQuery);
	else // curQuery == NULL, meaning this is the first query
	{
		m_ResourceList = newQuery;
		m_FirstQuery = newQuery;
	}

	// increase number of queries
	getDnsHeader()->numberOfQuestions = htons(getQueryCount() + 1);

	return newQuery;
}
Ejemplo n.º 3
0
void Profile::begin()
{
	assert(!CHECKERROR);
	
	if (ready)
	{
		ready = false;
	}

	if (queries.size())
	{
		//if the last query is done, they are all done
		GLint available;
		glGetQueryObjectiv(queryObjs[current-1], GL_QUERY_RESULT_AVAILABLE, &available);
		if (available)
		{
			//get the results
			timeStamps.resize(queryObjs.size());
			for (int i = 0; i < (int)queryObjs.size(); ++i)
			{
				CHECKERROR;
				GLuint64 result;
				glGetQueryObjectui64vEXT(queryObjs[i], GL_QUERY_RESULT, &result);
				timeStamps[i] = result;
				CHECKERROR;
			}
			
			//append the differences to the samples list
			for (QueryMap::iterator it = queries.begin(); it != queries.end(); ++it)
			{
				if (it->second.timeDiff < 1) continue;
				GLuint64 timediff = timeStamps[it->second.timeDiff] - timeStamps[it->second.timeDiff-1];
				it->second.times.push_back(timediff);
				if (it->second.times.size() > PROFILE_SAMPLES)
					it->second.times.pop_front();
				it->second.timeDiff = -1;
			}
			
			//start the next set of samples
			ready = true;
			restartQueries();
		}
	}
	else
		ready = true;
	
	if (ready)
	{
		glQueryCounter(getNextQuery(), GL_TIMESTAMP);
	}
}