From: Julien Desfossez Date: Fri, 16 Mar 2012 19:01:09 +0000 (-0400) Subject: Reactivate header counters X-Git-Tag: v0.2~50 X-Git-Url: https://git.lttng.org/?p=lttngtop.git;a=commitdiff_plain;h=e05a35a69ff03f10bba459a07dc26684049f1bc9 Reactivate header counters This commit reenables the header counters where we display the amount of processes and files open. Signed-off-by: Julien Desfossez --- diff --git a/src/common.c b/src/common.c index 7c67264..c01aee2 100644 --- a/src/common.c +++ b/src/common.c @@ -135,6 +135,9 @@ struct processtop* add_proc(struct lttngtop *ctx, int tid, char *comm, newproc->threads = g_ptr_array_new(); newproc->perf = g_hash_table_new(g_str_hash, g_str_equal); g_ptr_array_add(ctx->process_table, newproc); + + ctx->nbnewthreads++; + ctx->nbthreads++; } newproc->comm = strdup(comm); @@ -165,8 +168,11 @@ void death_proc(struct lttngtop *ctx, int tid, char *comm, { struct processtop *tmp; tmp = find_process_tid(ctx, tid, comm); - if (tmp && strcmp(tmp->comm, comm) == 0) + if (tmp && strcmp(tmp->comm, comm) == 0) { tmp->death = timestamp; + ctx->nbdeadthreads++; + ctx->nbthreads--; + } } struct processtop* get_proc(struct lttngtop *ctx, int tid, char *comm, @@ -297,6 +303,30 @@ void cleanup_processtop() } } +void reset_global_counters() +{ + lttngtop.nbnewproc = 0; + lttngtop.nbdeadproc = 0; + lttngtop.nbnewthreads = 0; + lttngtop.nbdeadthreads = 0; + lttngtop.nbnewfiles = 0; + lttngtop.nbclosedfiles = 0; +} + +void copy_global_counters(struct lttngtop *dst) +{ + dst->nbproc = lttngtop.nbproc; + dst->nbnewproc = lttngtop.nbnewproc; + dst->nbdeadproc = lttngtop.nbdeadproc; + dst->nbthreads = lttngtop.nbthreads; + dst->nbnewthreads = lttngtop.nbnewthreads; + dst->nbdeadthreads = lttngtop.nbdeadthreads; + dst->nbfiles = lttngtop.nbfiles; + dst->nbnewfiles = lttngtop.nbnewfiles; + dst->nbclosedfiles = lttngtop.nbclosedfiles; + reset_global_counters(); +} + struct lttngtop* get_copy_lttngtop(unsigned long start, unsigned long end) { gint i, j; @@ -309,6 +339,7 @@ struct lttngtop* get_copy_lttngtop(unsigned long start, unsigned long end) dst = g_new0(struct lttngtop, 1); dst->start = start; dst->end = end; + copy_global_counters(dst); dst->process_table = g_ptr_array_new(); dst->files_table = g_ptr_array_new(); dst->cpu_table = g_ptr_array_new(); @@ -357,6 +388,7 @@ struct lttngtop* get_copy_lttngtop(unsigned long start, unsigned long end) * files associated with if after the copy */ if (tmp->death > 0 && tmp->death < end) { + /* FIXME : close the files before */ g_ptr_array_remove(tmp->process_files_table, tmpfile); g_free(tmpfile); } @@ -368,6 +400,7 @@ struct lttngtop* get_copy_lttngtop(unsigned long start, unsigned long end) * the current process list after the copy */ if (tmp->death > 0 && tmp->death < end) { + fprintf(stderr, "removing : %ld : %d %s\n", end, tmp->tid, tmp->comm); g_ptr_array_remove(lttngtop.process_table, tmp); /* FIXME : TRUE does not mean clears the object in it */ g_ptr_array_free(tmp->threads, TRUE); diff --git a/src/common.h b/src/common.h index 6370b77..a9befb0 100644 --- a/src/common.h +++ b/src/common.h @@ -50,6 +50,7 @@ struct perfcounter *add_perf_counter(GPtrArray *perf, GQuark quark, unsigned long count); struct perfcounter *get_perf_counter(const char *name, struct processtop *proc, struct cputime *cpu); +void reset_global_counters(void); /* common field access functions */ uint64_t get_cpu_id(const struct bt_ctf_event *event); diff --git a/src/cputop.c b/src/cputop.c index c561d47..1b9a129 100644 --- a/src/cputop.c +++ b/src/cputop.c @@ -120,7 +120,13 @@ enum bt_cb_ret handle_sched_process_free(struct bt_ctf_event *call_data, goto error; } - tid = get_context_tid(call_data); + tid = bt_ctf_get_int64(bt_ctf_get_field(call_data, + scope, "_tid")); + if (bt_ctf_field_get_error()) { + fprintf(stderr, "Missing tid field\n"); + goto error; + } + death_proc(<tngtop, tid, comm, timestamp); return BT_CB_OK; diff --git a/src/cursesdisplay.c b/src/cursesdisplay.c index 2fd6976..042d45a 100644 --- a/src/cursesdisplay.c +++ b/src/cursesdisplay.c @@ -165,7 +165,7 @@ void print_headers(int line, char *desc, int value, int first, int second) wattron(header, A_BOLD); mvwprintw(header, line, 4, "%s", desc); wattroff(header, A_BOLD); - mvwprintw(header, line, 16, "N/A", value); + mvwprintw(header, line, 16, "%d", value); wmove(header, line, 24); print_digits(header, first, second); wmove(header, line, 40); @@ -254,11 +254,9 @@ void basic_header() set_window_title(header, "Statistics for interval [gathering data...["); wattron(header, A_BOLD); mvwprintw(header, 1, 4, "CPUs"); - mvwprintw(header, 2, 4, "Processes"); - mvwprintw(header, 3, 4, "Threads"); - mvwprintw(header, 4, 4, "Files"); - mvwprintw(header, 5, 4, "Network"); - mvwprintw(header, 6, 4, "IO"); + mvwprintw(header, 2, 4, "Threads"); + mvwprintw(header, 3, 4, "Files"); + mvwprintw(header, 4, 4, "Network"); wattroff(header, A_BOLD); wrefresh(header); } @@ -281,15 +279,13 @@ void update_header() wattroff(header, A_BOLD); wprintw(header, "\t%d\t(max/cpu : %0.2f%)", data->cpu_table->len, 100.0/data->cpu_table->len); - print_headers(2, "Processes", data->nbproc, data->nbnewproc, - -1*(data->nbdeadproc)); - print_headers(3, "Threads", data->nbthreads, data->nbnewthreads, + print_headers(2, "Threads", data->nbthreads, data->nbnewthreads, -1*(data->nbdeadthreads)); - print_headers(4, "Files", data->nbfiles, data->nbnewfiles, + print_headers(3, "Files", data->nbfiles, data->nbnewfiles, -1*(data->nbclosedfiles)); - mvwprintw(header, 4, 43, "N/A kbytes/sec"); - print_headers(5, "Network", 114, 0, 0); - mvwprintw(header, 5, 43, "N/A Mbytes/sec"); + mvwprintw(header, 3, 43, "N/A kbytes/sec"); + print_headers(4, "Network", 0, 0, 0); + mvwprintw(header, 4, 43, "N/A Mbytes/sec"); wrefresh(header); } @@ -940,8 +936,8 @@ void init_ncurses() sem_init(&update_display_sem, 0, 1); init_screen(); - header = create_window(7, COLS - 1, 0, 0); - center = create_window(LINES - 7 - 7, COLS - 1, 7, 0); + header = create_window(6, COLS - 1, 0, 0); + center = create_window(LINES - 7 - 7, COLS - 1, 6, 0); status = create_window(MAX_LOG_LINES + 2, COLS - 1, LINES - 7, 0); footer = create_window(1, COLS - 1, LINES - 1, 0); diff --git a/src/iostreamtop.c b/src/iostreamtop.c index 71843cb..35a58a4 100644 --- a/src/iostreamtop.c +++ b/src/iostreamtop.c @@ -55,6 +55,8 @@ void add_file(struct processtop *proc, struct files *file, int fd) } file->fd = fd; file->flag = __NR_open; + lttngtop.nbfiles++; + lttngtop.nbnewfiles++; } /* TODO */ @@ -85,7 +87,6 @@ void insert_file(struct processtop *proc, int fd) tmp->fd = fd; add_file(proc, tmp, fd); } else { - tmp = g_ptr_array_index(proc->process_files_table, fd); if (tmp == NULL) { tmp = g_new0(struct files, 1); @@ -102,10 +103,12 @@ void close_file(struct processtop *proc, int fd) { struct files *file; - file = get_file(proc, fd); - if (file != NULL) + if (file != NULL) { file->flag = __NR_close; + lttngtop.nbfiles--; + } + lttngtop.nbclosedfiles++; } struct files *get_file(struct processtop *proc, int fd) diff --git a/src/lttngtop.c b/src/lttngtop.c index e98785a..dfa1d14 100644 --- a/src/lttngtop.c +++ b/src/lttngtop.c @@ -316,6 +316,11 @@ void init_lttngtop() sem_init(&pause_sem, 0, 1); sem_init(&end_trace_sem, 0, 0); + reset_global_counters(); + lttngtop.nbproc = 0; + lttngtop.nbthreads = 0; + lttngtop.nbfiles = 0; + lttngtop.process_table = g_ptr_array_new(); lttngtop.files_table = g_ptr_array_new(); lttngtop.cpu_table = g_ptr_array_new();