diff options
author | clkao <clkao@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2010-11-10 16:36:38 +0800 |
---|---|---|
committer | clkao <clkao@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2010-11-10 16:36:38 +0800 |
commit | ed034c33a4f641e99c35fc7368de66f74dc41c36 (patch) | |
tree | e7317356547a79001305d09c1dd57883de4cd9c6 | |
parent | 68978689a41dc6ab73b4cea5438c00248f4d085d (diff) | |
download | pttbbs-ed034c33a4f641e99c35fc7368de66f74dc41c36.tar pttbbs-ed034c33a4f641e99c35fc7368de66f74dc41c36.tar.gz pttbbs-ed034c33a4f641e99c35fc7368de66f74dc41c36.tar.bz2 pttbbs-ed034c33a4f641e99c35fc7368de66f74dc41c36.tar.lz pttbbs-ed034c33a4f641e99c35fc7368de66f74dc41c36.tar.xz pttbbs-ed034c33a4f641e99c35fc7368de66f74dc41c36.tar.zst pttbbs-ed034c33a4f641e99c35fc7368de66f74dc41c36.zip |
macros for collecting rusage cpu stats
git-svn-id: http://opensvn.csie.org/pttbbs/trunk@5235 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r-- | pttbbs/include/statistic.h | 26 | ||||
-rw-r--r-- | pttbbs/mbbsd/read.c | 3 |
2 files changed, 29 insertions, 0 deletions
diff --git a/pttbbs/include/statistic.h b/pttbbs/include/statistic.h index 0d22f6f0..03110853 100644 --- a/pttbbs/include/statistic.h +++ b/pttbbs/include/statistic.h @@ -6,6 +6,29 @@ } while(0) #define STATINC(X) STAT(X, ++) +#ifdef CPU_STATS + +#include <sys/time.h> +#include <sys/resource.h> + +#define BEGINSTAT(name) struct rusage name ## _start; getrusage(RUSAGE_SELF, &(name ## _start)); + +#define TVALDIFF_TO_MS(start, end) ((end.tv_sec - start.tv_sec)*1000 + (end.tv_usec - start.tv_usec)/1000) + +#define ENDSTAT(name) do { \ + struct rusage *_start = &( name ## _start), _end; \ + getrusage(RUSAGE_SELF, &_end); \ + STAT(name ## _S, += TVALDIFF_TO_MS(_end.ru_stime, _start->ru_stime)); \ + STAT(name ## _U, += TVALDIFF_TO_MS(_end.ru_utime, _start->ru_utime)); \ + STATINC(name); \ +} while(0); + +#else +#define BEGINSTAT(name) +#define ENDSTAT(name) STATINC(name) +#endif + + enum { // XXX description in shmctl.c STAT_LOGIN, STAT_SHELLLOGIN, @@ -45,6 +68,9 @@ enum { // XXX description in shmctl.c STAT_READPOST_7DAY, STAT_READPOST_OLD, STAT_SIGXCPU, + STAT_BOARDREC, + STAT_BOARDREC_S, + STAT_BOARDREC_U, /* insert here. don't forget update shmctl.c */ STAT_NUM, STAT_MAX=512 diff --git a/pttbbs/mbbsd/read.c b/pttbbs/mbbsd/read.c index 022a3e77..1b0f89a3 100644 --- a/pttbbs/mbbsd/read.c +++ b/pttbbs/mbbsd/read.c @@ -1159,11 +1159,13 @@ get_records_and_bottom(const char *direct, fileheader_t* headers, if( last_line < 1) // 完全沒東西 return 0; + BEGINSTAT(STAT_BOARDREC); // 不顯示置底的情形 if( n >= headers_size || (currmode & (MODE_SELECT | MODE_DIGEST)) ) { rv = get_records(direct, headers, sizeof(fileheader_t), recbase, headers_size); + ENDSTAT(STAT_BOARDREC); return rv > 0 ? rv : 0; } @@ -1195,6 +1197,7 @@ get_records_and_bottom(const char *direct, fileheader_t* headers, rv += n; } + ENDSTAT(STAT_BOARDREC); return rv; } |