Sorting output to diff files into a single file 
Author Message
 Sorting output to diff files into a single file

  During my programs execution, I'm writing to files about operations within
the program (Mostly to track down memory leak or things that aren't cleaned
up in one way or another.)  The output is being written to several different
files; mainly, each ADT I'm writing makes its own calls to its own file.
What I end up with is files stating:

*** File stack.debug ***
A34EF: stack created.
234AC: node created.
A32AFC: node created.
A32AFC: node destroyed.
234AC: node destroyed.
A34EF: stack destroyed.

*** File hash_table.debug ***
324324: hash table created.
...
...
...
324324: hash table destroyed

What I'd like to do is write another function that combines all these files
into a single file, sorts it, and then matches closest lines referencing the
same memory address so I can track down memory leak.  I should have any
problems doing that.
  I obviously have to begin each line with some sort of information that is
sequential even if the write occurs in a different part of the program that
can't access the last time a write occured, my question is, what do you guys
recommend?  I'm thinking of using the date/time for the system or maybe
even the number of clock ticks since the program began running.  Any other
ideas?
  Also, to use the system time correctly, do I call the function time() and
then localtime() on the appropriate structures?  Or is there more to it?  I
realize there could obviously be other calls to determine the timezone or
something else I'm just not thinking of.  But then again, localtime() would
imply the local time zone in my mind.

Thanks for any help,

Robert



Tue, 01 Oct 2002 03:00:00 GMT  
 Sorting output to diff files into a single file
(posted and mailed)

Quote:
>   During my programs execution, I'm writing to files about operations
within
> the program (Mostly to track down memory leak or things that aren't
cleaned
> up in one way or another.)  The output is being written to several
different
> files; mainly, each ADT I'm writing makes its own calls to its own file.
...
> What I'd like to do is write another function that combines all these
files
> into a single file, sorts it, and then ...
>   I obviously have to begin each line with some sort of information that
is
> sequential even if the write occurs in a different part of the program
that
> can't access the last time a write occured, my question is, what do you
guys
> recommend?  I'm thinking of using the date/time for the system or maybe
> even the number of clock ticks since the program began running.  Any
other
> ideas?
>   Also, to use the system time correctly, do I call the function time()
and
> then localtime() on the appropriate structures?  Or is there more to it?
I
> realize there could obviously be other calls to determine the timezone or
> something else I'm just not thinking of.  But then again, localtime()
would
> imply the local time zone in my mind.

As described, you don't really need to sort, only to merge files
that are each already ordered.  Just concatenating them and
sorting the result works, but is one of the least efficient ways,
and if you have a problem finding your memory leak(s) you probably
are talking about large amounts of log data here.

The precision of time() is not guaranteed by the C standard,
and most systems (including all Unices) provide one second.
Unless your program (or system) is horrendously slow, I doubt
you are doing only one allocate or deallocate per second.
Some systems have a more precise clock available in some
nonstandard way, but you must look in a system-specific group,
or read your system's documentation.
clock() is standardly supposed to return CPU time used
by the program so far, to the extent determinable,
but again the precision is implementation dependent,
though in this case it must be documented.
I have seen few systems where either of these is precise enough
to reliably resolve all (relevant) calls within a running program.

If you are on Intel Pentium (and maybe below, I don't recall)
the RDTSC instruction returns a count of the CPU clock
(which is necessarily precise enough); your C implementation
may provide a builtin way to access this (it is a fairly common
desire) or at least a way to inline or call assemby code to do it.

Simpler, and portable, would be to use a global counter,
shared across all your modules (ADTs), and sufficiently large
it doesn't wrap within one program execution.  unsigned long
is at least (and usually exactly) 32 bits; [unsigned] long long
is now standard in C99, and available in some C90 compilers
as an extension, or else you can do multiprecision with ulong.

Even simpler would be to just write to one file in the first place.
Instead of having each "ADT" open its own file, have the caller
(probably main) open one (or several) files and give the desired
FILE* to each ADT.  You could still have the ADT default to
using its own file if the caller did *not* provide one.  You can
label the data (lines) for each ADT differently, and select out
the data for one (or several) if needed with grep or equivalent.

--
- David.Thompson 1 now at worldnet.att.net



Sat, 05 Oct 2002 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. problem sorting ascii-files from non-ascii files

2. hi,who can help me how to sort files by file type

3. read a file than produce 2 output files(HELP)

4. Reading a file & output a file

5. read a file than produce 2 output files(HELP)

6. output file as true 3-d file

7. ANSI C Run Time Erroe to output data to the output file

8. VC 5 TRACE output to a file instead of the output window

9. quickest way to sort an almost sorted file

10. MFC CDC HTML Output (ala Meta File Output)

11. conflicting definitions in diff. header files

12. conflicting definitions in diff. header files

 

 
Powered by phpBB® Forum Software