g_ptr_array_add(ctx->process_table, newproc);
g_hash_table_insert(ctx->process_hash_table,
(gpointer) (unsigned long) tid, newproc);
-
+ if (lookup_tid_list(tid)) {
+ add_filter_tid_list(tid, newproc);
+ }
ctx->nbnewthreads++;
ctx->nbthreads++;
}
free(proc->hostname);
}
proc->hostname = strdup(hostname);
+ if (lookup_hostname_list(hostname)) {
+ add_filter_tid_list(tid, proc);
+ }
}
}
return proc;
*/
g_ptr_array_add(dst->cpu_table, newcpu);
}
- for (i = 0; i < lttngtop.kprobes_table->len; i++) {
- tmpprobe = g_ptr_array_index(lttngtop.kprobes_table, i);
- newprobe = g_new0(struct kprobes, 1);
- memcpy(newprobe, tmpprobe, sizeof(struct kprobes));
- tmpprobe->count = 0;
- g_ptr_array_add(dst->kprobes_table, newprobe);
+ if (lttngtop.kprobes_table) {
+ for (i = 0; i < lttngtop.kprobes_table->len; i++) {
+ tmpprobe = g_ptr_array_index(lttngtop.kprobes_table, i);
+ newprobe = g_new0(struct kprobes, 1);
+ memcpy(newprobe, tmpprobe, sizeof(struct kprobes));
+ tmpprobe->count = 0;
+ g_ptr_array_add(dst->kprobes_table, newprobe);
+ }
}
/* FIXME : better algo */
/* create the threads index if required */
int *lookup_tid_list(int tid)
{
+ if (!tid_list)
+ return NULL;
+
return g_hash_table_lookup(tid_list, (gpointer) &tid);
}
char *lookup_hostname_list(const char *hostname)
{
- if (!hostname)
+ if (!hostname || !hostname_list)
return NULL;
return g_hash_table_lookup(hostname_list, (gpointer) hostname);
}
+
+int *lookup_filter_tid_list(int tid)
+{
+ return g_hash_table_lookup(global_filter_list, (gpointer) &tid);
+}
+
+void add_filter_tid_list(int tid, struct processtop *newproc)
+{
+ unsigned long *hash_tid;
+
+ hash_tid = malloc(sizeof(unsigned long));
+ *hash_tid = tid;
+ g_hash_table_insert(global_filter_list,
+ (gpointer) (unsigned long) hash_tid, newproc);
+}
+
+void remove_filter_tid_list(int tid)
+{
+ g_hash_table_remove(global_filter_list,
+ (gpointer) (unsigned long) &tid);
+}
int toggle_pause = -1;
int max_center_lines;
-GPtrArray *selected_processes;
pthread_t keyboard_thread;
init_pair(2, COLOR_GREEN, COLOR_BLACK); /* + */
init_pair(3, COLOR_BLACK, COLOR_WHITE); /* keys */
init_pair(4, COLOR_WHITE, COLOR_GREEN); /* keys activated */
- init_pair(5, COLOR_WHITE, COLOR_BLUE); /* select line */
- init_pair(6, COLOR_WHITE, COLOR_GREEN); /* selected process */
+ init_pair(5, COLOR_BLACK, COLOR_YELLOW); /* select line */
+ init_pair(6, COLOR_GREEN, COLOR_BLACK); /* selected process */
+ init_pair(7, COLOR_RED, COLOR_YELLOW); /* selected process + line*/
}
termtype = getenv("TERM");
if (!strcmp(termtype, "xterm") || !strcmp(termtype, "xterm-color") ||
int process_selected(struct processtop *process)
{
- int i;
- struct processtop *stored_process;
-
- for (i = 0; i < selected_processes->len; i++) {
- stored_process = g_ptr_array_index(selected_processes, i);
- if (!stored_process)
- return 0;
- if (stored_process->tid == process->tid)
- return 1;
- }
+ if (lookup_filter_tid_list(process->tid))
+ return 1;
return 0;
}
void update_selected_processes()
{
- int i;
- struct processtop *stored_process;
-
if (process_selected(selected_process)) {
- for (i = 0; i < selected_processes->len; i++) {
- stored_process = g_ptr_array_index(selected_processes, i);
- if (!stored_process)
- return;
- if (stored_process->tid == selected_process->tid)
- g_ptr_array_remove(selected_processes,
- stored_process);
- print_log("Process removed");
- }
+ remove_filter_tid_list(selected_process->tid);
} else {
- g_ptr_array_add(selected_processes, selected_process);
- print_log("Process added");
+ add_filter_tid_list(selected_process->tid, selected_process);
}
}
nblinedisplayed < max_center_lines; i++) {
tmp = g_ptr_array_index(data->process_table, i);
current_row_offset = 1;
- if (!opt_tid && (opt_hostname && !lookup_hostname_list(tmp->hostname)))
- continue;
- if (!opt_hostname && (opt_tid && !lookup_tid_list(tmp->pid)))
- continue;
- if ((opt_tid && !lookup_tid_list(tmp->tid)) &&
- (opt_hostname && !lookup_hostname_list(tmp->hostname)))
+ if (toggle_filter > 0 && !lookup_filter_tid_list(tmp->tid))
continue;
if (tmp->pid != tmp->tid)
if (toggle_threads == -1)
continue;
- if (process_selected(tmp)) {
- wattron(center, COLOR_PAIR(6));
- mvwhline(center, current_line + header_offset, 1, ' ', COLS-3);
- }
+ /* line */
if (current_line == selected_line) {
selected_process = tmp;
wattron(center, COLOR_PAIR(5));
mvwhline(center, current_line + header_offset, 1, ' ', COLS-3);
}
+ /* filtered process */
+ if (process_selected(tmp)) {
+ if (current_line == selected_line)
+ wattron(center, COLOR_PAIR(7));
+ else
+ wattron(center, COLOR_PAIR(6));
+ }
/* CPU(%) */
mvwprintw(center, current_line + header_offset,
current_row_offset, "%1.2f",
/* NAME */
mvwprintw(center, current_line + header_offset,
current_row_offset, "%s", tmp->comm);
+ wattroff(center, COLOR_PAIR(7));
wattroff(center, COLOR_PAIR(6));
wattroff(center, COLOR_PAIR(5));
nblinedisplayed++;
nblinedisplayed < max_center_lines; i++) {
tmp = g_ptr_array_index(data->process_table, i);
- if (!opt_tid && (opt_hostname && !lookup_hostname_list(tmp->hostname)))
- continue;
- if (!opt_hostname && (opt_tid && !lookup_tid_list(tmp->pid)))
- continue;
- if ((opt_tid && !lookup_tid_list(tmp->tid)) &&
- (opt_hostname && !lookup_hostname_list(tmp->hostname)))
+ if (toggle_filter > 0 && !lookup_filter_tid_list(tmp->tid))
continue;
if (tmp->pid != tmp->tid)
continue;
if (process_selected(tmp)) {
- wattron(center, COLOR_PAIR(6));
- mvwhline(center, current_line + header_offset, 1, ' ', COLS-3);
+ if (current_line == selected_line)
+ wattron(center, COLOR_PAIR(7));
+ else
+ wattron(center, COLOR_PAIR(6));
}
if (current_line == selected_line) {
selected_process = tmp;
nblinedisplayed < max_center_lines; i++) {
tmp = g_ptr_array_index(data->process_table, i);
- if (!opt_tid && (opt_hostname && !lookup_hostname_list(tmp->hostname)))
- continue;
- if (!opt_hostname && (opt_tid && !lookup_tid_list(tmp->pid)))
- continue;
- if ((opt_tid && !lookup_tid_list(tmp->tid)) &&
- (opt_hostname && !lookup_hostname_list(tmp->hostname)))
+ if (toggle_filter > 0 && !lookup_filter_tid_list(tmp->tid))
continue;
if (tmp->pid != tmp->tid)
continue;
if (process_selected(tmp)) {
- wattron(center, COLOR_PAIR(6));
- mvwhline(center, current_line + header_offset, 1, ' ', COLS-3);
+ if (current_line == selected_line)
+ wattron(center, COLOR_PAIR(7));
+ else
+ wattron(center, COLOR_PAIR(6));
}
if (current_line == selected_line) {
selected_process = tmp;
update_preference_panel(&pref_line_selected, 1, 0);
} else {
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;
+ }
update_current_view();
}
break;
/* exit keyboard thread */
pthread_exit(0);
break;
+ case 'f':
+ toggle_filter *= -1;
+ selected_line = 0;
+ if (toggle_filter > 0)
+ max_elements = g_hash_table_size(global_filter_list);
+ else
+ max_elements = data->process_table->len;
+ update_current_view();
+ break;
case 't':
toggle_threads *= -1;
update_current_view();
void init_ncurses()
{
- selected_processes = g_ptr_array_new();
sem_init(&update_display_sem, 0, 1);
init_view_headers();
init_screen();
}
hostname = get_context_hostname(call_data);
+ if (opt_tid || opt_hostname)
+ if (!lookup_filter_tid_list(pid))
+ goto end;
+
+ /*
if (!opt_tid && (opt_hostname && !lookup_hostname_list(hostname)))
goto end;
if (!opt_hostname && (opt_tid && !lookup_tid_list(pid)))
if ((opt_tid && !lookup_tid_list(pid)) &&
(opt_hostname && !lookup_hostname_list(hostname)))
goto end;
+ */
cpu_id = get_cpu_id(call_data);
procname = get_context_comm(call_data);
{
copies = g_ptr_array_new();
global_perf_liszt = g_hash_table_new(g_str_hash, g_str_equal);
+ global_filter_list = g_hash_table_new(g_str_hash, g_str_equal);
sem_init(&goodtodisplay, 0, 0);
sem_init(&goodtoupdate, 0, 1);
lttngtop.process_table = g_ptr_array_new();
lttngtop.files_table = g_ptr_array_new();
lttngtop.cpu_table = g_ptr_array_new();
+
+ toggle_filter = -1;
}
void usage(FILE *fp)
opt_child = 1;
break;
case OPT_PID:
+ toggle_filter = 1;
tid_list = g_hash_table_new(g_str_hash,
g_str_equal);
tmp_str = strtok(opt_tid, ",");
}
break;
case OPT_HOSTNAME:
+ toggle_filter = 1;
hostname_list = g_hash_table_new(g_str_hash,
g_str_equal);
tmp_str = strtok(opt_hostname, ",");
begin_pos.type = BT_SEEK_BEGIN;
iter = bt_ctf_iter_create(bt_ctx, &begin_pos, NULL);
+ /* at each event, verify the status of the process table */
+ bt_ctf_iter_add_callback(iter, 0, NULL, 0,
+ fix_process_table,
+ NULL, NULL, NULL);
if (opt_textdump) {
bt_ctf_iter_add_callback(iter, 0, NULL, 0,
print_timestamp,
bt_ctf_iter_add_callback(iter, 0, NULL, 0,
check_timestamp,
NULL, NULL, NULL);
- /* at each event, verify the status of the process table */
- bt_ctf_iter_add_callback(iter, 0, NULL, 0,
- fix_process_table,
- NULL, NULL, NULL);
/* to handle the scheduling events */
bt_ctf_iter_add_callback(iter,
g_quark_from_static_string("sched_switch"),
NULL, NULL, NULL);
/* for kprobes */
- for (i = 0; i < lttngtop.kprobes_table->len; i++) {
- kprobe = g_ptr_array_index(lttngtop.kprobes_table, i);
- bt_ctf_iter_add_callback(iter,
- g_quark_from_static_string(
- kprobe->probe_name),
- NULL, 0, handle_kprobes,
- NULL, NULL, NULL);
+ if (lttngtop.kprobes_table) {
+ for (i = 0; i < lttngtop.kprobes_table->len; i++) {
+ kprobe = g_ptr_array_index(lttngtop.kprobes_table, i);
+ bt_ctf_iter_add_callback(iter,
+ g_quark_from_static_string(
+ kprobe->probe_name),
+ NULL, 0, handle_kprobes,
+ NULL, NULL, NULL);
+ }
}
}