summaryrefslogtreecommitdiff
path: root/main/threadstorage.c
diff options
context:
space:
mode:
authorRussell Bryant <russell@russellbryant.com>2007-10-11 19:03:06 +0000
committerRussell Bryant <russell@russellbryant.com>2007-10-11 19:03:06 +0000
commite97a723cf1710d0c40bcbe7ac53fc943abedd2c4 (patch)
tree44dcb2c14abed6932db4f248b17626a01a38f59b /main/threadstorage.c
parent8a52c889883f2013e377d87389f07aec5b781122 (diff)
Merge a ton of NEW_CLI conversions. Thanks to everyone that helped out! :)
(closes issue #10724) Reported by: eliel Patches: chan_skinny.c.patch uploaded by eliel (license 64) chan_oss.c.patch uploaded by eliel (license 64) chan_mgcp.c.patch2 uploaded by eliel (license 64) pbx_config.c.patch uploaded by seanbright (license 71) iax2-provision.c.patch uploaded by eliel (license 64) chan_gtalk.c.patch uploaded by eliel (license 64) pbx_ael.c.patch uploaded by seanbright (license 71) file.c.patch uploaded by seanbright (license 71) image.c.patch uploaded by seanbright (license 71) cli.c.patch uploaded by moy (license 222) astobj2.c.patch uploaded by moy (license 222) asterisk.c.patch uploaded by moy (license 222) res_limit.c.patch uploaded by seanbright (license 71) res_convert.c.patch uploaded by seanbright (license 71) res_crypto.c.patch uploaded by seanbright (license 71) app_osplookup.c.patch uploaded by seanbright (license 71) app_rpt.c.patch uploaded by seanbright (license 71) app_mixmonitor.c.patch uploaded by seanbright (license 71) channel.c.patch uploaded by seanbright (license 71) translate.c.patch uploaded by seanbright (license 71) udptl.c.patch uploaded by seanbright (license 71) threadstorage.c.patch uploaded by seanbright (license 71) db.c.patch uploaded by seanbright (license 71) cdr.c.patch uploaded by moy (license 222) pbd_dundi.c.patch uploaded by moy (license 222) app_osplookup-rev83558.patch uploaded by moy (license 222) res_clioriginate.c.patch uploaded by moy (license 222) git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@85460 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main/threadstorage.c')
-rw-r--r--main/threadstorage.c79
1 files changed, 47 insertions, 32 deletions
diff --git a/main/threadstorage.c b/main/threadstorage.c
index 26f3e1c19..de3e9e0df 100644
--- a/main/threadstorage.c
+++ b/main/threadstorage.c
@@ -104,15 +104,30 @@ void __ast_threadstorage_object_replace(void *key_old, void *key_new, size_t len
AST_RWLIST_UNLOCK(&tls_objects);
}
-static int handle_show_allocations(int fd, int argc, char *argv[])
+static char *handle_cli_threadstorage_show_allocations(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
char *fn = NULL;
size_t len = 0;
unsigned int count = 0;
struct tls_object *to;
- if (argc > 3)
- fn = argv[3];
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "threadstorage show allocations";
+ e->usage =
+ "Usage: threadstorage show allocations [<file>]\n"
+ " Dumps a list of all thread-specific memory allocations,\n"
+ " optionally limited to those from a specific file\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+
+ if (a->argc > 4)
+ return CLI_SHOWUSAGE;
+
+ if (a->argc > 3)
+ fn = a->argv[3];
AST_RWLIST_RDLOCK(&tls_objects);
@@ -120,7 +135,7 @@ static int handle_show_allocations(int fd, int argc, char *argv[])
if (fn && strcasecmp(to->file, fn))
continue;
- ast_cli(fd, "%10d bytes allocated in %20s at line %5d of %25s (thread %p)\n",
+ ast_cli(a->fd, "%10d bytes allocated in %20s at line %5d of %25s (thread %p)\n",
(int) to->size, to->function, to->line, to->file, (void *) to->thread);
len += to->size;
count++;
@@ -128,12 +143,12 @@ static int handle_show_allocations(int fd, int argc, char *argv[])
AST_RWLIST_UNLOCK(&tls_objects);
- ast_cli(fd, "%10d bytes allocated in %d allocation%s\n", (int) len, count, count > 1 ? "s" : "");
+ ast_cli(a->fd, "%10d bytes allocated in %d allocation%s\n", (int) len, count, count > 1 ? "s" : "");
- return RESULT_SUCCESS;
+ return CLI_SUCCESS;
}
-static int handle_show_summary(int fd, int argc, char *argv[])
+static char *handle_cli_threadstorage_show_summary(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
char *fn = NULL;
size_t len = 0;
@@ -145,10 +160,26 @@ static int handle_show_summary(int fd, int argc, char *argv[])
unsigned int count;
AST_LIST_ENTRY(file) entry;
} *file;
+
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "threadstorage show summary";
+ e->usage =
+ "Usage: threadstorage show summary [<file>]\n"
+ " Summarizes thread-specific memory allocations by file, or optionally\n"
+ " by function, if a file is specified\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+
+ if (a->argc > 4)
+ return CLI_SHOWUSAGE;
+
AST_LIST_HEAD_NOLOCK_STATIC(file_summary, file);
- if (argc > 3)
- fn = argv[3];
+ if (a->argc > 3)
+ fn = a->argv[3];
AST_RWLIST_RDLOCK(&tls_objects);
@@ -178,38 +209,22 @@ static int handle_show_summary(int fd, int argc, char *argv[])
len += file->len;
count += file->count;
if (fn) {
- ast_cli(fd, "%10d bytes in %d allocation%ss in function %s\n",
+ ast_cli(a->fd, "%10d bytes in %d allocation%ss in function %s\n",
(int) file->len, file->count, file->count > 1 ? "s" : "", file->name);
} else {
- ast_cli(fd, "%10d bytes in %d allocation%s in file %s\n",
+ ast_cli(a->fd, "%10d bytes in %d allocation%s in file %s\n",
(int) file->len, file->count, file->count > 1 ? "s" : "", file->name);
}
}
- ast_cli(fd, "%10d bytes allocated in %d allocation%s\n", (int) len, count, count > 1 ? "s" : "");
-
- return RESULT_SUCCESS;
+ ast_cli(a->fd, "%10d bytes allocated in %d allocation%s\n", (int) len, count, count > 1 ? "s" : "");
+
+ return CLI_SUCCESS;
}
static struct ast_cli_entry cli[] = {
- {
- .cmda = { "threadstorage", "show", "allocations", NULL },
- .handler = handle_show_allocations,
- .summary = "Display outstanding thread local storage allocations",
- .usage =
- "Usage: threadstorage show allocations [<file>]\n"
- " Dumps a list of all thread-specific memory allocations,\n"
- "optionally limited to those from a specific file\n",
- },
- {
- .cmda = { "threadstorage", "show", "summary", NULL },
- .handler = handle_show_summary,
- .summary = "Summarize outstanding memory allocations",
- .usage =
- "Usage: threadstorage show summary [<file>]\n"
- " Summarizes thread-specific memory allocations by file, or optionally\n"
- "by function, if a file is specified\n",
- },
+ NEW_CLI(handle_cli_threadstorage_show_allocations, "Display outstanding thread local storage allocations"),
+ NEW_CLI(handle_cli_threadstorage_show_summary, "Summarize outstanding memory allocations")
};
void threadstorage_init(void)