]> git.itanic.dy.fi Git - scan-pagemap/commitdiff
Print verbose output during operation
authorTimo Kokkonen <kaapeli@itanic.dy.fi>
Sun, 2 Oct 2011 09:10:38 +0000 (12:10 +0300)
committerTimo Kokkonen <kaapeli@itanic.dy.fi>
Sun, 2 Oct 2011 14:54:32 +0000 (17:54 +0300)
Sometimes (especially with slower computers with a lot of memory, or
just computers with *a lot* of memory) it can take quite a while until
all the processing is done. Print brief status notes to the user
stating which pid's data we are now processing. This allows the user
to know how far we are going.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
analyze.c
main.c
parse.c

index 4c1b542df0ba4609e6ea4445555fbc191d8db150..57d08694d2fcac4b9011a602797c049b40b36f49 100644 (file)
--- a/analyze.c
+++ b/analyze.c
@@ -179,6 +179,8 @@ void print_page_stats(struct pageframe *pf)
 
        count = bintree_walk(&pf->tree, &af.ops);
 
 
        count = bintree_walk(&pf->tree, &af.ops);
 
+       printf("\n");
+
        for (i = 0; i < KPAGEFLAGS_NUM; i++) {
                if (!af.kpageflag[i])
                        continue;
        for (i = 0; i < KPAGEFLAGS_NUM; i++) {
                if (!af.kpageflag[i])
                        continue;
@@ -216,12 +218,19 @@ void print_pid_stats(struct pageframe *pf, struct process *process_list,
        long int swapped, present, unique, total;
        long int biggest = 0, second_biggest;
        int count, processes = 0;
        long int swapped, present, unique, total;
        long int biggest = 0, second_biggest;
        int count, processes = 0;
+       int len = 0, i;
 
        /*
         * walk through all processes, find the one with most present
         * pages
         */
 
        /*
         * walk through all processes, find the one with most present
         * pages
         */
+       printf("\rAnalyzing pages for process: ");
        list_for_each_entry(ps, &process_list->list, list) {
        list_for_each_entry(ps, &process_list->list, list) {
+               for (i = 0; i < len; i++)
+                       putchar('\b');
+               len =  printf("% 5d", ps->pid);
+               fflush(stdout);
+
                memset(&af, 0, sizeof(af));
                af.ops.callback = count_pages;
                af.pid = ps->pid;
                memset(&af, 0, sizeof(af));
                af.ops.callback = count_pages;
                af.pid = ps->pid;
@@ -232,6 +241,9 @@ void print_pid_stats(struct pageframe *pf, struct process *process_list,
                ps->pages_unique  = af.pages_unique;
                biggest = MAX(biggest, ps->pages_present + ps->pages_swapped);
        }
                ps->pages_unique  = af.pages_unique;
                biggest = MAX(biggest, ps->pages_present + ps->pages_swapped);
        }
+       for (i = 0; i < len; i++)
+               putchar('\b');
+       printf("Done  \n\n");
 
        printf("     RSS  swapped      USS    total   pid");
        if (opts->with_threads)
 
        printf("     RSS  swapped      USS    total   pid");
        if (opts->with_threads)
diff --git a/main.c b/main.c
index 10f1a9eb5c21e1ad4b5ee690b400a52ceffd1ce9..2142e5a3292af8e96b681411ccadd0cb46e02786 100644 (file)
--- a/main.c
+++ b/main.c
@@ -172,11 +172,15 @@ int main(int argc, char *argv[])
        memset(&process_list, 0, sizeof(process_list));
        INIT_LIST_HEAD(&process_list.list);
 
        memset(&process_list, 0, sizeof(process_list));
        INIT_LIST_HEAD(&process_list.list);
 
+       printf("Scanning all process IDs\n");
+
        if (scan_all_pids(&pf, &process_list, &opts))
                return 1;
 
        if (scan_all_pids(&pf, &process_list, &opts))
                return 1;
 
+       printf("Updating kpageflags\n");
        update_kpageflags(&pf);
 
        update_kpageflags(&pf);
 
+       printf("Preparing to print out results\n");
        if (opts.parse_mask & PARSE_DUMP)
                dump_process_maps(&pf, &process_list, &opts);
        else
        if (opts.parse_mask & PARSE_DUMP)
                dump_process_maps(&pf, &process_list, &opts);
        else
diff --git a/parse.c b/parse.c
index 5f3196c50cbfe1b242b2b0d846184c2a25b91d97..5e29ea576d730d9d49c5a3e5940ec72505be15b5 100644 (file)
--- a/parse.c
+++ b/parse.c
@@ -379,6 +379,7 @@ int scan_all_pids(struct pageframe *pf, struct process *process_list,
        DIR *dir = NULL;
        int pid;
        int count = 0;
        DIR *dir = NULL;
        int pid;
        int count = 0;
+       int len = 0, i;
 
        if (is_parse_option(opts, PARSE_PID)) {
                list_for_each_entry_safe(pidlist, n, &opts->pidlist, list) {
 
        if (is_parse_option(opts, PARSE_PID)) {
                list_for_each_entry_safe(pidlist, n, &opts->pidlist, list) {
@@ -398,23 +399,45 @@ int scan_all_pids(struct pageframe *pf, struct process *process_list,
 
        if (is_parse_option(opts, PARSE_MAP_NAME) &&
                !is_parse_option(opts, PARSE_PID)) {
 
        if (is_parse_option(opts, PARSE_MAP_NAME) &&
                !is_parse_option(opts, PARSE_PID)) {
+               printf("Scanning page mappings for process: ");
                while (1) {
                        pid = get_next_pid(&dir);
                        if (pid <= 0)
                                break;
                while (1) {
                        pid = get_next_pid(&dir);
                        if (pid <= 0)
                                break;
+
+                       for (i = 0; i < len; i++)
+                               putchar('\b');
+                       len = printf("% 5d", pid);
+                       fflush(stdout);
+
                        read_pageframe_with_threads(pid, pf, process_list,
                                                opts);
                }
                        read_pageframe_with_threads(pid, pf, process_list,
                                                opts);
                }
+
+               for (i = 0; i < len; i++)
+                       putchar('\b');
+               printf("Done  \n");
+               len = 0;
        }
        /* Do not add new pages in the tree after the initial scan */
        opts->parse_mask |= PARSE_NOADD_TREE;
 
        }
        /* Do not add new pages in the tree after the initial scan */
        opts->parse_mask |= PARSE_NOADD_TREE;
 
+       printf("Scanning page mappings for process: ");
        while (1) {
                pid = get_next_pid(&dir);
                if (pid <= 0)
                        break;
        while (1) {
                pid = get_next_pid(&dir);
                if (pid <= 0)
                        break;
+
+               for (i = 0; i < len; i++)
+                       putchar('\b');
+               len = printf("% 5d", pid);
+               fflush(stdout);
+
                read_pageframe_with_threads(pid, pf, process_list, opts);
        }
                read_pageframe_with_threads(pid, pf, process_list, opts);
        }
+       for (i = 0; i < len; i++)
+               putchar('\b');
+       printf("Done  \n");
 
        return 0;
 }
 
        return 0;
 }