Index: channel.c =================================================================== RCS file: /usr/local/cvsroot/asterisk/channel.c,v retrieving revision 1.137 diff -u -r1.137 channel.c --- channel.c 2 Sep 2004 13:48:11 -0000 1.137 +++ channel.c 3 Sep 2004 00:25:04 -0000 @@ -79,8 +79,7 @@ int ast_check_hangup(struct ast_channel *chan) { time_t myt; - - /* if soft hangup flag, return true */ + /* if soft hangup flag, return true */ if (chan->_softhangup) return 1; /* if no private structure, return true */ if (!chan->pvt->pvt) return 1; @@ -278,7 +277,7 @@ int x; int flags; struct varshead *headp; - + struct timeval now; /* If shutting down, don't allocate any new channels */ if (shutting_down) @@ -330,6 +329,8 @@ tmp->pvt = pvt; /* Initial state */ tmp->_state = AST_STATE_DOWN; + gettimeofday(&now, NULL); + tmp->whenstarted = now.tv_sec; tmp->stack = -1; tmp->streamid = -1; tmp->appl = NULL; @@ -2205,6 +2206,7 @@ char orig[100]; char masqn[100]; char zombn[100]; + struct timeval now; #if 1 ast_log(LOG_DEBUG, "Actually Masquerading %s(%d) into the structure of %s(%d)\n", @@ -2283,6 +2285,8 @@ origstate = original->_state; original->_state = clone->_state; clone->_state = origstate; + gettimeofday(&now, NULL); + clone->whenstarted = now.tv_sec; if (clone->pvt->fixup){ res = clone->pvt->fixup(original, clone); @@ -2428,9 +2432,13 @@ int ast_setstate(struct ast_channel *chan, int state) { + struct timeval now; + if (chan->_state != state) { int oldstate = chan->_state; chan->_state = state; + gettimeofday(&now, NULL); + chan->whenstarted = now.tv_sec; if (oldstate == AST_STATE_DOWN) { ast_device_state_changed(chan->name); manager_event(EVENT_FLAG_CALL, "Newchannel", Index: cli.c =================================================================== RCS file: /usr/local/cvsroot/asterisk/cli.c,v retrieving revision 1.50 diff -u -r1.50 cli.c --- cli.c 2 Sep 2004 20:45:24 -0000 1.50 +++ cli.c 3 Sep 2004 00:25:04 -0000 @@ -311,20 +311,34 @@ } static int handle_chanlist(int fd, int argc, char *argv[]) { -#define FORMAT_STRING "%15s (%-10s %-12s %-4d) %7s %-12s %-15s\n" -#define FORMAT_STRING2 "%15s (%-10s %-12s %-4s) %7s %-12s %-15s\n" +#define FORMAT_STRING "%dh%dm%ds %25s (%-10s %-12s %-4d) %7s %-12s %-15s\n" +#define FORMAT_STRING2 "%s %22s (%-10s %-12s %-4s) %7s %-12s %-15s\n" #define CONCISE_FORMAT_STRING "%s:%s:%s:%d:%s:%s:%s:%s:%s:%d\n" struct ast_channel *c=NULL; int numchans = 0; int concise = 0; + int diff = 0; + int hrs = 0; + int min = 0; + int sec = 0; + struct timeval now; + if (argc < 2 || argc > 3) return RESULT_SHOWUSAGE; + gettimeofday(&now, NULL); concise = (argc == 3 && (!strcasecmp(argv[2],"concise"))); c = ast_channel_walk_locked(NULL); + + if (c) { + diff = now.tv_sec - c->whenstarted; + hrs = diff / 3600; + min = (diff % 3600) / 60; + sec = diff % 60; + } if(!concise) - ast_cli(fd, FORMAT_STRING2, "Channel", "Context", "Extension", "Pri", "State", "Appl.", "Data"); + ast_cli(fd, FORMAT_STRING2, "Time Active", "Channel", "Context", "Extension", "Pri", "State", "Appl.", "Data"); while(c) { if(concise) ast_cli(fd, CONCISE_FORMAT_STRING, c->name, c->context, c->exten, c->priority, ast_state2str(c->_state), @@ -332,7 +346,7 @@ (c->callerid && !ast_strlen_zero(c->callerid)) ? c->callerid : "", (c->accountcode && !ast_strlen_zero(c->accountcode)) ? c->accountcode : "",c->amaflags); else - ast_cli(fd, FORMAT_STRING, c->name, c->context, c->exten, c->priority, ast_state2str(c->_state), + ast_cli(fd, FORMAT_STRING, hrs, min, sec, c->name, c->context, c->exten, c->priority, ast_state2str(c->_state), c->appl ? c->appl : "(None)", c->data ? ( !ast_strlen_zero(c->data) ? c->data : "(Empty)" ): "(None)"); numchans++; Index: include/asterisk/channel.h =================================================================== RCS file: /usr/local/cvsroot/asterisk/include/asterisk/channel.h,v retrieving revision 1.54 diff -u -r1.54 channel.h --- include/asterisk/channel.h 6 Aug 2004 14:43:25 -0000 1.54 +++ include/asterisk/channel.h 3 Sep 2004 00:25:04 -0000 @@ -95,6 +95,8 @@ int zombie; /*! Non-zero, set to actual time when channel is to be hung up */ time_t whentohangup; + /*! Non-zero, set to actual time when channel is started */ + time_t whenstarted; /*! If anyone is blocking, this is them */ pthread_t blocker; /*! Lock, can be used to lock a channel for some operations */