//creates a sorted list of profile reports to work with
bool CreateProfileReportsFromProfileMap(ProfileReports& outProfileReports, bool sortReports) {
	outProfileReports.clear();
	for (ProfileMapIterator it = s_profileMap.begin(); it != s_profileMap.end(); ++it) {
		ProfileReport& report = (it->second);
		outProfileReports.push_back(report);
	}

	if (sortReports) {
		QuickSort(outProfileReports, outProfileReports.size(), 0);
	}

	return (!outProfileReports.empty());
}
static void createDrawable(unsigned long long orig_config, unsigned long long orig_surface)
{
    ProfileMap::iterator it = profile_map.find(orig_config);
    glprofile::Profile profile;

    // If the requested config is associated with a profile, use that
    // profile. Otherwise, assume that the last used profile is what
    // the user wants.
    if (it != profile_map.end()) {
        profile = it->second;
    } else {
        profile = last_profile;
    }

    glws::Drawable *drawable = glretrace::createDrawable(profile);
    drawable_map[orig_surface] = drawable;
}
void ProfileSection::AddProfileToMap(const std::string& profileName){
	profileCritSec.Enter();
	ProfileMapIterator profileEntry = s_profileMap.find(profileName);
	//if entry exists, increment existing entry
	if (profileEntry != s_profileMap.end()){
		ProfileReport& existingProfile = (profileEntry->second);

		//assumes elapsed time already set
		existingProfile.m_totalElapsedTime += elapsedTime;
		existingProfile.m_numCalls++;//= numCalls;
		
		existingProfile.SetAverageElapsedTime();
	}
	else{
		//numCalls++;
		//add entry
		s_profileMap.insert(ProfileEntry(profileName, ProfileReport(profileName, totalElapsedTime, numCalls)));
		//Access violation reading location 0xBAADF00D. serious memory corruption here O.o
	}
	profileCritSec.Exit();
}