diff options
author | Chris Kuethe <chris.kuethe@gmail.com> | 2008-12-27 09:15:40 +0000 |
---|---|---|
committer | Chris Kuethe <chris.kuethe@gmail.com> | 2008-12-27 09:15:40 +0000 |
commit | e6b2b986ff8c91f2ec1f8dbc05a62f5bf9fcd91b (patch) | |
tree | a0b4e270d5b7fdf0c2e9aa2551c29bce51dc088a /hex.c | |
parent | d4bee24389232b37dd0ae816789806f8fe1f34fa (diff) | |
download | gpsd-e6b2b986ff8c91f2ec1f8dbc05a62f5bf9fcd91b.tar.gz |
Add a wrapper function around gpsd_hexdump to avoid hexdumping buffers...
...and copying ascii strings around when they're not going to be printed.
This saves quite a lot of CPU. I processed a 50MB ubx binary file. With
no "-D" options, this saved nearly 2.2M calls to gpsd_hexdump and the
processing time for this file went from 84 seconds to 35 seconds.
Diffstat (limited to 'hex.c')
-rw-r--r-- | hex.c | 19 |
1 files changed, 19 insertions, 0 deletions
@@ -8,6 +8,25 @@ #include "gpsd_config.h" #include "gpsd.h" +int gpsd_hexdump_level = -1; +/* + * A wrapper around gpsd_hexdump to prevent wasting cpu time by hexdumping + * buffers and copying strings that will never be printed. only messages at + * level "N" and lower will be printed. By way of example, without any -D + * options, gpsd probably won't ever call the real gpsd_hexdump. At -D2, + * LOG_PROG (and higher) won't get to call the real gpsd_hexdump. For high + * speed, chatty protocols, this can save a lot of CPU. + */ +char *gpsd_hexdump_wrapper(const void *binbuf, size_t binbuflen, + int msg_debug_level) +{ +#ifndef SQUELCH_ENABLE + if (msg_debug_level <= gpsd_hexdump_level) + return gpsd_hexdump(binbuf, binbuflen); +#endif /* SQUELCH_ENABLE */ + return ""; +} + char /*@ observer @*/ *gpsd_hexdump(const void *binbuf, size_t binbuflen) { static char hexbuf[MAX_PACKET_LENGTH*2+1]; |