mirror of
https://github.com/haiwen/libsearpc.git
synced 2025-06-22 11:47:04 +00:00
Add profile support: show function call time
This commit is contained in:
parent
22479b384c
commit
0b0d51accd
@ -17,7 +17,18 @@ contains three fields:
|
|||||||
* **err_msg**: error message. This field is only set if the RPC function
|
* **err_msg**: error message. This field is only set if the RPC function
|
||||||
reports an error.
|
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
|
Example
|
||||||
=======
|
=======
|
||||||
|
@ -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
|
# 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
|
# we need to generate the first
|
||||||
BUILT_SOURCES = gensource
|
BUILT_SOURCES = gensource
|
||||||
|
@ -10,6 +10,10 @@
|
|||||||
#include "searpc-server.h"
|
#include "searpc-server.h"
|
||||||
#include "searpc-utils.h"
|
#include "searpc-utils.h"
|
||||||
|
|
||||||
|
#ifdef PROFILE
|
||||||
|
#include <sys/time.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
struct FuncItem;
|
struct FuncItem;
|
||||||
|
|
||||||
typedef struct MarshalItem {
|
typedef struct MarshalItem {
|
||||||
@ -189,6 +193,11 @@ searpc_server_call_function (gchar *func, gsize len, gsize *ret_len, GError **er
|
|||||||
JsonParser *parser;
|
JsonParser *parser;
|
||||||
JsonNode *root;
|
JsonNode *root;
|
||||||
JsonArray *array;
|
JsonArray *array;
|
||||||
|
#ifdef PROFILE
|
||||||
|
struct timeval start, end, intv;
|
||||||
|
|
||||||
|
gettimeofday(&start, NULL);
|
||||||
|
#endif
|
||||||
|
|
||||||
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
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);
|
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);
|
g_object_unref (parser);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
Loading…
Reference in New Issue
Block a user