My little contribution, C-Profiler

E

Eyegor

Hi all,
I am going through my old code files and found a parser I wrote couple
years back for LCC-win32.

I made a web page listing it here: http://magicmrv.com/codes/ACP/

The parser itself is a work in progress, the executable works well,
but for some reason if i recompile the code for the parser using MSVS
the parser crashes. Anyhow, I would like to revisit this project and
improve it by adding native compatibility with MSVS and not just LCC.
Different header files and real time clock is used by MSVS than LCC.

Let me know what you all think, and may be someone can spot a problem
with the parsers code which causes parser to crash if i compile parser
with MSVS. The parser uses comments, like shown in my input code to
determine which chunks of core are to be profiled. Profiler output is
only generated if the profiled program completes execution.

This code is 100% open source GPL, do with it as you please, All I
want is to know if you made an improvement on it, this way I can use
that improved code myself.
 
J

Jorgen Grahn

Hi all,
I am going through my old code files and found a parser I wrote couple
years back for LCC-win32.

I made a web page listing it here: http://magicmrv.com/codes/ACP/

The parser itself is a work in progress, the executable works well,
but for some reason if i recompile the code for the parser using MSVS
the parser crashes. Anyhow, I would like to revisit this project and
improve it by adding native compatibility with MSVS and not just LCC.
Different header files and real time clock is used by MSVS than LCC.

Let me know what you all think, and may be someone can spot a problem
with the parsers code which causes parser to crash if i compile parser
with MSVS. The parser uses comments, like shown in my input code to
determine which chunks of core are to be profiled. Profiler output is
only generated if the profiled program completes execution.

This code is 100% open source GPL, do with it as you please, All I
want is to know if you made an improvement on it, this way I can use
that improved code myself.

You don't say what the program is supposed to *do*, neither here nor
on the web page. A parser, or a profiler of some kind?

Also try compiling it with warnings enabled in your compiler -- you'll
notice a score of fatal bugs. On my system:

salix:/tmp% gcc -Wall -Wextra -pedantic -std=c99 -O3 -c ACP.c
ACP.c: In function 'main':
ACP.c:23: warning: format '%s' expects type 'char *', but argument 2 has type 'char (*)[20]'
ACP.c:42: warning: format '%s' expects type 'char *', but argument 3 has type 'char **'
...
ACP.c:131: warning: passing argument 1 of 'strcpy' from incompatible
pointer type
ACP.c:595: warning: format '%s' expects type 'char *', but argument 3 has type 'char **'
...
ACP.c:698: warning: function returns address of local variable
...
ACP.c:158: warning: 'Fname' may be used uninitialized in this function
ACP.c:157: warning: 'tok3' may be used uninitialized in this function
ACP.c:154: warning: 'lc' may be used uninitialized in this function

Any one of these is probably enough to crash your program.

I didn't try to execute it (for all I know it might be a trojan), and
I found the source code virtually unreadable. Start by indenting it
properly, and pay attention to spelling.

/Jorgen
 
E

Eyegor

Sorry, I though that the input/output file example would be self
explanatory. The program injects real time clock statements before and
after every line of the code to be profiled and then a chunk of code
at the end of the main function to export the results as an HTML
file.

Thanks for error log I guess i need to mess with my MSVS settings to
see it. I'll mess with profiler code once I have some free time.
 
E

Eric Sosman

Sorry, I though that the input/output file example would be self
explanatory. The program injects real time clock statements before and
after every line of the code to be profiled and then a chunk of code
at the end of the main function to export the results as an HTML
file.

Thanks for error log I guess i need to mess with my MSVS settings to
see it. I'll mess with profiler code once I have some free time.

I looked at it for only a few moments, but even that was enough
to spot some serious errors. Here are three of the truly classic
howlers:

ff = fopen(FN, "r");
while (!feof(ff))

FstatName[index] = malloc(strlen(tok2) * sizeof(char));
strcpy(FstatName[index], tok2);

char *appendSlash(...) {
char line2[MAX_LINE_LENGTH * 2];
...
return line2;
}

I term these "truly classic" because all three are covered in the FAQ,
as Questions 12.2, 7.19, and 7.5a, respectively. If you want to be
respected on comp.lang.c, you'll need to learn to make subtler errors.
 
E

Eyegor

Sorry, I though that the input/output file example would be self
explanatory. The program injects real time clock statements before and
after every line of the code to be profiled and then a chunk of code
at the end of the main function to export the results as an HTML
file.

Thanks for error log I guess i need to mess with my MSVS settings to
see it. I'll mess with profiler code once I have some free time.
 
E

Eyegor

May i have the link to the FAQ you referring to? Sorry to say but my
university's choice for the C text was the Shieldt's C reference,
which I heard many people bash pretty bad. I got C++ book by Bjarne
Stroustrup but have not had a chance to read it yet...
 
E

Eric Sosman

May i have the link to the FAQ you referring to?[...]

(Wouldn't you know it? The one time I decide to omit the link
in the interests of brevity, the person doesn't already know where
it is. I thought "Eyegor" had been around long enough to have been
referred to the FAQ half a dozen times by now, but apparently not.)

http://www.c-faq.com/

Also, there's this really neat web site at http://www.google.com/
that can find lots of things for you. Try it on "C FAQ" and see if it
leads anywhere useful ...
 
I

Ian Collins

On 11/29/10 11:38 AM, Eyegor wrote:

Please don't snip the context you are relying to!
May i have the link to the FAQ you referring to?

Google has it, search for c faq.
 
E

Eyegor

On 11/29/10 11:38 AM, Eyegor wrote:

Please don't snip the context you are relying to!


Google has it, search for c faq.

Google has the whole world, in my hands, the whole wide world in my
hands...

but then there are a googol C FAQs too, so how am I to know which one
was being refered to.

and thanks for the link, ill read through it.
 
E

Eyegor

I looked at the FAQ, now that I actually have link for it, and of
course you are correct about the point you made. What can I say, its
been couple years since i did anything in C... way out of practice...
 
H

H Vlems

Hi all,
I am going through my old code files and found a parser I wrote couple
years back for LCC-win32.

I made a web page listing it here:http://magicmrv.com/codes/ACP/

The parser itself is a work in progress, the executable works well,
but for some reason if i recompile the code for the parser using MSVS
the parser crashes. Anyhow, I would like to revisit this project and
improve it by adding native compatibility with MSVS and not just LCC.
Different header files and real time clock is used by MSVS than LCC.

Let me know what you all think, and may be someone can spot a problem
with the parsers code which causes parser to crash if i compile parser
with MSVS. The parser uses comments, like shown in my input code to
determine which chunks of core are to be profiled. Profiler output is
only generated if the profiled program completes execution.

This code is 100% open source GPL, do with it as you please, All I
want is to know if you made an improvement on it, this way I can use
that improved code myself.

Try a formatter for your code, it's virtually unreadable the way it is
written.
Just scanning the code I saw examples of "while (i<strlen(mumble))",
which might indicate
poor performance. If possible I'd suggest x=strlen(mumble) and while
(i<x) instead.
Hans
 
E

Eyegor

Try a formatter for your code, it's virtually unreadable the way it is
written.
Just scanning the code I saw examples of "while (i<strlen(mumble))",
which might indicate
poor performance. If possible I'd suggest  x=strlen(mumble) and while
(i<x) instead.
Hans

you are also 100% correct, the executioner of strlen is very
inefficient on every iteration of the loop. It is rare that I write
clean code from the start, unless i know it will be computationally
intense, bad habit. This code was meant to parse couple KB of text so
taking 3 seconds to do it, rather than 0.0001 second for this
particular code is acceptable for me.

I use lcc-win32 which auto formats code for me, i'll try to re-post
spaced code in html format, i just assumed that every one will copy it
to their ide... bad assumption i guess.

What do you all use for performance profiling? I don't mean just
branching diagrams and number of calls to every function, but i mean
full line by line profiling. With tracking of number of calls, average
execution time per call and total time.
 
H

H Vlems

you are also 100% correct, the executioner of strlen is very
inefficient on every iteration of the loop. It is rare that I write
clean code from the start, unless i know it will be computationally
intense, bad habit. This code was meant to parse couple KB of text so
taking 3 seconds to do it, rather than 0.0001 second for this
particular code is acceptable for me.

I use lcc-win32 which auto formats code for me, i'll try to re-post
spaced code in html format, i just assumed that every one will copy it
to their ide... bad assumption i guess.

What do you all use for performance profiling? I don't mean just
branching diagrams and number of calls to every function, but i mean
full line by line profiling. With tracking of number of calls, average
execution time per call and total time.- Hide quoted text -

- Show quoted text -

Performance issues for code like this probably doesn't hurt you. And
you learned to
program fairly recently which means that you have enough memory and
cpu power available to you.
Which just shows my age I guess. But I learned that function calls may
be expensive, so put
their output apart for further use, even though the language allowed
assignments in expressions, like C does.
So it is a matter of reviewing and getting used to a coding style. One
that will work in most languages.

Hans
 
K

Keith Thompson

Eyegor said:
I use lcc-win32 which auto formats code for me, i'll try to re-post
spaced code in html format, i just assumed that every one will copy it
to their ide... bad assumption i guess.
[...]

Please don't post HTML.

Just post plain text, indented with spaces, not tabs. (Whether you
think tabs or spaces are better for code indentation, some Usenet
software doesn't handle them well.)
 
E

Eyegor

[...]> I use lcc-win32 which auto formats code for me, i'll try to re-post
spaced code in html format, i just assumed that every one will copy it
to their ide... bad assumption i guess.

[...]

Please don't post HTML.

Just post plain text, indented with spaces, not tabs.  (Whether you
think tabs or spaces are better for code indentation, some Usenet
software doesn't handle them well.)

--
Keith Thompson (The_Other_Keith) (e-mail address removed)  <http://www.ghoti.net/~kst>
Nokia
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

Thanks, I'll keep it in mind when I post my Array Encoded Integer
library, i am working on it now, but its not yet ready for the
showcase yet.

Also, I actually find myself allot more "memory-worrier" than most now
day programmers. I have written code, just not in C which had to
reference 70MB data files back when PCs had 256 MB or ram, and those
were top of the line consumer ones, not the low end windows 95 with
64MB limit. The biggest memory hog app i ever wrote was for netflix
competition, i did not get any good predictions in, my best score was
1.01 with baseline being 0.95, lower is better... Anyhow I had 1.5GB
data sets to play with on a PC with 2GB of ram... was fun lol.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top