* mu-cmd-index: show some timing information for the indexing

This commit is contained in:
Dirk-Jan C. Binnema
2010-09-12 21:18:30 +03:00
parent 2fef78abc1
commit 9a32d86851

View File

@ -52,9 +52,10 @@ update_warning (void)
static void static void
sig_handler (int sig) sig_handler (int sig)
{ {
if (!MU_CAUGHT_SIGNAL && sig == SIGINT) /* Ctrl-C */ if (!MU_CAUGHT_SIGNAL && sig == SIGINT) { /* Ctrl-C */
g_warning ("Shutting down gracefully, " g_warning ("Shutting down gracefully, "
"press again to kill immediately\n"); "press again to kill immediately");
}
MU_CAUGHT_SIGNAL = TRUE; MU_CAUGHT_SIGNAL = TRUE;
} }
@ -219,6 +220,16 @@ run_index (MuIndex *midx, const char* maildir, MuIndexStats *stats,
return rv; return rv;
} }
static void
show_time (unsigned t, unsigned processed)
{
if (processed)
g_message ("Elapsed: %u second(s), ca. %.2f seconds per message",
t, (double)((t+.0)/(processed+.0)));
else
g_message ("Elapsed: %u second(s)", t);
}
gboolean gboolean
mu_cmd_index (MuConfigOptions *opts) mu_cmd_index (MuConfigOptions *opts)
@ -226,12 +237,12 @@ mu_cmd_index (MuConfigOptions *opts)
gboolean rv; gboolean rv;
MuIndex *midx; MuIndex *midx;
MuIndexStats stats; MuIndexStats stats;
time_t t;
g_return_val_if_fail (opts, FALSE); g_return_val_if_fail (opts, FALSE);
g_return_val_if_fail (mu_cmd_equals (opts, "index"), FALSE); g_return_val_if_fail (mu_cmd_equals (opts, "index"), FALSE);
if (!check_index_params (opts) || if (!check_index_params (opts) || !database_version_check_and_update(opts))
!database_version_check_and_update(opts))
return FALSE; return FALSE;
install_sig_handler (); install_sig_handler ();
@ -244,22 +255,22 @@ mu_cmd_index (MuConfigOptions *opts)
g_message ("Indexing messages under %s", opts->maildir); g_message ("Indexing messages under %s", opts->maildir);
g_message ("Database: %s", opts->xpath); g_message ("Database: %s", opts->xpath);
t = time (NULL);
rv = run_index (midx, opts->maildir, &stats, rv = run_index (midx, opts->maildir, &stats, opts->reindex, opts->quiet);
opts->reindex, opts->quiet); maybe_newline (opts->quiet);
show_time ((unsigned)(time(NULL)-t), stats._processed);
if (rv == MU_OK && !opts->nocleanup) { if (rv == MU_OK && !opts->nocleanup) {
maybe_newline (opts->quiet);
stats._processed = 0; /* restart processed at 0 */ stats._processed = 0; /* restart processed at 0 */
t = time (NULL);
rv = run_cleanup (midx, &stats, opts->quiet); rv = run_cleanup (midx, &stats, opts->quiet);
maybe_newline (opts->quiet);
show_time ((unsigned)(time(NULL)-t),stats._processed);
} }
mu_index_destroy (midx); mu_index_destroy (midx);
MU_WRITE_LOG ("processed: %u; updated/new: %u, cleaned-up: %u", MU_WRITE_LOG ("processed: %u; updated/new: %u, cleaned-up: %u",
(unsigned)stats._processed, (unsigned)stats._updated, stats._processed, stats._updated, stats._cleaned_up);
(unsigned)stats._cleaned_up);
maybe_newline (opts->quiet);
return (rv == MU_OK || rv == MU_STOP) ? TRUE: FALSE; return (rv == MU_OK || rv == MU_STOP) ? TRUE: FALSE;
} }