Ejemplo n.º 1
0
bool CJobWatchDlg::GetCurrentWorkerText( 
	CUtlVector<char> &text, 
	unsigned long &curMessageIndex )
{
	text.SetSize( 0 );

	unsigned long jobWorkerID;
	if ( !GetCurJobWorkerID( jobWorkerID ) )
		return false;

	// Now copy all the text out.
	CMySQLQuery query;
	if ( curMessageIndex == 0 )
		query.Format( "select * from text_messages where JobWorkerID=%lu", jobWorkerID );
	else
		query.Format( "select * from text_messages where JobWorkerID=%lu and MessageIndex >= %lu", jobWorkerID, curMessageIndex );
	
	GetMySQL()->Execute( query );

	while ( GetMySQL()->NextRow() )
	{
		const char *pTextStr = GetMySQL()->GetColumnValue( "text" ).String();
		int len = strlen( pTextStr );
		text.AddMultipleToTail( len, pTextStr );

		curMessageIndex = GetMySQL()->GetColumnValue( "MessageIndex" ).UInt32() + 1;
	}

	text.AddToTail( 0 );
	return true;
}
Ejemplo n.º 2
0
	virtual int RunCommand()
	{
		CMySQLQuery query;
		query.Format( "insert into job_master_end values ( %lu, %d, %d, \"no errors\" )", g_JobPrimaryID, g_nWorkersConnected, g_nWorkersDisconnected ); 
		g_pSQL->Execute( query );

		// Now set RunningTimeMS.
		query.Format( "update job_master_start set RunningTimeMS=%lu where JobID=%lu", g_RunningTimeMS, g_JobPrimaryID );
		g_pSQL->Execute( query );
		return 1;
	}
Ejemplo n.º 3
0
	virtual int RunCommand()
	{
		CMySQLQuery query;
		query.Format( "insert into job_master_end values ( %lu, %d, %d, \"no errors\" )", g_JobPrimaryID, g_nWorkersConnected, g_nWorkersDisconnected ); 
		query.Execute( g_pSQL  );

		// Now set RunningTimeMS.
		unsigned long runningTimeMS = GetTickCount() - g_StatsStartTime;
		query.Format( "update job_master_start set RunningTimeMS=%lu where JobID=%lu", runningTimeMS, g_JobPrimaryID );
		query.Execute( g_pSQL );
		return 1;
	}
Ejemplo n.º 4
0
	virtual int RunCommand()
	{
		CMySQLQuery query;
		query.Format( "insert into job_worker_end ( JobWorkerID, ErrorText, RunningTimeMS ) values ( %lu, \"%s\", %lu )", g_JobWorkerID, "No Errors", g_RunningTimeMS );
		g_pSQL->Execute( query );
		return 1;
	}
Ejemplo n.º 5
0
	virtual int RunCommand()
	{
		CMySQLQuery query;
		query.Format( "insert into text_messages (JobWorkerID, MessageIndex, Text) values ( %lu, %lu, \"%s\" )", g_JobWorkerID, g_CurrentMessageIndex, m_pText );
		query.Execute( g_pSQL );

		++g_CurrentMessageIndex;
		return 1;
	}
Ejemplo n.º 6
0
bool VMPI_Stats_Init_Worker( const char *pHostName, const char *pDBName, const char *pUserName, unsigned long DBJobID )
{
	g_StatsStartTime = GetTickCount();
	
	// If pDBServerName is null, then we're the master and we just want to make the job_worker_start entry.
	if ( pHostName )
	{
		Assert( !g_pDB );
		
		// Connect the database.
		g_pDB = new CMySqlDatabase;
		if ( !g_pDB || !g_pDB->Initialize() || !LoadMySQLWrapper( pHostName, pDBName, pUserName ) )
		{
			delete g_pDB;
			g_pDB = NULL;
			return false;
		}
		
		// Get our machine name to store in the database.
		DWORD size = sizeof( g_MachineName );
		GetComputerName( g_MachineName, &size );
	}


	g_JobPrimaryID = DBJobID;
	g_JobWorkerID = 0;

	CMySQLQuery query;
	query.Format( "insert into job_worker_start ( JobID, CurrentStage, IsMaster, MachineName ) values ( %lu, \"none\", %d, \"%s\" )",
		g_JobPrimaryID, g_bMaster, g_MachineName );
	query.Execute( g_pSQL );
			
	g_JobWorkerID = g_pSQL->InsertID();
	if ( g_JobWorkerID == 0 )
	{
		delete g_pDB;
		g_pDB = NULL;
		return false;
	}

	// Now create a thread that samples perf data and stores it in the database.
	g_hPerfThreadExitEvent = CreateEvent( NULL, FALSE, FALSE, NULL );
	g_hPerfThread = CreateThread(
		NULL,
		0,
		PerfThreadFn,
		NULL,
		0,
		&g_PerfThreadID );

	return true;	
}
Ejemplo n.º 7
0
	virtual int RunCommand()
	{
		CMySQLQuery query;
		query.Format(	"insert into graph_entry (JobWorkerID, MSSinceJobStart, BytesSent, BytesReceived) "
						"values ( %lu, %lu, %lu, %lu )", 
			g_JobWorkerID, 
			m_msTime, 
			m_nBytesSent, 
			m_nBytesReceived );
		
		g_pSQL->Execute( query );

		++g_CurrentMessageIndex;
		return 1;
	}
Ejemplo n.º 8
0
bool VMPI_Stats_Init_Master( 
	const char *pHostName, 
	const char *pDBName, 
	const char *pUserName,
	const char *pBSPFilename, 
	unsigned long *pDBJobID )
{
	Assert( !g_pDB );

	g_bMaster = true;
	
	// Connect the database.
	g_pDB = new CMySqlDatabase;
	if ( !g_pDB || !g_pDB->Initialize() || !LoadMySQLWrapper( pHostName, pDBName, pUserName ) )
	{
		delete g_pDB;
		g_pDB = NULL;
		return false;
	}

	DWORD size = sizeof( g_MachineName );
	GetComputerName( g_MachineName, &size );

	// Create the job_master_start row.
	Q_FileBase( pBSPFilename, g_BSPFilename, sizeof( g_BSPFilename ) );

	g_JobPrimaryID = 0;
	CMySQLQuery query;
	query.Format( "insert into job_master_start ( BSPFilename, StartTime, MachineName, RunningTimeMS ) values ( \"%s\", null, \"%s\", %lu )", g_BSPFilename, g_MachineName, RUNNINGTIME_MS_SENTINEL ); 
	query.Execute( g_pSQL );

	g_JobPrimaryID = g_pSQL->InsertID();
	if ( g_JobPrimaryID == 0 )
	{
		delete g_pDB;
		g_pDB = NULL;
		return false;
	}


	// Now init the worker portion.
	*pDBJobID = g_JobPrimaryID;
	return VMPI_Stats_Init_Worker( NULL, NULL, NULL, g_JobPrimaryID );
}
Ejemplo n.º 9
0
void UpdateJobWorkerRunningTime()
{
	unsigned long runningTimeMS = GetTickCount() - g_StatsStartTime;
	
	char curStage[256];
	VMPI_GetCurrentStage( curStage, sizeof( curStage ) );
	
	CMySQLQuery query;
	query.Format( "update job_worker_start set RunningTimeMS=%lu, CurrentStage=\"%s\", "
		"Thread0WU=%d, Thread1WU=%d, Thread2WU=%d, Thread3WU=%d where JobWorkerID=%lu", 
		runningTimeMS, 
		curStage,
		(int) g_ThreadWUs[0],
		(int) g_ThreadWUs[1],
		(int) g_ThreadWUs[2],
		(int) g_ThreadWUs[3],
		g_JobWorkerID );
	query.Execute( g_pSQL );
}
Ejemplo n.º 10
0
void CJobWatchDlg::FillGraph()
{
	// Get all the graph samples.
	unsigned long jobWorkerID;
	if ( !GetCurJobWorkerID( jobWorkerID ) )
		return;

	CMySQLQuery query;
	query.Format( "select * from graph_entry where JobWorkerID=%lu", jobWorkerID );
	GetMySQL()->Execute( query );

	int iMSTime = GetMySQL()->GetColumnIndex( "MSSinceJobStart" );	
	int iBytesSent = GetMySQL()->GetColumnIndex( "BytesSent" );
	int iBytesReceived = GetMySQL()->GetColumnIndex( "BytesReceived" );

	// See if there's anything new.
	CUtlVector<CGraphEntry> entries;

	int highest = m_CurGraphTime;
	while ( GetMySQL()->NextRow() )
	{
		CGraphEntry entry;
		entry.m_msTime = GetMySQL()->GetColumnValue( iMSTime ).Int32();
		entry.m_nBytesSent = GetMySQL()->GetColumnValue( iBytesSent ).Int32();
		entry.m_nBytesReceived = GetMySQL()->GetColumnValue( iBytesReceived ).Int32();
		entries.AddToTail( entry );

		highest = max( highest, entry.m_msTime );
	}

	if ( highest > m_CurGraphTime )
	{
		m_CurGraphTime = highest;
		
		m_GraphControl.Clear();
		m_GraphControl.Fill( entries );
	}
}
Ejemplo n.º 11
0
BOOL CJobWatchDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();


	m_GraphControl.SubclassDlgItem( IDC_GRAPH_AREA, this );


	CString str;

	// Get all our startup info from the command line.
	const char *pJobID = FindArg( "-JobID", NULL );
	const char *pDBName = FindArg( "-dbname", NULL );
	const char *pHostName = FindArg( "-hostname", NULL );
	const char *pUserName = FindArg( "-username", NULL );

	if ( !pJobID || !pDBName || !pHostName || !pUserName )
	{
		str.Format( "Missing a command line parameter (-JobID or -dbname or -hostname or -username)" );
		MessageBox( str, "Error", MB_OK );
		EndDialog( 1 );
		return FALSE;
	}

	m_JobID = atoi( pJobID );
	
	m_pSQL = InitMySQL( pDBName, pHostName, pUserName );
	if ( !m_pSQL )
	{
		str.Format( "Can't init MYSQL db (db = '%s', host = '%s', user = '******')", pDBName, pHostName, pUserName );
		MessageBox( str, "Error", MB_OK );
		EndDialog( 0 );
		return FALSE;
	}
	
	
	// Fill the workers list.
	CMySQLQuery query;
	query.Format( "select * from job_worker_start where JobID=%lu order by MachineName", m_JobID );
	GetMySQL()->Execute( query );

	while ( GetMySQL()->NextRow() )
	{
		const char *pMachineName = GetMySQL()->GetColumnValue( "MachineName" ).String();

		int index;
		if ( GetMySQL()->GetColumnValue( "IsMaster" ).Int32() )
		{
			char tempStr[512];
			Q_snprintf( tempStr, sizeof( tempStr ), "%s (master)", pMachineName );
			index = m_Workers.AddString( tempStr );
		}
		else
		{
			index = m_Workers.AddString( pMachineName );
		}

		unsigned long jobWorkerID = GetMySQL()->GetColumnValue( "JobWorkerID" ).UInt32();
		m_Workers.SetItemData( index, jobWorkerID );
	}
	

	// (Init the idle processor so we can update text and graphs).
	StartIdleProcessing( 300 );


	// Setup anchors.
	m_AnchorMgr.AddAnchor( this, GetDlgItem( IDC_WORKERS_PANEL ), ANCHOR_LEFT, ANCHOR_TOP, ANCHOR_WIDTH_PERCENT, ANCHOR_HEIGHT_PERCENT );
	m_AnchorMgr.AddAnchor( this, GetDlgItem( IDC_WORKERS ), ANCHOR_LEFT, ANCHOR_TOP, ANCHOR_WIDTH_PERCENT, ANCHOR_HEIGHT_PERCENT );

	m_AnchorMgr.AddAnchor( this, GetDlgItem( IDC_TEXT_OUTPUT_PANEL ), ANCHOR_LEFT, ANCHOR_HEIGHT_PERCENT, ANCHOR_WIDTH_PERCENT, ANCHOR_BOTTOM );
	m_AnchorMgr.AddAnchor( this, GetDlgItem( IDC_TEXTOUTPUT ), ANCHOR_LEFT, ANCHOR_HEIGHT_PERCENT, ANCHOR_WIDTH_PERCENT, ANCHOR_BOTTOM );

	m_AnchorMgr.AddAnchor( this, GetDlgItem( IDC_GRAPHS_PANEL ), ANCHOR_WIDTH_PERCENT, ANCHOR_TOP, ANCHOR_RIGHT, ANCHOR_HEIGHT_PERCENT );
	m_AnchorMgr.AddAnchor( this, &m_GraphControl, ANCHOR_WIDTH_PERCENT, ANCHOR_TOP, ANCHOR_RIGHT, ANCHOR_HEIGHT_PERCENT );
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}