Click here to Skip to main content
15,891,873 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Edit Box Question Pin
John R. Shaw7-Nov-05 14:00
John R. Shaw7-Nov-05 14:00 
GeneralRe: Edit Box Question Pin
Jethro637-Nov-05 14:14
Jethro637-Nov-05 14:14 
GeneralRe: Edit Box Question Pin
John R. Shaw7-Nov-05 15:05
John R. Shaw7-Nov-05 15:05 
QuestionMaking Stealth Input (hide from keyloggers) Pin
TheDen7-Nov-05 8:39
TheDen7-Nov-05 8:39 
AnswerRe: Making Stealth Input (hide from keyloggers) Pin
John R. Shaw7-Nov-05 15:32
John R. Shaw7-Nov-05 15:32 
QuestionMDI caret keyboard and mouse Pin
Richard_487-Nov-05 7:47
Richard_487-Nov-05 7:47 
AnswerRe: MDI caret keyboard and mouse Pin
John R. Shaw7-Nov-05 18:25
John R. Shaw7-Nov-05 18:25 
QuestionHelp with speeding up a log parser Pin
RobJones7-Nov-05 7:17
RobJones7-Nov-05 7:17 
Hello all,
I have a program that reads a IIS log and then parses every line and puts that info into a structure.. I later use this info to disply different items of value. The following code is used in a Win UI Thread.. This works fine but its SUPER Slow.. Can anyone help me speed this up? I thought about parsing the file line by line as I read it in but I don't see any line by line options in CFile.

Any suggestions are welcome..
<code>
// Select the file to be parsed.
static char BASED_CODE szFilter[] = _T("Log Files (*.log)|*.log||");
CFileDialog m_ldFile(TRUE,_T(".log"),_T(""),OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, szFilter);

if (m_ldFile.DoModal() == IDOK)
{
	::PostMessage(m_pMainWnd->GetSafeHwnd(), UWM_PT_START, 0,0);
		
	// Get the filename selected
	CString strFilePath = m_ldFile.GetPathName(),
			strData	= _T("");

	// Read the file and dump the data into strData
	CFile file;
	if(file.Open(strFilePath, CFile::modeRead | CFile::shareDenyNone))
	{
		// Declare a buffer for reading the text
		char cBuf[65536];
		UINT uBytesRead;

		// Continue reading until no more data is read
		while(uBytesRead = file.Read(cBuf, sizeof(cBuf)-1))
		{
			// Null terminate after the last charcter
			cBuf[uBytesRead] = NULL;

			// Add the buffer to the mapped CString
			strData += CString(cBuf);
		}

		// Close the file
		file.Close();

		strData.MakeLower();

		int nHeaderStart = 0,
			nHeaderEnd = 0,
			nEndLine = 0;

		// Find the header
		nHeaderStart = strData.Find(_T("#fields: "),0);
		nHeaderEnd = strData.Find(_T("\r\n"), nHeaderStart);

		// Delete up to and including the header
		if(strData.GetLength() >= (nHeaderEnd +2))
			strData.Delete(0, nHeaderEnd +2);
		else
			strData.Empty();
			
		// Clear out the vector
		v_items.erase(v_items.begin(), v_items.end());

		// Parse the data and populate the vector
		while(!strData.IsEmpty())
		{
			// Split up the data per line
			nEndLine = strData.Find(_T("\r\n"), 0);
			if(nEndLine > 0)
			{
				CString strLine = strData.Mid(0, nEndLine);
				int nToken = 0;
				s_item pItem;
					
				// Date
				nToken = strLine.Find(_T(" "), 0);
				pItem.sDate = strLine.Mid(0, nToken);
				strLine.Delete(0, nToken +1);

				// Time
				nToken = strLine.Find(_T(" "), 0);
				pItem.sTime = strLine.Mid(0, nToken);
				strLine.Delete(0, nToken +1);

				// Server IP
				nToken = strLine.Find(_T(" "), 0);
				pItem.sIPServer = strLine.Mid(0, nToken);
				strLine.Delete(0, nToken +1);

				// Method
				nToken = strLine.Find(_T(" "), 0);
				pItem.sMethod = strLine.Mid(0, nToken);
				strLine.Delete(0, nToken +1);

				// URI Stem
				nToken = strLine.Find(_T(" "), 0);
				pItem.sURIStem = strLine.Mid(0, nToken);
				strLine.Delete(0, nToken +1);

				// URI Query
				nToken = strLine.Find(_T(" "), 0);
				pItem.sURIQuery = strLine.Mid(0, nToken);
				strLine.Delete(0, nToken +1);

				// Port
				nToken = strLine.Find(_T(" "), 0);
				pItem.sPort = strLine.Mid(0, nToken);
				strLine.Delete(0, nToken +1);

				// User Name
				nToken = strLine.Find(_T(" "), 0);
				pItem.sUsername = strLine.Mid(0, nToken);
				strLine.Delete(0, nToken +1);

				// IP Client
				nToken = strLine.Find(_T(" "), 0);
				pItem.sIPClient = strLine.Mid(0, nToken);
				strLine.Delete(0, nToken +1);

				// User Agent
				nToken = strLine.Find(_T(" "), 0);
				pItem.sUserAgent = strLine.Mid(0, nToken);
				strLine.Delete(0, nToken +1);

				// Status
				nToken = strLine.Find(_T(" "), 0);
				pItem.sStatus = strLine.Mid(0, nToken);
				strLine.Delete(0, nToken +1);

				// SubStatus
				nToken = strLine.Find(_T(" "), 0);
				pItem.sSubstatus = strLine.Mid(0, nToken);
				strLine.Delete(0, nToken +1);

				// Win32 Stataus
				pItem.sWin32Status = strLine;
				strLine.Empty();

				// Insert the structure into the vector
				v_items.push_back(pItem);

				// Delete the line from the main buffer
				if(strData.GetLength() > (nEndLine +2))
					strData.Delete(0, nEndLine +2);
				else
					strData.Empty();
			}
			else
				strData.Empty();
		}
	}
}
</code>


Whoever said nothing's impossible never tried slamming a revolving door!
AnswerRe: Help with speeding up a log parser Pin
Chris Losinger7-Nov-05 7:45
professionalChris Losinger7-Nov-05 7:45 
AnswerRe: Help with speeding up a log parser Pin
Maximilien7-Nov-05 7:55
Maximilien7-Nov-05 7:55 
GeneralRe: Help with speeding up a log parser Pin
David Crow7-Nov-05 8:06
David Crow7-Nov-05 8:06 
AnswerRe: Help with speeding up a log parser Pin
David Crow7-Nov-05 7:57
David Crow7-Nov-05 7:57 
AnswerThanks Pin
RobJones7-Nov-05 8:27
RobJones7-Nov-05 8:27 
Questionhelp for streaming using MCI Pin
V.G7-Nov-05 6:02
V.G7-Nov-05 6:02 
Questionabstract class problem Pin
followait7-Nov-05 5:36
followait7-Nov-05 5:36 
AnswerRe: abstract class problem Pin
Chris Losinger7-Nov-05 5:55
professionalChris Losinger7-Nov-05 5:55 
GeneralRe: abstract class problem Pin
followait7-Nov-05 14:45
followait7-Nov-05 14:45 
GeneralRe: abstract class problem Pin
Chris Losinger7-Nov-05 14:54
professionalChris Losinger7-Nov-05 14:54 
GeneralRe: abstract class problem Pin
followait7-Nov-05 19:19
followait7-Nov-05 19:19 
QuestionProblem building projects from command line Pin
Henrik Pettersson7-Nov-05 5:18
Henrik Pettersson7-Nov-05 5:18 
Questionload data from excel Pin
hoanhdung7-Nov-05 3:46
hoanhdung7-Nov-05 3:46 
AnswerRe: load data from excel Pin
Cedric Moonen7-Nov-05 3:58
Cedric Moonen7-Nov-05 3:58 
AnswerRe: load data from excel Pin
David Crow7-Nov-05 5:22
David Crow7-Nov-05 5:22 
AnswerRe: load data from excel Pin
S Douglas7-Nov-05 20:25
professionalS Douglas7-Nov-05 20:25 
Questionhooking to a COM port opened by another application Pin
pankajdaga7-Nov-05 3:16
pankajdaga7-Nov-05 3:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.