-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add notice-log for every request #226
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/usr/bin/env python | ||
#coding: utf-8 | ||
#file : gen_msg_type_str.py | ||
#author : ning | ||
#date : 2014-05-28 13:45:16 | ||
|
||
|
||
import os | ||
import re | ||
|
||
content = file('src/nc_message.h').read() | ||
|
||
m = re.search(r'typedef enum msg_type {(.*?)}', content, re.DOTALL) | ||
body = m.group(1) | ||
print body | ||
|
||
print ''' | ||
inline char * | ||
nc_msg_type_str(msg_type_t type) | ||
{ | ||
switch (type) { | ||
''' | ||
|
||
for line in body.split(): | ||
if line.find(',') > -1: | ||
msg_type = line.split(',')[0].strip() | ||
msg_type_str = msg_type.split('_')[-1] | ||
print ' case %s: ' % msg_type | ||
print ' return "%s"; ' % msg_type_str | ||
|
||
print ''' | ||
default: | ||
+ return "UNKNOWN"; | ||
} | ||
} | ||
''' | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -168,6 +168,7 @@ struct msg { | |
|
||
struct mhdr mhdr; /* message mbuf header */ | ||
uint32_t mlen; /* message length */ | ||
int64_t start_usec; /* request start usec*/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. usec */ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. call this `int_64_t start_ts /* request start timestamp in usec */ |
||
|
||
int state; /* current parser state */ | ||
uint8_t *pos; /* parser position marker */ | ||
|
@@ -229,6 +230,7 @@ void msg_dump(struct msg *msg); | |
bool msg_empty(struct msg *msg); | ||
rstatus_t msg_recv(struct context *ctx, struct conn *conn); | ||
rstatus_t msg_send(struct context *ctx, struct conn *conn); | ||
char * msg_type_str(msg_type_t type); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. s/char */uint_8 */ |
||
|
||
struct msg *req_get(struct conn *conn); | ||
void req_put(struct msg *msg); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,8 @@ | |
#include <nc_core.h> | ||
#include <nc_server.h> | ||
|
||
void req_notice_log(struct msg * req); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. formatting - |
||
|
||
struct msg * | ||
req_get(struct conn *conn) | ||
{ | ||
|
@@ -29,6 +31,9 @@ req_get(struct conn *conn) | |
if (msg == NULL) { | ||
conn->err = errno; | ||
} | ||
if (log_loggable(LOG_NOTICE) != 0){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. space between the closing paren and curly brace. So |
||
msg->start_usec = nc_usec_now(); | ||
} | ||
|
||
return msg; | ||
} | ||
|
@@ -40,6 +45,8 @@ req_put(struct msg *msg) | |
|
||
ASSERT(msg->request); | ||
|
||
req_notice_log(msg); | ||
|
||
pmsg = msg->peer; | ||
if (pmsg != NULL) { | ||
ASSERT(!pmsg->request && pmsg->peer == msg); | ||
|
@@ -53,6 +60,48 @@ req_put(struct msg *msg) | |
msg_put(msg); | ||
} | ||
|
||
void | ||
req_notice_log(struct msg * req){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just call it req_log() also format is |
||
struct msg *rsp; /* peer message (response) */ | ||
int64_t request_time; /*time cost for this request*/ | ||
|
||
uint32_t req_len = 0; /* message length */ | ||
uint32_t rsp_len = 0; /* message length */ | ||
|
||
|
||
if (log_loggable(LOG_NOTICE) == 0){ | ||
return; | ||
} | ||
|
||
if (req->start_usec == 0){ /*a fragment*/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. formatting -- |
||
return; | ||
} | ||
|
||
if (req->mlen == 0){ /*conn close normally*/ | ||
return; | ||
} | ||
|
||
rsp = req->peer; | ||
|
||
req_len = req->mlen; | ||
if(rsp){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. formatting - |
||
rsp_len = rsp->mlen; | ||
} | ||
|
||
if (req->key_end){ | ||
*(req->key_end) = '\0'; | ||
} | ||
|
||
request_time = nc_usec_now() - req->start_usec; | ||
|
||
log_debug(LOG_NOTICE, "notice req %"PRIu64" done on c %d req_time: %"PRIi64".%03"PRIi64" type: %s " | ||
"narg: %"PRIu32" req_len: %"PRIu32" rsp_len: %"PRIu32" " | ||
"key0: %s, done: %d, error:%d", | ||
req->id, req->owner->sd, request_time/1000, request_time%1000, msg_type_str(req->type), | ||
req->narg, req_len, rsp_len, | ||
req->key_start, req->done, req->error); | ||
} | ||
|
||
/* | ||
* Return true if request is done, false otherwise | ||
* | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for a py script. You can generate the strings using macro magic called strigificaion :) This way your code never gets outdate
See this for reference --
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
macro create clean code but break cscope/ctags :(
clean code is more important, I will have a try.