D807: chg: show timestamp with debug messages
quark (Jun Wu)
phabricator at mercurial-scm.org
Sat Sep 23 22:08:58 UTC 2017
quark created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.
REVISION SUMMARY
Like `strace -tr`, this helps finding performance bottlenecks.
REPOSITORY
rHG Mercurial
REVISION DETAIL
https://phab.mercurial-scm.org/D807
AFFECTED FILES
contrib/chg/util.c
CHANGE DETAILS
diff --git a/contrib/chg/util.c b/contrib/chg/util.c
--- a/contrib/chg/util.c
+++ b/contrib/chg/util.c
@@ -14,6 +14,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <sys/time.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
@@ -59,6 +60,13 @@
}
static int debugmsgenabled = 0;
+static double debugstart = 0;
+
+static double now() {
+ struct timeval t;
+ gettimeofday(&t, 0);
+ return t.tv_usec / 1e6 + t.tv_sec;
+}
void enablecolor(void)
{
@@ -68,6 +76,7 @@
void enabledebugmsg(void)
{
debugmsgenabled = 1;
+ debugstart = now();
}
void debugmsg(const char *fmt, ...)
@@ -78,7 +87,7 @@
va_list args;
va_start(args, fmt);
fsetcolor(stderr, "1;30");
- fputs("chg: debug: ", stderr);
+ fprintf(stderr, "chg: debug: %4.6f ", now() - debugstart);
vfprintf(stderr, fmt, args);
fsetcolor(stderr, "");
fputc('\n', stderr);
To: quark, #hg-reviewers
Cc: mercurial-devel
More information about the Mercurial-devel
mailing list