real time printf-like logging

Discussion in 'C Programming' started by jacob navia, Dec 1, 2007.

  1. jacob navia

    jacob navia Guest

    Yossi Kreinin wrote:
    > Hi!
    >
    > There's this way of doing real time debug prints which look like
    > printf calls:
    >
    > log3("points[%d]={%d,%d}\n", i, points.x, points.y);
    >
    > The implementation writes something like {format-string-ptr, num-args,
    > arg0, arg1, arg2} to a binary log buffer. The buffer is written out in
    > binary form, and then the formatting is done at the host. The string
    > pointers are "decoded" by reading the constant format strings out of
    > the program image or, more portably, they can be collected by the
    > target code when the binary log buffer is written out, at the cost of
    > a slight time & space overhead.
    >
    > Is there a free implementation of something like this? Do you think it
    > would be useful?
    >
    > -- Yossi


    Of course it is possible. I did it when implementing a debugger for an
    embedded DSP. The printf specs were kept in the host,
    and the in place debugger sent the raw data through a serial line.

    Now, "real time" will be another thing, since this takes time, the
    serial line keeps the processor busy, and there is obviously a
    big debugger overhead. But there is no free lunch!



    --
    jacob navia
    jacob at jacob point remcomp point fr
    logiciels/informatique
    http://www.cs.virginia.edu/~lcc-win32
     
    jacob navia, Dec 1, 2007
    #1
    1. Advertising

  2. Hi!

    There's this way of doing real time debug prints which look like
    printf calls:

    log3("points[%d]={%d,%d}\n", i, points.x, points.y);

    The implementation writes something like {format-string-ptr, num-args,
    arg0, arg1, arg2} to a binary log buffer. The buffer is written out in
    binary form, and then the formatting is done at the host. The string
    pointers are "decoded" by reading the constant format strings out of
    the program image or, more portably, they can be collected by the
    target code when the binary log buffer is written out, at the cost of
    a slight time & space overhead.

    Is there a free implementation of something like this? Do you think it
    would be useful?

    -- Yossi
     
    Yossi Kreinin, Dec 1, 2007
    #2
    1. Advertising

  3. jacob navia

    Ian Collins Guest

    Yossi Kreinin wrote:
    > Hi!
    >
    > There's this way of doing real time debug prints which look like
    > printf calls:
    >
    > log3("points[%d]={%d,%d}\n", i, points.x, points.y);
    >

    Certainly.

    > The implementation writes something like {format-string-ptr, num-args,
    > arg0, arg1, arg2} to a binary log buffer. The buffer is written out in
    > binary form, and then the formatting is done at the host. The string
    > pointers are "decoded" by reading the constant format strings out of
    > the program image or, more portably, they can be collected by the
    > target code when the binary log buffer is written out, at the cost of
    > a slight time & space overhead.
    >

    Yes, I used something like this on a couple of projects where we only
    had a very small area of non-volatile storage for logging. I still have
    at least one in production where this technique is used for assert logs.

    > Is there a free implementation of something like this? Do you think it
    > would be useful?
    >

    Maybe, but it is trivial to implement.

    --
    Ian Collins.
     
    Ian Collins, Dec 1, 2007
    #3
  4. On Dec 1, 10:33 pm, Ian Collins <> wrote:
    >
    > > Is there a free implementation of something like this? Do you think it
    > > would be useful?

    >
    > Maybe, but it is trivial to implement.
    >


    It is indeed trivial. But I'm ashamed to admit that it took me some
    time to realize it. For example, the version where you read out
    strings out of the program image at the host came more natural to me
    than the (simpler) version where you write them out at the target (I
    didn't immediately realize that you can stuff the strings into mutable
    buffers and zero the first byte to mark strings you already wrote out
    to avoid repetitions, for example).

    I have this impression that lots of real time logging is done by
    filling structures or using other kind of pre-defined format, or by
    elaborate binary serialization schemes. So the simple thing is somehow
    used less than more complicated alternatives. Would you say this is
    wildly wrong?
     
    Yossi Kreinin, Dec 1, 2007
    #4
  5. On Dec 1, 9:31 pm, jacob navia <> wrote:
    >
    > Of course it is possible. I did it when implementing a debugger for an
    > embedded DSP. The printf specs were kept in the host,
    > and the in place debugger sent the raw data through a serial line.
    >


    Cool stuff. Was it by any chance the CCS? I think it has a trace
    facility like this.

    > Now, "real time" will be another thing, since this takes time, the
    > serial line keeps the processor busy, and there is obviously a
    > big debugger overhead. But there is no free lunch!
    >


    Well, sometimes you could DMA them out pretty fast in "standalone"
    runs (without a debugger attached), so the lunch would be cheap if not
    completely free.

    I think you can do it more neatly when you control the software tools
    implementation. That is, you can have a compiler/linker convert format
    specs to IDs and emit a table of ID->string for the debugger to use.
    What I thought was the case when you don't control the tools, so you
    have the strings linked into the executable (wasting a certain amount
    of space), and then you parse the executable and read the strings out
    of it, or you have the strings written out at the target. Which, of
    course, isn't a big deal, either; I just wondered if there's a free
    implementation people use for this.
     
    Yossi Kreinin, Dec 1, 2007
    #5
    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. ben
    Replies:
    4
    Views:
    657
    Martin Ambuhl
    Jun 26, 2004
  2. whatluo

    (void) printf vs printf

    whatluo, May 26, 2005, in forum: C Programming
    Replies:
    29
    Views:
    1,328
  3. azza

    printf affects following printf/s

    azza, Oct 17, 2010, in forum: C Programming
    Replies:
    0
    Views:
    455
  4. guru
    Replies:
    8
    Views:
    301
  5. Jef Driesen
    Replies:
    16
    Views:
    724
    Jorgen Grahn
    Sep 20, 2012
Loading...

Share This Page