File: code_usage_dump.c

package info (click to toggle)
jmp 0.48-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 2,692 kB
  • ctags: 1,732
  • sloc: ansic: 13,985; sh: 8,611; makefile: 526; yacc: 318; java: 18
file content (86 lines) | stat: -rw-r--r-- 2,364 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include <stdlib.h>
#include <code_usage_dump.h>
#include <comparators.h>
#include <method.h>

static int code_usage_dump_file_counter = -1;

static method** methodlist = NULL;
static int methods_count = 0;

static void dump_method_row (method* m, FILE* f) {
    cls* c = method_get_owner (m);
    
    fprintf (f, "\"%s\", \"%s\", %li, %u\n", 
	     cls_get_name (c),
	     method_get_method_jmpname (m),
	     method_get_calls (m),
	     method_get_entered (m)
    );
}

/** Count the number of methodods that have used any time. */
static void count_methods (void* data) {
    if ((method_get_calls ((method*)data) > 0L) || 
	(method_get_entered ((method*)data) > 0)) {
        methods_count++;
    }
}

/** Add a row to the array of data. */
static void add_methods_row (void* data) {
    if ((method_get_calls ((method*)data) > 0L) || 
	(method_get_entered ((method*)data) > 0)) {
        methodlist [methods_count++] = (method*)data;
    }
}

void write_code_usage_dump ()
{
    char filename[128];
    char status[128];

    FILE* f;
    hashtab* methods;
	
    snprintf (filename, 128, "jmp_code_usage_dump-%d.txt", ++code_usage_dump_file_counter);
    f = fopen (filename, "w");

    if (f == NULL) {
        set_status (_("code usage dumped failed to open file"));
        return;
    }

    methods = get_methods();    
	
    methods_count = 0;
    jmphash_for_each ((jmphash_iter_f)count_methods, methods);
    
    methodlist = malloc (methods_count * sizeof (method*));

    if (methods_count > 0) {
        int i;
        methods_count = 0;
        jmphash_for_each ((jmphash_iter_f)add_methods_row, methods);
        qsort (methodlist, methods_count, sizeof (method*), method_compr_class);

        for (i = 0; i < methods_count; i++) { 
            dump_method_row (methodlist[i], f);
        }
    }
    free (methodlist);

    fflush (f);
    fclose (f);    

    snprintf (status, 128, _("code usage dumped to %s"), filename);
    set_status (status);
}

/* Emacs Local Variables: */
/* Emacs mode:C */
/* Emacs c-indentation-style:"gnu" */
/* Emacs c-hanging-braces-alist:((brace-list-open)(brace-entry-open)(defun-open after)(substatement-open after)(block-close . c-snug-do-while)(extern-lang-open after)) */
/* Emacs c-cleanup-list:(brace-else-brace brace-elseif-brace space-before-funcall) */
/* Emacs c-basic-offset:4 */
/* Emacs End: */