From 0b0d51accd150146918ca34bf363dd914c4ec49c Mon Sep 17 00:00:00 2001 From: plt Date: Sun, 25 Dec 2011 15:30:15 +0800 Subject: [PATCH] Add profile support: show function call time --- README.markdown | 13 ++++++++++++- lib/Makefile.am | 5 ++++- lib/searpc-server.c | 16 ++++++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/README.markdown b/README.markdown index 41429a2..ce72ac3 100644 --- a/README.markdown +++ b/README.markdown @@ -17,7 +17,18 @@ contains three fields: * **err_msg**: error message. This field is only set if the RPC function reports an error. - +Compile +======= + +Just + + ./autogen.sh; ./configure; make; make install + +To enable profile, Use + + CFLAGS="-DPROFILE" ./configure + +When profile is enabled, the time spend in each rpc call will be printed. Example ======= diff --git a/lib/Makefile.am b/lib/Makefile.am index e53dd81..c1f2909 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -19,7 +19,10 @@ generated_sources = fcall-impr.h searpc-fcall.h searpc-dfun.h \ # rpc_headers = fcall-impr.h searpc-fcall.h searpc-dfun.h searpc-signature.h searpc-marshal.h -AM_CFLAGS = @GLIB2_CFLAGS@ @GOBJECT_CFLAGS@ @JSON_GLIB_CFLAGS@ -I${top_builddir}/lib -I${top_srcdir}/lib +AM_CFLAGS = @GLIB2_CFLAGS@ @GOBJECT_CFLAGS@ @JSON_GLIB_CFLAGS@ \ + -I${top_builddir}/lib \ + -I${top_srcdir}/lib \ + -DG_LOG_DOMAIN=\"Searpc\" # we need to generate the first BUILT_SOURCES = gensource diff --git a/lib/searpc-server.c b/lib/searpc-server.c index e1d62fd..9b0fe74 100644 --- a/lib/searpc-server.c +++ b/lib/searpc-server.c @@ -10,6 +10,10 @@ #include "searpc-server.h" #include "searpc-utils.h" +#ifdef PROFILE + #include +#endif + struct FuncItem; typedef struct MarshalItem { @@ -189,6 +193,11 @@ searpc_server_call_function (gchar *func, gsize len, gsize *ret_len, GError **er JsonParser *parser; JsonNode *root; JsonArray *array; +#ifdef PROFILE + struct timeval start, end, intv; + + gettimeofday(&start, NULL); +#endif g_return_val_if_fail (error == NULL || *error == NULL, NULL); @@ -213,6 +222,13 @@ searpc_server_call_function (gchar *func, gsize len, gsize *ret_len, GError **er gchar* ret = fitem->marshal->mfunc (fitem->func, array, ret_len); +#ifdef PROFILE + gettimeofday(&end, NULL); + timersub(&end, &start, &intv); + g_debug ("[searpc] Time spend in call %s: %ds %dus\n", + fname, intv.tv_sec, intv.tv_usec); +#endif + g_object_unref (parser); return ret;