Summary: | ASTERISK-05895: [patch] new command, show threads | ||
Reporter: | Luigi Rizzo (rizzo) | Labels: | |
Date Opened: | 2005-12-22 17:22:30.000-0600 | Date Closed: | 2011-06-07 14:03:10 |
Priority: | Major | Regression? | No |
Status: | Closed/Complete | Components: | Core/General |
Versions: | Frequency of Occurrence | ||
Related Issues: | |||
Environment: | Attachments: | ( 0) patch-showthreads ( 1) show_threads.diff | |
Description: | the attached patch implements a new command, "show threads", which lists all currently active threads (see sample output below). It might be useful as a debugging tool. The patch is suitable to improvements, such as: - minor code cleanup; - record the starting time of a thread; - store records in a better data structure so thread termination will run in O(1) instead of O(N) time; Will implement them if there is interest. ****** ADDITIONAL INFORMATION ****** *CLI> show threads 0x8583c00 process_precache started at [ 2154] pbx_dundi.c start_network_thread() 0x8583800 network_thread started at [ 2153] pbx_dundi.c start_network_thread() 0x8583000 scan_thread started at [ 422] pbx_spool.c load_module() 0x8538c00 do_monitor started at [ 6702] chan_zap.c restart_monitor() 0x8538800 sound_thread started at [ 1372] chan_oss.c store_config() 0x8538400 do_monitor started at [ 3042] chan_skinny.c restart_monitor() 0x8538000 accept_thread started at [ 3227] chan_skinny.c reload_config() 0x822fc00 network_thread started at [ 7982] chan_iax2.c start_network_thread() 0x822f000 do_monitor started at [ 3491] chan_mgcp.c restart_monitor() 0x822cc00 do_monitor started at [11122] chan_sip.c restart_monitor() 0x8133800 do_parking_thread started at [ 2149] res_features.c load_module() 0x8133400 do_devstate_changes started at [ 279] devicestate.c ast_device_state_engine_init() 0x8133000 listener started at [ 709] asterisk.c ast_makesocket() 13 threads listed. | ||
Comments: | By: Tilghman Lesher (tilghman) 2005-12-23 00:03:16.000-0600 1. Your prototypes should be in a header file, not listed in each source file. 2. I don't see why dummy_start needs to be a public routine. You should declare it static and get rid of the prototype. By: Luigi Rizzo (rizzo) 2005-12-23 01:49:14.000-0600 I agree with the comments. This code is only a [working] proof of concept. In the final implementation, surely the register/unregister routines, should be static, as they are not meant to be used by anything else, it's just that i have not figured out a good place to do this. One option could be to move dummy_start and maybe the final part of ast_pthread_create_stack() into asterisk.c so the internals of the thread list and its hooks are not publicly visible. That still leaves one extra public function, but to avoid that one should move the entire ast_pthread_create_stack() together with the rest. The other option would be to put everything into utils.c. Not sure which one looks better. Suggestions welcome. But also the question is if there is any interest in having this functionality (in which case the thread_create function should be probably extended with additional arguments describing what the thread does). there is no point in By: Olle Johansson (oej) 2006-01-03 05:03:03.000-0600 I like this feature. Go ahead! It could be enabled under a Makefile option or within the new testing framework, since it's mostly for developers. By: Luigi Rizzo (rizzo) 2006-01-18 12:57:18.000-0600 updated patch, implementing both corydon's suggestions. if some good soul wants to put this in... it would be interesting to have an idea on how many and which threads are running on various systems. By: Olle Johansson (oej) 2006-01-24 06:26:08.000-0600 Hmm. I think this only should be enabled if the DEBUG_THREADS is enabled in the makefile - what do you think? It's not a user's tool anyway, it's more for debugging. By: Luigi Rizzo (rizzo) 2006-01-24 06:36:05.000-0600 oej: it's no different from 'show version files'. and debug_threads is way to expensive to have it running all the times, whereas this one is very little intrusive i believe. anyways we can add a disable hook if we don't want it. probably a runtime one, though. By: Olle Johansson (oej) 2006-03-04 05:02:06.000-0600 I am getting a lot of compilation warnings and errors while trying to apply this patch to current trunk. Please update - I would like to include this in the test branch. By: Luigi Rizzo (rizzo) 2006-03-05 09:51:15.000-0600 oej - i just applied the patch from mantis to SVN 11914 and it compiles fine. What errors are you getting ? By: Olle Johansson (oej) 2006-03-06 02:03:23.000-0600 gcc -D_FILE_OFFSET_BITS=64 -pipe -Wall -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -g3 -Iinclude -I../include -D_REENTRANT -D_GNU_SOURCE -O6 -Wno-pointer-sign -fomit-frame-pointer -D__Darwin__ -DPOLLCOMPAT -DT38_SUPPORT -c -o utils.o utils.c utils.c: In function 'dummy_start': utils.c:531: warning: no previous prototype for 'ast_pthread_create_stack' utils.c:572: warning: no previous prototype for 'ast_wait_for_input' utils.c:581: warning: no previous prototype for 'ast_strip_quoted' utils.c:598: warning: no previous prototype for 'ast_build_string_va' utils.c:617: warning: no previous prototype for 'ast_build_string' utils.c:629: warning: no previous prototype for 'ast_true' utils.c:646: warning: no previous prototype for 'ast_false' utils.c:668: error: invalid storage class for function 'tvfix' utils.c:668: warning: no previous prototype for 'tvfix' utils.c:683: warning: no previous prototype for 'ast_tvadd' utils.c:697: warning: no previous prototype for 'ast_tvsub' utils.c:713: error: invalid storage class for function 'upper' utils.c:713: warning: no previous prototype for 'upper' utils.c:727: warning: no previous prototype for 'strcasestr' utils.c:755: warning: no previous prototype for 'strnlen' utils.c:768: warning: no previous prototype for 'strndup' utils.c:926: warning: no previous prototype for 'getloadavg' utils.c:941: error: invalid storage class for function 'init_randomlock' utils.c:941: warning: no previous prototype for 'init_randomlock' utils.c:941: error: invalid storage class for function 'fini_randomlock' utils.c:941: warning: no previous prototype for 'fini_randomlock' utils.c:944: warning: no previous prototype for 'ast_random' utils.c:954: warning: no previous prototype for 'ast_process_quotes_and_slashes' utils.c:980: warning: no previous prototype for 'ast_join' utils.c:1001: error: invalid storage class for function 'add_string_pool' utils.c:1001: warning: no previous prototype for 'add_string_pool' utils.c:1018: warning: no previous prototype for '__ast_string_field_init' utils.c:1032: warning: no previous prototype for '__ast_string_field_alloc_space' utils.c:1054: warning: no previous prototype for '__ast_string_field_index_build' utils.c:1089: warning: no previous prototype for 'ast_get_time_t' utils.c:1109: error: parse error at end of input make: *** [utils.o] Error 1 By: Olle Johansson (oej) 2006-03-06 02:06:47.000-0600 This is on OS/X By: Olle Johansson (oej) 2006-03-06 14:46:17.000-0600 Added to test-this-branch with small fix by tholo for OS/X support. By: Olle Johansson (oej) 2006-03-06 14:48:07.000-0600 This small fix by tholo fixed this patch: static void *dummy_start(void *data) { void *ret; struct thr_arg a = *((struct thr_arg *)data); /* make a local copy */ free(data); ast_register_thread(a.name); pthread_cleanup_push(ast_unregister_thread, pthread_self()); /* on unregister */ ret = a.start_routine(a.data); pthread_cleanup_pop(1); return ret; } By: Luigi Rizzo (rizzo) 2006-03-28 09:50:05.000-0600 this code is now maintained as part of SVN6795, so this report can be closed. By: Luigi Rizzo (rizzo) 2006-03-28 09:55:18.000-0600 maintained as part of SVN6795 |