1
0
mirror of https://github.com/haiwen/libsearpc.git synced 2025-05-08 15:16:19 +00:00

Add profile support: show function call time

This commit is contained in:
plt 2011-12-25 15:30:15 +08:00
parent 22479b384c
commit 0b0d51accd
3 changed files with 32 additions and 2 deletions

View File

@ -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
=======

View File

@ -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

View File

@ -10,6 +10,10 @@
#include "searpc-server.h"
#include "searpc-utils.h"
#ifdef PROFILE
#include <sys/time.h>
#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;