<commit_before>#include "../common/graycom.h"
#include "strings.h"
#include "threads.h"

ProfileData::ProfileData()
{
	// we don't want to use SetActive here because ADDTOCALLSTACK will cause an infinite loop

	memset(m_AverageTimes, 0, sizeof(m_AverageTimes));
	memset(m_CurrentTimes, 0, sizeof(m_CurrentTimes));
	memset(m_PreviousTimes, 0, sizeof(m_PreviousTimes));
	memset(m_EnabledProfiles, 0, sizeof(m_EnabledProfiles));

	m_iActiveWindowSeconds = 10;
	m_iAverageCount = 1;

	LONGLONG llTicks;
	TIME_PROFILE_START;

	m_CurrentTime = llTicks;
	m_CurrentTask = PROFILE_IDLE;
	m_TimeTotal = 0;
}

void ProfileData::SetActive(int iSampleSec)
{
	ADDTOCALLSTACK("ProfileData::SetActive");

	memset(m_AverageTimes, 0, sizeof(m_AverageTimes));
	memset(m_CurrentTimes, 0, sizeof(m_CurrentTimes));
	memset(m_PreviousTimes, 0, sizeof(m_PreviousTimes));

	m_iActiveWindowSeconds = iSampleSec;
	m_iAverageCount		= 1;

	if (m_iActiveWindowSeconds == 0)
		return;

	LONGLONG llTicks;
	TIME_PROFILE_START;

	m_CurrentTime = llTicks;
	m_CurrentTask = PROFILE_OVERHEAD;
	m_TimeTotal = 0;
}

void ProfileData::Start(PROFILE_TYPE id)
{
	ADDTOCALLSTACK("ProfileData::Start");
	if (( id < 0 ) || ( id >= PROFILE_TIME_QTY ) || !m_iActiveWindowSeconds )
		return;

	// ensure profile is enabled
	EnableProfile(id);

	// Stop prev task.
	if ( m_TimeTotal >= (llTimeProfileFrequency * m_iActiveWindowSeconds) )
	{
		for ( int i = 0; i < PROFILE_DATA_QTY; i++ )
		{
			if ( m_iAverageCount < 4 )
			{
				memcpy( m_AverageTimes, m_CurrentTimes, sizeof( m_AverageTimes ));
			}
			else
			{
				if ( m_PreviousTimes[i].m_Time > llTimeProfileFrequency )
					m_PreviousTimes[i].m_Time = llTimeProfileFrequency;

				m_AverageTimes[i].m_Time	= (((m_AverageTimes[i].m_Time * 90) + (m_PreviousTimes[i].m_Time * 10)) / 100);
				m_AverageTimes[i].m_iCount	= (((m_AverageTimes[i].m_iCount * 95) + (m_PreviousTimes[i].m_iCount * 10)) / 100);<commit_msg>- Fixed ProfileData::Start clearing 'total' statistic for PROFILE_STAT_FAULTS at the same time as resetting average times.<commit_after>#include "../common/graycom.h"
#include "strings.h"
#include "threads.h"

ProfileData::ProfileData()
{
	// we don't want to use SetActive here because ADDTOCALLSTACK will cause an infinite loop

	memset(m_AverageTimes, 0, sizeof(m_AverageTimes));
	memset(m_CurrentTimes, 0, sizeof(m_CurrentTimes));
	memset(m_PreviousTimes, 0, sizeof(m_PreviousTimes));
	memset(m_EnabledProfiles, 0, sizeof(m_EnabledProfiles));

	m_iActiveWindowSeconds = 10;
	m_iAverageCount = 1;

	LONGLONG llTicks;
	TIME_PROFILE_START;

	m_CurrentTime = llTicks;
	m_CurrentTask = PROFILE_IDLE;
	m_TimeTotal = 0;
}

void ProfileData::SetActive(int iSampleSec)
{
	ADDTOCALLSTACK("ProfileData::SetActive");

	memset(m_AverageTimes, 0, sizeof(m_AverageTimes));
	memset(m_CurrentTimes, 0, sizeof(m_CurrentTimes));
	memset(m_PreviousTimes, 0, sizeof(m_PreviousTimes));

	m_iActiveWindowSeconds = iSampleSec;
	m_iAverageCount		= 1;

	if (m_iActiveWindowSeconds == 0)
		return;

	LONGLONG llTicks;
	TIME_PROFILE_START;

	m_CurrentTime = llTicks;
	m_CurrentTask = PROFILE_OVERHEAD;
	m_TimeTotal = 0;
}

void ProfileData::Start(PROFILE_TYPE id)
{
	ADDTOCALLSTACK("ProfileData::Start");
	if (( id < 0 ) || ( id >= PROFILE_TIME_QTY ) || !m_iActiveWindowSeconds )
		return;

	// ensure profile is enabled
	EnableProfile(id);

	// Stop prev task.
	if ( m_TimeTotal >= (llTimeProfileFrequency * m_iActiveWindowSeconds) )
	{
		for ( int i = 0; i < PROFILE_DATA_QTY; i++ )
		{
			if ( m_iAverageCount < 4 )
			{
				m_AverageTimes[i].m_Time = m_CurrentTimes[i].m_Time;
				m_AverageTimes[i].m_iCount = m_CurrentTimes[i].m_iCount;
			}
			else
			{
				if ( m_PreviousTimes[i].m_Time > llTimeProfileFrequency )
					m_PreviousTimes[i].m_Time = llTimeProfileFrequency;

				m_AverageTimes[i].m_Time	= (((m_AverageTimes[i].m_Time * 90) + (m_PreviousTimes[i].m_Time * 10)) / 100);
				m_AverageTimes[i].m_iCount	= (((m_AverageTimes[i].m_iCount * 95) + (m_PreviousTimes[i].m_iCount * 10)) / 100);
{'fraction_non_alphanumeric': 0.1241879060469765, 'fraction_numerical': 0.015492253873063468, 'mean_word_length': 5.294025157232705, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4485442', 'n_tokens_mistral': 1661, 'n_tokens_neox': 1492, 'n_words': 277}