My little contribution, C-Profiler

Discussion in 'C Programming' started by Eyegor, Nov 26, 2010.

  1. Eyegor

    Eyegor Guest

    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.
    Eyegor, Nov 26, 2010
    #1
    1. Advertising

  2. Eyegor

    Jorgen Grahn Guest

    On Fri, 2010-11-26, Eyegor wrote:
    > 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

    --
    // Jorgen Grahn <grahn@ Oo o. . .
    \X/ snipabacken.se> O o .
    Jorgen Grahn, Nov 28, 2010
    #2
    1. Advertising

  3. Eyegor

    Eyegor Guest

    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.
    Eyegor, Nov 28, 2010
    #3
  4. Eyegor

    Eric Sosman Guest

    On 11/28/2010 4:31 PM, Eyegor wrote:
    > 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.

    --
    Eric Sosman
    lid
    Eric Sosman, Nov 28, 2010
    #4
  5. Eyegor

    Eyegor Guest

    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.
    Eyegor, Nov 28, 2010
    #5
  6. Eyegor

    Eyegor Guest

    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...
    Eyegor, Nov 28, 2010
    #6
  7. Eyegor

    Eric Sosman Guest

    On 11/28/2010 5:38 PM, Eyegor wrote:
    > 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 ...

    --
    Eric Sosman
    lid
    Eric Sosman, Nov 28, 2010
    #7
  8. Eyegor

    Ian Collins Guest

    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.

    --
    Ian Collins
    Ian Collins, Nov 28, 2010
    #8
  9. Eyegor

    Eyegor Guest

    On Nov 28, 5:51 pm, Ian Collins <> wrote:
    > 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.
    >
    > --
    > Ian Collins


    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.
    Eyegor, Nov 29, 2010
    #9
  10. Eyegor

    Eyegor Guest

    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...
    Eyegor, Nov 29, 2010
    #10
  11. Eyegor

    H Vlems Guest

    On 26 nov, 20:17, Eyegor <> wrote:
    > 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
    H Vlems, Nov 29, 2010
    #11
  12. Eyegor

    Eyegor Guest

    On Nov 29, 3:33 am, H Vlems <> wrote:
    > On 26 nov, 20:17, Eyegor <> wrote:
    >
    >
    >
    > > 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


    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.
    Eyegor, Nov 29, 2010
    #12
  13. Eyegor

    H Vlems Guest

    On Nov 29, 6:09 pm, Eyegor <> wrote:
    > On Nov 29, 3:33 am, H Vlems <> wrote:
    >
    >
    >
    >
    >
    > > On 26 nov, 20:17, Eyegor <> wrote:

    >
    > > > 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

    >
    > 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
    H Vlems, Nov 29, 2010
    #13
  14. Eyegor <> writes:
    [...]
    > 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) <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"
    Keith Thompson, Nov 30, 2010
    #14
  15. Eyegor

    Eyegor Guest

    On Nov 29, 7:53 pm, Keith Thompson <> wrote:
    > Eyegor <> writes:
    >
    > [...]> 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)  <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.
    Eyegor, Nov 30, 2010
    #15
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Antoon Pardon
    Replies:
    7
    Views:
    657
    Paul Rubin
    Oct 16, 2005
  2. Detlev Offenbach

    eric4 request for contribution

    Detlev Offenbach, Jan 12, 2008, in forum: Python
    Replies:
    0
    Views:
    265
    Detlev Offenbach
    Jan 12, 2008
  3. Detlev Offenbach

    eric4 request for contribution

    Detlev Offenbach, Jan 12, 2008, in forum: Python
    Replies:
    0
    Views:
    258
    Detlev Offenbach
    Jan 12, 2008
  4. potatosoftware
    Replies:
    0
    Views:
    661
    potatosoftware
    Nov 4, 2009
  5. Replies:
    0
    Views:
    267
Loading...

Share This Page