diff options
author | Роман Донченко <dpb@corrigendum.ru> | 2014-06-27 22:10:28 +0400 |
---|---|---|
committer | Anders Broman <a.broman58@gmail.com> | 2014-07-06 08:08:20 +0000 |
commit | afa8f21f56f1e65bb2ec37cffdf3422d15b45347 (patch) | |
tree | bbb9b85dfdcc347cc44ce681e724ea80eb857923 /tools/make-dissector-reg | |
parent | 3490bc6eb923e7e8666f9ad9213b0f5010a91c03 (diff) |
make-dissectors-reg: optimize by factoring out the loops
Instead of calling the grep/sed pipelines for each file, build the
list of files in the beginning and call each pipeline only once,
passing the list to the first grep.
This results in a massive speedup in Cygwin; in my test, the time
it takes to run make-dissector-reg . dissectors packet-*.c in dissectors/epan
is reduced from ~116 to ~3 seconds. I also tried it on NetBSD, where
the time do to the same goes from ~6 to ~0.5 seconds.
Amend makefile comments to elide mentions of invoking multiple processes
per file.
Change-Id: Iad441e7d2b6cc3669dada57646e2f8f6b987fd34
Reviewed-on: https://code.wireshark.org/review/2826
Reviewed-by: Anders Broman <a.broman58@gmail.com>
Diffstat (limited to 'tools/make-dissector-reg')
-rwxr-xr-x | tools/make-dissector-reg | 116 |
1 files changed, 36 insertions, 80 deletions
diff --git a/tools/make-dissector-reg b/tools/make-dissector-reg index d28793e1d5..72e896d0b2 100755 --- a/tools/make-dissector-reg +++ b/tools/make-dissector-reg @@ -27,6 +27,22 @@ fi # # All subsequent arguments are the files to scan. # +files='' + +for f in "$@" +do + # This won't work if any filenames contain spaces. + # However, this script is called by make, which doesn't support + # spaces either. + if [ -f "$f" ] + then + files="$files $f" + else + files="$files $srcdir/$f" + fi +done + + rm -f ${outfile}-tmp echo '/* Do not modify this file. */' >${outfile}-tmp echo '/* It is created automatically by the Makefile. */'>>${outfile}-tmp @@ -54,26 +70,11 @@ EOF # # Build code to call all the protocol registration routines. # - for f in "$@" - do - if [ -f $f ] - then - srcfile=$f - else - srcfile=$srcdir/$f - fi - grep '^proto_register_[a-z_0-9A-Z]* *(' $srcfile 2>/dev/null | grep -v ';' - done | sed -e 's/^.*://' -e 's/^\([a-z_0-9A-Z]*\).*/ {extern void \1 (void); \1 ();}/' >>${outfile}-tmp - for f in "$@" - do - if [ -f $f ] - then - srcfile=$f - else - srcfile=$srcdir/$f - fi - grep '^void proto_register_[a-z_0-9A-Z]* *(' $srcfile 2>/dev/null | grep -v ';' - done | sed -e 's/^.*://' -e 's/^void \([a-z_0-9A-Z]*\).*/ {extern void \1 (void); \1 ();}/' >>${outfile}-tmp + grep '^proto_register_[a-z_0-9A-Z]* *(' $files 2>/dev/null | grep -v ';' \ + | sed -e 's/^.*://' -e 's/^\([a-z_0-9A-Z]*\).*/ {extern void \1 (void); \1 ();}/' >>${outfile}-tmp + + grep '^void proto_register_[a-z_0-9A-Z]* *(' $files 2>/dev/null | grep -v ';' \ + | sed -e 's/^.*://' -e 's/^void \([a-z_0-9A-Z]*\).*/ {extern void \1 (void); \1 ();}/' >>${outfile}-tmp else cat <<"EOF" >>${outfile}-tmp #include "register.h" @@ -84,26 +85,11 @@ EOF # # Build code to call all the protocol registration routines. # - for f in "$@" - do - if [ -f $f ] - then - srcfile=$f - else - srcfile=$srcdir/$f - fi - grep '^proto_register_[a-z_0-9A-Z]* *(' $srcfile 2>/dev/null | grep -v ';' - done | sed -e 's/^.*://' -e 's/^\([a-z_0-9A-Z]*\).*/ {extern void \1 (void); if(cb) (*cb)(RA_REGISTER, \"\1\", client_data); \1 ();}/' >>${outfile}-tmp - for f in "$@" - do - if [ -f $f ] - then - srcfile=$f - else - srcfile=$srcdir/$f - fi - grep '^void proto_register_[a-z_0-9A-Z]* *(' $srcfile 2>/dev/null | grep -v ';' - done | sed -e 's/^.*://' -e 's/^void \([a-z_0-9A-Z]*\).*/ {extern void \1 (void); if(cb) (*cb)(RA_REGISTER, \"\1\", client_data); \1 ();}/' >>${outfile}-tmp + grep '^proto_register_[a-z_0-9A-Z]* *(' $files 2>/dev/null | grep -v ';' \ + | sed -e 's/^.*://' -e 's/^\([a-z_0-9A-Z]*\).*/ {extern void \1 (void); if(cb) (*cb)(RA_REGISTER, \"\1\", client_data); \1 ();}/' >>${outfile}-tmp + + grep '^void proto_register_[a-z_0-9A-Z]* *(' $files 2>/dev/null | grep -v ';' \ + | sed -e 's/^.*://' -e 's/^void \([a-z_0-9A-Z]*\).*/ {extern void \1 (void); if(cb) (*cb)(RA_REGISTER, \"\1\", client_data); \1 ();}/' >>${outfile}-tmp fi echo '}' >>${outfile}-tmp @@ -119,52 +105,22 @@ WS_DLL_PUBLIC_DEF void plugin_reg_handoff(void) { EOF - for f in "$@" - do - if [ -f $f ] - then - srcfile=$f - else - srcfile=$srcdir/$f - fi - grep '^proto_reg_handoff_[a-z_0-9A-Z]* *(' $srcfile 2>/dev/null | grep -v ';' - done | sed -e 's/^.*://' -e 's/^\([a-z_0-9A-Z]*\).*/ {extern void \1 (void); \1 ();}/' >>${outfile}-tmp - for f in "$@" - do - if [ -f $f ] - then - srcfile=$f - else - srcfile=$srcdir/$f - fi - grep '^void proto_reg_handoff_[a-z_0-9A-Z]* *(' $srcfile 2>/dev/null | grep -v ';' - done | sed -e 's/^.*://' -e 's/^void \([a-z_0-9A-Z]*\).*/ {extern void \1 (void); \1 ();}/' >>${outfile}-tmp + grep '^proto_reg_handoff_[a-z_0-9A-Z]* *(' $files 2>/dev/null | grep -v ';' \ + | sed -e 's/^.*://' -e 's/^\([a-z_0-9A-Z]*\).*/ {extern void \1 (void); \1 ();}/' >>${outfile}-tmp + + grep '^void proto_reg_handoff_[a-z_0-9A-Z]* *(' $files 2>/dev/null | grep -v ';' \ + | sed -e 's/^.*://' -e 's/^void \([a-z_0-9A-Z]*\).*/ {extern void \1 (void); \1 ();}/' >>${outfile}-tmp else cat <<"EOF" >>${outfile}-tmp void register_all_protocol_handoffs(register_cb cb, gpointer client_data) { EOF - for f in "$@" - do - if [ -f $f ] - then - srcfile=$f - else - srcfile=$srcdir/$f - fi - grep '^proto_reg_handoff_[a-z_0-9A-Z]* *(' $srcfile 2>/dev/null | grep -v ';' - done | sed -e 's/^.*://' -e 's/^\([a-z_0-9A-Z]*\).*/ {extern void \1 (void); if(cb) (*cb)(RA_HANDOFF, \"\1\", client_data); \1 ();}/' >>${outfile}-tmp - for f in "$@" - do - if [ -f $f ] - then - srcfile=$f - else - srcfile=$srcdir/$f - fi - grep '^void proto_reg_handoff_[a-z_0-9A-Z]* *(' $srcfile 2>/dev/null | grep -v ';' - done | sed -e 's/^.*://' -e 's/^void \([a-z_0-9A-Z]*\).*/ {extern void \1 (void); if(cb) (*cb)(RA_HANDOFF, \"\1\", client_data); \1 ();}/' >>${outfile}-tmp + grep '^proto_reg_handoff_[a-z_0-9A-Z]* *(' $files 2>/dev/null | grep -v ';' \ + | sed -e 's/^.*://' -e 's/^\([a-z_0-9A-Z]*\).*/ {extern void \1 (void); if(cb) (*cb)(RA_HANDOFF, \"\1\", client_data); \1 ();}/' >>${outfile}-tmp + + grep '^void proto_reg_handoff_[a-z_0-9A-Z]* *(' $files 2>/dev/null | grep -v ';' \ + | sed -e 's/^.*://' -e 's/^void \([a-z_0-9A-Z]*\).*/ {extern void \1 (void); if(cb) (*cb)(RA_HANDOFF, \"\1\", client_data); \1 ();}/' >>${outfile}-tmp fi echo '}' >>${outfile}-tmp if [ "$registertype" = plugin ] |