Module: sip-router Branch: master Commit: b6ae8ad5695eb6c4ec330f8ca44725a36172b8d4 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=b6ae8ad5...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: Wed Dec 22 12:59:00 2010 +0100
kex: pkg.stats command extended
- it can take optionally a filter for which process to print pkg stats. It can be: - pid value - print by process pid - rank value - print by process rank - index value - print by index in process table
---
modules_k/kex/pkg_stats.c | 71 +++++++++++++++++++++++++++++++------------- 1 files changed, 50 insertions(+), 21 deletions(-)
diff --git a/modules_k/kex/pkg_stats.c b/modules_k/kex/pkg_stats.c index 7a8d9c3..2a04e3d 100644 --- a/modules_k/kex/pkg_stats.c +++ b/modules_k/kex/pkg_stats.c @@ -182,8 +182,10 @@ static void rpc_pkg_stats(rpc_t* rpc, void* ctx) { int i; int limit; - int lpid; + int cval; + str cname; void* th; + int mode;
if(_pkg_proc_stats_list==NULL) { @@ -191,37 +193,64 @@ static void rpc_pkg_stats(rpc_t* rpc, void* ctx) return; } i = 0; + mode = 0; + cval = 0; limit = _pkg_proc_stats_no; - if (rpc->scan(ctx, "*d", &lpid) == 1) + if (rpc->scan(ctx, "*S", &cname) == 1) { - i = pkg_proc_get_pid_index((unsigned int)lpid); - if(i<0) + if(cname.len==3 && strncmp(cname.s, "pid", 3)==0) + mode = 1; + else if(cname.len==4 && strncmp(cname.s, "rank", 4)==0) + mode = 2; + else if(cname.len==5 && strncmp(cname.s, "index", 5)==0) + mode = 3; + else { + rpc->fault(ctx, 500, "Invalid filter type"); + return; + } + + if (rpc->scan(ctx, "d", &cval) < 1) { - rpc->fault(ctx, 500, "No such pid"); + rpc->fault(ctx, 500, "One more parameter expected"); return; } - limit = i + 1; + if(mode==1) + { + i = pkg_proc_get_pid_index((unsigned int)cval); + if(i<0) + { + rpc->fault(ctx, 500, "No such pid"); + return; + } + limit = i + 1; + } else if(mode==3) { + i=cval; + limit = i + 1; + } }
for(; i<limit; i++) { /* add entry node */ - if (rpc->add(ctx, "{", &th) < 0) + if(mode!=2 || _pkg_proc_stats_list[i].rank==cval) { - rpc->fault(ctx, 500, "Internal error creating rpc"); - return; - } - if(rpc->struct_add(th, "dddddd", - "entry", i, - "pid", _pkg_proc_stats_list[i].pid, - "rank", _pkg_proc_stats_list[i].rank, - "used", _pkg_proc_stats_list[i].used, - "free", _pkg_proc_stats_list[i].available, - "real_used", _pkg_proc_stats_list[i].real_used - )<0) - { - rpc->fault(ctx, 500, "Internal error creating rpc"); - return; + if (rpc->add(ctx, "{", &th) < 0) + { + rpc->fault(ctx, 500, "Internal error creating rpc"); + return; + } + if(rpc->struct_add(th, "dddddd", + "entry", i, + "pid", _pkg_proc_stats_list[i].pid, + "rank", _pkg_proc_stats_list[i].rank, + "used", _pkg_proc_stats_list[i].used, + "free", _pkg_proc_stats_list[i].available, + "real_used", _pkg_proc_stats_list[i].real_used + )<0) + { + rpc->fault(ctx, 500, "Internal error creating rpc"); + return; + } } } }