This is the mail archive of the systemtap@sourceware.org mailing list for the systemtap project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

binary printf checked in


I've committed a new printf. I'm working on docs and tests and will get
those in tomorrow. Meanwhile, please give it a try and let me know about
any problems, needed enhancements, etc.

This printf implements %b, %n, and corrects problems with %p.

%p - pointer. Takes 64-bit arg, truncates to sizeof(ptr), and prints
it as "%08x" or "%016x"

%1n, %2n, %4n, %n -  These functions instruct printf to write
a binary length at this location that is the total length of
the string written by the printf.  The field width is the number
of bytes to write. The default is "2". [ Note: I change the default from
4 because typically the length will be small enough to easily fit in 2
bytes]

%1b, %2b, %4b, %8b, %b - binary write. The field width specifies the
number of bytes to write. Default is 4 (32-bits).

Examples:

stap -e 'probe begin{for(i=97;i<123;i++) printf("%3d: %1b%1b%1b\n",i,i,i-32,i-64); exit()}'

> stap -e 'probe begin{printf("%1n%b%b", 0xc0dedbad, 0x12345678);exit()}' | hexdump -C
00000000  08 ad db de c0 78 56 34  12                       |.....xV4.|

> stap -e 'probe begin{printf("%1b%1b%1blo %1b%1brld\n", 72,101,108,87,111);exit()}'
Hello World

on x86_64
> stap -e 'probe begin{printf("%p\n", 0x8000000002345678); exit()}'
8000000002345678

on x86
> stap -e 'probe begin{printf("%p\n", 0x8000000002345678); exit()}'
02345678

Performance:
SystemTap BENCH2        Sat Apr  8 18:31:07 PDT 2006
kernel: 2.6.9-34.ELsmp x86_64
Red Hat Enterprise Linux WS release 4 (Nahant Update 3)
tiger:  18:31:07 up  4:26,  1 user,  load average: 0.09, 0.40, 0.24
processors: 4 (2 physical)                   Intel(R) Xeon(TM) CPU 2.80GHz
MemTotal:      1025428 kB       MemFree:        575964 kB
----------------------------------------------------------------
For comparison, function call overhead is 529 nsecs.
Times below are nanoseconds per probe and include kprobe overhead.
----------------------------------------------------------------
+--- S = Script, R = Runtime
|+-- * = Relayfs                Threads
|| NAME                             1       2       4
R : empty probe                  1488     746     560
S : empty probe                  1598     796     592
S : printf 100 chars             2187    1418    1111
S*: printf 100 chars             2227    1285    1083
S : print 100 chars              2897    1671    1318
S : printf 5 integers            3837    2127    1620
S : printf 10 integers           5649    3047    2319
S : binary printf 5 integers     1968    1107     874
S : binary printf 10 integers    2177    1297     987
S : binary printf 10 8-bit ints  2067    1202     933




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]