[Tutor] processing multi entry logs
Alan Gauld
alan.gauld at freenet.co.uk
Tue Aug 15 09:58:08 CEST 2006
>I have a log file. Essentially the file has 2 important entries for
> each process id. One when the process starts with an id and a
> another
> piece of data. the second is when the process finishes, with the
> result also with the process id.
> I can't think of an efficient way to store the data from the first
> entry.
This sounds like a job for a dictionary based on process Id.
You can store a tuple of start/stop times and key it by pid.
In pseudo code:
for line in logfile:
pid,event,time = parseData(line)
if event == start
processes[pid] = [time,0]
elif event == stop:
processes[pid][1] = time
That throws all other events away and leaves you a dictionary
holding start and stop times per process id.
> Keep processing line by line and check against the partially
> recorded
> ids?
Thats what I've done yes.
HTH,
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld
More information about the Tutor
mailing list