From 349463c0ca48d64fc0700ac8c6065e4d923650ed Mon Sep 17 00:00:00 2001 From: Arnaldo Carvalho de Melo Date: Sun, 24 Dec 2006 13:03:33 -0200 Subject: [PATCH] [CODIFF]: Handle new functions [acme@newtoy pahole]$ codiff build/ctracer.before build/ctracer /home/acme/pahole/ctracer.c: emit_module_preamble | -188 1 function changed, 188 bytes removed /home/acme/pahole/ctracer.c: emit_struct_defs | +74 emit_class_fwd_decl | +58 2 functions changed, 132 bytes added build/ctracer: 3 functions changed, 132 bytes added, 188 bytes removed [acme@newtoy pahole]$ Signed-off-by: Arnaldo Carvalho de Melo --- codiff.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/codiff.c b/codiff.c index 106962c..6b0d939 100644 --- a/codiff.c +++ b/codiff.c @@ -82,6 +82,13 @@ static void diff_function(const struct cu *new_cu, struct function *function) else function->cu->function_bytes_removed += -function->diff; } + } else { + const size_t len = strlen(function->name); + if (len > function->cu->max_len_changed_item) + function->cu->max_len_changed_item = len; + function->diff = -function__size(function); + ++function->cu->nr_functions_changed; + function->cu->function_bytes_removed += -function->diff; } } @@ -203,6 +210,42 @@ static int diff_function_iterator(struct function *function, void *new_cu) return 0; } +static int find_new_functions_iterator(struct function *function, void *old_cu) +{ + struct function *old_function; + + assert(function->tag.tag == DW_TAG_subprogram); + + if (function->inlined) + return 0; + + old_function = cu__find_function_by_name(old_cu, function->name); + if (old_function == NULL) { + const size_t len = strlen(function->name); + if (len > function->cu->max_len_changed_item) + function->cu->max_len_changed_item = len; + function->diff = function__size(function); + ++function->cu->nr_functions_changed; + function->cu->function_bytes_added += function->diff; + } + + return 0; +} + +static int cu_find_new_classes_iterator(struct cu *new_cu, void *old_cus) +{ + struct cu *old_cu = cus__find_cu_by_name(old_cus, new_cu->name); + + if (old_cu != NULL) { + //cu__for_each_class(new_cu, diff_class_iterator, + // old_cu, NULL); + cu__for_each_function(new_cu, find_new_functions_iterator, + old_cu, NULL); + } + + return 0; +} + static int cu_diff_iterator(struct cu *cu, void *new_cus) { struct cu *new_cu = cus__find_cu_by_name(new_cus, cu->name); @@ -385,6 +428,10 @@ static int cu_show_diffs_iterator(struct cu *cu, void *cookie) return 0; } +static int cu_show_new_classes_iterator(struct cu *cu, void *cookie) +{ +} + static void print_total_function_diff(const char *filename) { printf("\n%s:\n", filename); @@ -454,7 +501,9 @@ int main(int argc, char *argv[]) } cus__for_each_cu(old_cus, cu_diff_iterator, new_cus, NULL); + cus__for_each_cu(new_cus, cu_find_new_classes_iterator, old_cus, NULL); cus__for_each_cu(old_cus, cu_show_diffs_iterator, NULL, NULL); + cus__for_each_cu(new_cus, cu_show_diffs_iterator, NULL, NULL); if (total_cus_changed > 1) { if (show_function_diffs)