From: Julien Desfossez Date: Wed, 29 Aug 2012 02:04:46 +0000 (-0400) Subject: add_proc now takes hostname param X-Git-Tag: v0.3~82 X-Git-Url: http://git.liburcu.org/?p=lttngtop.git;a=commitdiff_plain;h=906c08f6245d165f7ccc3d0336714b425169d406 add_proc now takes hostname param Signed-off-by: Julien Desfossez --- diff --git a/src/common.c b/src/common.c index 500c80d..02d72bb 100644 --- a/src/common.c +++ b/src/common.c @@ -175,7 +175,7 @@ struct processtop *find_process_tid(struct lttngtop *ctx, int tid, char *comm) } struct processtop* add_proc(struct lttngtop *ctx, int tid, char *comm, - unsigned long timestamp) + unsigned long timestamp, char *hostname) { struct processtop *newproc; @@ -207,6 +207,15 @@ struct processtop* add_proc(struct lttngtop *ctx, int tid, char *comm, ctx->nbthreads++; } newproc->comm = strdup(comm); + if (hostname) { + if (newproc->hostname && strcmp(newproc->hostname, hostname) != 0) { + free(newproc->hostname); + } + newproc->hostname = strdup(hostname); + if (lookup_hostname_list(hostname)) { + add_filter_tid_list(tid, newproc); + } + } return newproc; } @@ -225,15 +234,6 @@ struct processtop* update_proc(struct processtop* proc, int pid, int tid, free(proc->comm); proc->comm = strdup(comm); } - if (hostname) { - if (proc->hostname && strcmp(proc->hostname, hostname) != 0) { - free(proc->hostname); - } - proc->hostname = strdup(hostname); - if (lookup_hostname_list(hostname)) { - add_filter_tid_list(tid, proc); - } - } } return proc; } @@ -258,23 +258,23 @@ void death_proc(struct lttngtop *ctx, int tid, char *comm, } struct processtop* get_proc(struct lttngtop *ctx, int tid, char *comm, - unsigned long timestamp) + unsigned long timestamp, char *hostname) { struct processtop *tmp; tmp = find_process_tid(ctx, tid, comm); if (tmp && strcmp(tmp->comm, comm) == 0) return tmp; - return add_proc(ctx, tid, comm, timestamp); + return add_proc(ctx, tid, comm, timestamp, hostname); } struct processtop *get_proc_pid(struct lttngtop *ctx, int tid, int pid, - unsigned long timestamp) + unsigned long timestamp, char *hostname) { struct processtop *tmp; tmp = find_process_tid(ctx, tid, NULL); if (tmp && tmp->pid == pid) return tmp; - return add_proc(ctx, tid, "Unknown", timestamp); + return add_proc(ctx, tid, "Unknown", timestamp, hostname); } void add_thread(struct processtop *parent, struct processtop *thread) @@ -620,8 +620,9 @@ enum bt_cb_ret handle_statedump_process_state(struct bt_ctf_event *call_data, } proc = find_process_tid(<tngtop, tid, procname); + /* FIXME : hostname NULL */ if (proc == NULL) - proc = add_proc(<tngtop, tid, procname, timestamp); + proc = add_proc(<tngtop, tid, procname, timestamp, NULL); update_proc(proc, pid, tid, ppid, vpid, vtid, vppid, procname, NULL); if (proc) { @@ -669,6 +670,14 @@ char *lookup_hostname_list(const char *hostname) return g_hash_table_lookup(hostname_list, (gpointer) hostname); } +void remove_hostname_list(const char *hostname) +{ + if (!hostname || !hostname_list) + return; + + g_hash_table_remove(hostname_list, (gpointer) hostname); +} + int *lookup_filter_tid_list(int tid) { return g_hash_table_lookup(global_filter_list, (gpointer) &tid); diff --git a/src/common.h b/src/common.h index 59a7a7f..e0d4f4a 100644 --- a/src/common.h +++ b/src/common.h @@ -46,16 +46,16 @@ struct lttngtop *data; struct processtop *find_process_tid(struct lttngtop *ctx, int pid, char *comm); struct processtop* add_proc(struct lttngtop *ctx, int pid, char *comm, - unsigned long timestamp); + unsigned long timestamp, char *hostname); struct processtop* update_proc(struct processtop* proc, int pid, int tid, int ppid, int vpid, int vtid, int vppid, char *comm, char *hostname); void add_thread(struct processtop *parent, struct processtop *thread); struct processtop* get_proc(struct lttngtop *ctx, int tid, char *comm, - unsigned long timestamp); + unsigned long timestamp, char *hostname); struct processtop *get_proc_pid(struct lttngtop *ctx, int tid, int pid, - unsigned long timestamp); + unsigned long timestamp, char *hostname); void death_proc(struct lttngtop *ctx, int tid, char *comm, unsigned long timestamp); @@ -87,6 +87,7 @@ struct tm format_timestamp(uint64_t timestamp); int *lookup_filter_tid_list(int tid); int *lookup_tid_list(int tid); char *lookup_hostname_list(const char *hostname); +void remove_hostname_list(const char *hostname); void add_filter_tid_list(int tid, struct processtop *newproc); void remove_filter_tid_list(int tid); diff --git a/src/cputop.c b/src/cputop.c index 2e0ccdd..7df5469 100644 --- a/src/cputop.c +++ b/src/cputop.c @@ -22,7 +22,7 @@ #include "cputop.h" void update_cputop_data(unsigned long timestamp, int64_t cpu, int prev_pid, - int next_pid, char *prev_comm, char *next_comm) + int next_pid, char *prev_comm, char *next_comm, char *hostname) { struct cputime *tmpcpu; unsigned long elapsed; @@ -39,7 +39,8 @@ void update_cputop_data(unsigned long timestamp, int64_t cpu, int prev_pid, } if (next_pid != 0) - tmpcpu->current_task = get_proc(<tngtop, next_pid, next_comm, timestamp); + tmpcpu->current_task = get_proc(<tngtop, next_pid, next_comm, + timestamp, hostname); else tmpcpu->current_task = NULL; @@ -54,6 +55,7 @@ enum bt_cb_ret handle_sched_switch(struct bt_ctf_event *call_data, uint64_t cpu_id; char *prev_comm, *next_comm; int prev_tid, next_tid; + char *hostname; timestamp = bt_ctf_get_timestamp(call_data); if (timestamp == -1ULL) @@ -88,11 +90,12 @@ enum bt_cb_ret handle_sched_switch(struct bt_ctf_event *call_data, fprintf(stderr, "Missing next_tid context info\n"); goto error; } + hostname = get_context_hostname(call_data); cpu_id = get_cpu_id(call_data); update_cputop_data(timestamp, cpu_id, prev_tid, next_tid, - prev_comm, next_comm); + prev_comm, next_comm, hostname); return BT_CB_OK; diff --git a/src/cursesdisplay.c b/src/cursesdisplay.c index 3695131..8487038 100644 --- a/src/cursesdisplay.c +++ b/src/cursesdisplay.c @@ -1494,8 +1494,6 @@ void *handle_keyboard(void *p) update_selected_processes(); if (toggle_filter > 0) { max_elements = g_hash_table_size(global_filter_list); - fprintf(stderr, "select : %d, max : %d\n", - selected_line, max_elements); if (selected_line >= max_elements) selected_line = max_elements - 1; } diff --git a/src/iostreamtop.c b/src/iostreamtop.c index d3172f0..367fdee 100644 --- a/src/iostreamtop.c +++ b/src/iostreamtop.c @@ -189,13 +189,14 @@ void show_history(struct file_history *history) } int update_iostream_ret(struct lttngtop *ctx, int tid, char *comm, - unsigned long timestamp, uint64_t cpu_id, int ret) + unsigned long timestamp, uint64_t cpu_id, int ret, + char *hostname) { struct processtop *tmp; struct files *tmpfile; int err = 0; - tmp = get_proc(ctx, tid, comm, timestamp); + tmp = get_proc(ctx, tid, comm, timestamp, hostname); if (!tmp) { err = -1; @@ -271,6 +272,7 @@ enum bt_cb_ret handle_exit_syscall(struct bt_ctf_event *call_data, char *comm; uint64_t ret, tid; uint64_t cpu_id; + char *hostname; timestamp = bt_ctf_get_timestamp(call_data); if (timestamp == -1ULL) @@ -289,13 +291,15 @@ enum bt_cb_ret handle_exit_syscall(struct bt_ctf_event *call_data, } cpu_id = get_cpu_id(call_data); + hostname = get_context_hostname(call_data); /* * if we encounter an exit_syscall and * it is not for a syscall read or write * we just abort the execution of this callback */ - if ((update_iostream_ret(<tngtop, tid, comm, timestamp, cpu_id, ret)) < 0) + if ((update_iostream_ret(<tngtop, tid, comm, timestamp, cpu_id, + ret, hostname)) < 0) return BT_CB_ERROR_CONTINUE; return BT_CB_OK; @@ -313,7 +317,7 @@ enum bt_cb_ret handle_sys_write(struct bt_ctf_event *call_data, unsigned long timestamp; uint64_t cpu_id; int64_t tid; - char *procname; + char *procname, *hostname; int fd; timestamp = bt_ctf_get_timestamp(call_data); @@ -324,6 +328,7 @@ enum bt_cb_ret handle_sys_write(struct bt_ctf_event *call_data, cpu_id = get_cpu_id(call_data); procname = get_context_comm(call_data); + hostname = get_context_hostname(call_data); scope = bt_ctf_get_top_level_scope(call_data, BT_EVENT_FIELDS); @@ -334,7 +339,7 @@ enum bt_cb_ret handle_sys_write(struct bt_ctf_event *call_data, goto error; } - tmp = get_proc(<tngtop, tid, procname, timestamp); + tmp = get_proc(<tngtop, tid, procname, timestamp, hostname); if (!tmp) goto end; @@ -359,6 +364,7 @@ enum bt_cb_ret handle_sys_read(struct bt_ctf_event *call_data, int64_t tid; char *procname; int fd; + char *hostname; timestamp = bt_ctf_get_timestamp(call_data); if (timestamp == -1ULL) @@ -368,6 +374,7 @@ enum bt_cb_ret handle_sys_read(struct bt_ctf_event *call_data, cpu_id = get_cpu_id(call_data); procname = get_context_comm(call_data); + hostname = get_context_hostname(call_data); scope = bt_ctf_get_top_level_scope(call_data, BT_EVENT_FIELDS); @@ -378,7 +385,7 @@ enum bt_cb_ret handle_sys_read(struct bt_ctf_event *call_data, goto error; } - tmp = get_proc(<tngtop, tid, procname, timestamp); + tmp = get_proc(<tngtop, tid, procname, timestamp, hostname); if (!tmp) goto end; @@ -403,7 +410,7 @@ enum bt_cb_ret handle_sys_open(struct bt_ctf_event *call_data, unsigned long timestamp; uint64_t cpu_id; int64_t tid; - char *procname; + char *procname, *hostname; char *file; timestamp = bt_ctf_get_timestamp(call_data); @@ -414,6 +421,7 @@ enum bt_cb_ret handle_sys_open(struct bt_ctf_event *call_data, cpu_id = get_cpu_id(call_data); procname = get_context_comm(call_data); + hostname = get_context_hostname(call_data); scope = bt_ctf_get_top_level_scope(call_data, BT_EVENT_FIELDS); @@ -424,7 +432,7 @@ enum bt_cb_ret handle_sys_open(struct bt_ctf_event *call_data, goto error; } - tmp = get_proc(<tngtop, tid, procname, timestamp); + tmp = get_proc(<tngtop, tid, procname, timestamp, hostname); if (!tmp) goto end; @@ -449,6 +457,7 @@ enum bt_cb_ret handle_sys_close(struct bt_ctf_event *call_data, int64_t tid; char *procname; int fd; + char *hostname; timestamp = bt_ctf_get_timestamp(call_data); if (timestamp == -1ULL) @@ -457,6 +466,7 @@ enum bt_cb_ret handle_sys_close(struct bt_ctf_event *call_data, tid = get_context_tid(call_data); procname = get_context_comm(call_data); + hostname = get_context_hostname(call_data); scope = bt_ctf_get_top_level_scope(call_data, BT_EVENT_FIELDS); @@ -467,7 +477,7 @@ enum bt_cb_ret handle_sys_close(struct bt_ctf_event *call_data, goto error; } - tmp = get_proc(<tngtop, tid, procname, timestamp); + tmp = get_proc(<tngtop, tid, procname, timestamp, hostname); if (!tmp) goto end; @@ -488,7 +498,7 @@ enum bt_cb_ret handle_statedump_file_descriptor(struct bt_ctf_event *call_data, struct files *file; unsigned long timestamp; int64_t pid; - char *file_name; + char *file_name, *hostname; int fd; timestamp = bt_ctf_get_timestamp(call_data); @@ -521,8 +531,9 @@ enum bt_cb_ret handle_statedump_file_descriptor(struct bt_ctf_event *call_data, fprintf(stderr, "Missing file name context info\n"); goto error; } + hostname = get_context_hostname(call_data); - parent = get_proc_pid(<tngtop, pid, pid, timestamp); + parent = get_proc_pid(<tngtop, pid, pid, timestamp, hostname); if (!parent) goto end; diff --git a/src/lttngtop.c b/src/lttngtop.c index 26da967..2672c8f 100644 --- a/src/lttngtop.c +++ b/src/lttngtop.c @@ -458,7 +458,7 @@ enum bt_cb_ret fix_process_table(struct bt_ctf_event *call_data, /* find or create the current process */ child = find_process_tid(<tngtop, tid, comm); if (!child) - child = add_proc(<tngtop, tid, comm, timestamp); + child = add_proc(<tngtop, tid, comm, timestamp, hostname); if (!child) goto end; update_proc(child, pid, tid, ppid, vpid, vtid, vppid, comm, hostname); @@ -467,7 +467,7 @@ enum bt_cb_ret fix_process_table(struct bt_ctf_event *call_data, /* find or create the parent */ parent = find_process_tid(<tngtop, pid, comm); if (!parent) { - parent = add_proc(<tngtop, pid, comm, timestamp); + parent = add_proc(<tngtop, pid, comm, timestamp, hostname); if (parent) parent->pid = pid; }