Mercurial > libpst
changeset 288:fa7fc1ac6385
add gprof profiling option; allow fork for parallel processing of individual email folders in separate mode
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Fri, 27 May 2011 09:50:24 -0700 |
parents | 0f0ccd29b0d7 |
children | cc8ee701f190 |
files | configure.in regression/regression-tests.bash src/readpst.c |
diffstat | 3 files changed, 60 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/configure.in Tue May 24 17:01:00 2011 -0700 +++ b/configure.in Fri May 27 09:50:24 2011 -0700 @@ -268,7 +268,7 @@ case "${enableval}" in yes) ;; no) ;; - *) AC_MSG_ERROR(bad value ${enableval} for --static-tools) ;; + *) AC_MSG_ERROR(bad value ${enableval} for --enable-static-tools) ;; esac ], [ @@ -324,6 +324,34 @@ fi +# The following lines adds the --enable-profiling option to configure: +# +# Give the user the choice to enter one of these: +# --enable-profiling +# --enable-profiling=yes +# --enable-profiling=no +# +AC_MSG_CHECKING([whether to link with gprof profiling]) +AC_ARG_ENABLE([profiling], + AC_HELP_STRING([--enable-profiling], [link with gprof profiling]), + [ + case "${enableval}" in + yes) + CFLAGS="$CFLAGS -pg" + CPPFLAGS="$CPPFLAGS -pg" + CXXFLAGS="$CXXFLAGS -pg" + ;; + no) + ;; + *) AC_MSG_ERROR(bad value ${enableval} for --profiling) ;; + esac + ], + [ + enable_profiling=no + ]) +AC_MSG_RESULT([$enable_profiling]) +AM_CONDITIONAL(GPROF_PROFILING, [test "$enable_profiling" = "yes"]) + AC_OUTPUT( \ Makefile \
--- a/regression/regression-tests.bash Tue May 24 17:01:00 2011 -0700 +++ b/regression/regression-tests.bash Fri May 27 09:50:24 2011 -0700 @@ -101,7 +101,7 @@ [ "$2" == "reg" ] && regression="yes" [ "$regression" == "yes" ] && val="" -$func 1 ams.pst +#$func 1 ams.pst #$func 2 sample_64.pst #$func 3 test.pst #$func 4 big_mail.pst @@ -125,7 +125,7 @@ #$func 23 rendgen5.pst # appointment test cases #$func 24 paul.sheer.pst # embedded rfc822 attachment #$func 25 jerry.pst # non ascii subject lines -#$func 26 phill.bertolus.pst # possible segfault in forked process, cannot reproduce +$func 26 phill.bertolus.pst # possible segfault in forked process, cannot reproduce #$func 27 justin.phelps.pst # segfault?
--- a/src/readpst.c Tue May 24 17:01:00 2011 -0700 +++ b/src/readpst.c Fri May 27 09:50:24 2011 -0700 @@ -152,7 +152,7 @@ #ifdef HAVE_FORK #ifdef HAVE_SEMAPHORE_H if (global_children) { - sem_getvalue(global_children, &available); + //sem_getvalue(global_children, &available); //printf("grim reaper %s for pid %d (parent %d) with %d children, %d available\n", (waitall) ? "all" : "", getpid(), getppid(), active_children, available); //fflush(stdout); int i,j; @@ -330,10 +330,35 @@ DEBUG_INFO(("I have an email type %"PRIi32", but the folder type %"PRIi32" isn't an email folder. Skipping it\n", item->type, ff.type)); } else { + ff.item_count++; char *extra_mime_headers = NULL; - ff.item_count++; - if (mode == MODE_SEPARATE) mk_separate_file(&ff, (mode_EX) ? ".eml" : ""); - write_normal_email(ff.output, ff.name, item, mode, mode_MH, &pstfile, save_rtf_body, &extra_mime_headers); + if (mode == MODE_SEPARATE) { + // process this single email message, possibly forking + pid_t parent = getpid(); + pid_t child = try_fork(item->file_as.str); + if (child == 0) { + // we are the child process, or the original parent if no children were available + pid_t me = getpid(); + mk_separate_file(&ff, (mode_EX) ? ".eml" : ""); + write_normal_email(ff.output, ff.name, item, mode, mode_MH, &pstfile, save_rtf_body, &extra_mime_headers); +#ifdef HAVE_FORK +#ifdef HAVE_SEMAPHORE_H + if (me != parent) { + // we really were a child, forked for the sole purpose of processing this message + // free my child count slot before really exiting, since + // all I am doing here is waiting for my children to exit + sem_post(global_children); + grim_reaper(1); // wait for all my child processes to exit - there should not be any + exit(0); // really exit + } +#endif +#endif + } + } + else { + // process this single email message, cannot fork since not separate mode + write_normal_email(ff.output, ff.name, item, mode, mode_MH, &pstfile, save_rtf_body, &extra_mime_headers); + } } }