[CLASSES]: Ditch struct function->cu
Since we have it available where we need: [acme@newtoy pahole]$ codiff build/libclasses.so.orig build/libclasses.so /home/acme/pahole/classes.c: struct function | -4 1 struct changed cu__add_function | -9 cus__find_class_by_name | +14 cus__find_function_by_name | +14 lexblock__account_inline_expansions | -6 function__print | -10 5 functions changed, 28 bytes added, 25 bytes removed [acme@newtoy pahole]$ Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
This commit is contained in:
parent
bed9378b42
commit
251e3973ef
24
classes.c
24
classes.c
|
@ -450,7 +450,6 @@ static void cu__add_tag(struct cu *self, struct tag *tag)
|
|||
|
||||
static void cu__add_function(struct cu *self, struct function *function)
|
||||
{
|
||||
function->cu = self;
|
||||
list_add_tail(&function->proto.tag.node, &self->tags);
|
||||
}
|
||||
|
||||
|
@ -508,30 +507,37 @@ struct class *cu__find_class_by_name(const struct cu *self, const char *name)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
struct class *cus__find_class_by_name(const struct cus *self, const char *name)
|
||||
struct class *cus__find_class_by_name(const struct cus *self,
|
||||
struct cu **cu, const char *name)
|
||||
{
|
||||
struct cu *pos;
|
||||
|
||||
list_for_each_entry(pos, &self->cus, node) {
|
||||
struct class *class = cu__find_class_by_name(pos, name);
|
||||
|
||||
if (class != NULL)
|
||||
if (class != NULL) {
|
||||
if (cu != NULL)
|
||||
*cu = pos;
|
||||
return class;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct function *cus__find_function_by_name(const struct cus *self,
|
||||
const char *name)
|
||||
struct cu **cu, const char *name)
|
||||
{
|
||||
struct cu *pos;
|
||||
|
||||
list_for_each_entry(pos, &self->cus, node) {
|
||||
struct function *function = cu__find_function_by_name(pos, name);
|
||||
|
||||
if (function != NULL)
|
||||
if (function != NULL) {
|
||||
if (cu != NULL)
|
||||
*cu = pos;
|
||||
return function;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
@ -1500,8 +1506,8 @@ size_t ftype__snprintf(const struct ftype *self, const struct cu *cu,
|
|||
return len - (l - n);
|
||||
}
|
||||
|
||||
void function__print(const struct function *self, int show_stats,
|
||||
const int show_variables,
|
||||
void function__print(const struct function *self, const struct cu *cu,
|
||||
int show_stats, const int show_variables,
|
||||
const int show_inline_expansions)
|
||||
{
|
||||
char bf[2048];
|
||||
|
@ -1511,13 +1517,13 @@ void function__print(const struct function *self, int show_stats,
|
|||
printf("/* %s:%u */\n", self->proto.tag.decl_file,
|
||||
self->proto.tag.decl_line);
|
||||
|
||||
ftype__snprintf(&self->proto, self->cu, bf, sizeof(bf),
|
||||
ftype__snprintf(&self->proto, cu, bf, sizeof(bf),
|
||||
self->name, function__declared_inline(self), 0, 0);
|
||||
fputs(bf, stdout);
|
||||
|
||||
if (show_variables || show_inline_expansions) {
|
||||
putchar('\n');
|
||||
lexblock__print(&self->lexblock, self->cu, 0);
|
||||
lexblock__print(&self->lexblock, cu, 0);
|
||||
} else
|
||||
puts(";");
|
||||
|
||||
|
|
10
classes.h
10
classes.h
|
@ -147,7 +147,6 @@ static inline struct ftype *tag__ftype(const struct tag *self)
|
|||
|
||||
struct function {
|
||||
struct ftype proto;
|
||||
struct cu *cu;
|
||||
struct lexblock lexblock;
|
||||
const char *name;
|
||||
size_t cu_total_size_inline_expansions;
|
||||
|
@ -212,7 +211,8 @@ struct enumerator {
|
|||
extern void class__find_holes(struct class *self);
|
||||
extern void tag__print(const struct tag *self, const struct cu *cu,
|
||||
const char *prefix, const char *suffix);
|
||||
extern void function__print(const struct function *self, const int show_stats,
|
||||
extern void function__print(const struct function *self, const struct cu *cu,
|
||||
const int show_stats,
|
||||
const int show_variables,
|
||||
const int show_inline_expansions);
|
||||
|
||||
|
@ -223,7 +223,11 @@ extern int cus__load_dir(struct cus *self, const char *dirname,
|
|||
const char *filename_mask, const int recursive);
|
||||
extern struct cu *cus__find_cu_by_name(const struct cus *self,
|
||||
const char *name);
|
||||
extern struct class *cus__find_class_by_name(const struct cus *self,
|
||||
struct cu **cu,
|
||||
const char *name);
|
||||
extern struct function *cus__find_function_by_name(const struct cus *self,
|
||||
struct cu **cu,
|
||||
const char *name);
|
||||
extern int cus__emit_ftype_definitions(struct cus *self, struct cu *cu,
|
||||
struct ftype *ftype);
|
||||
|
@ -238,8 +242,6 @@ extern struct class *cu__find_class_by_name(const struct cu *cu,
|
|||
const char *name);
|
||||
extern int tag__is_struct(const struct tag *self, struct tag **typedef_alias,
|
||||
const struct cu *cu);
|
||||
extern struct class *cus__find_class_by_name(const struct cus *self,
|
||||
const char *name);
|
||||
extern void cu__account_inline_expansions(struct cu *self);
|
||||
extern int cu__for_each_tag(struct cu *self,
|
||||
int (*iterator)(struct tag *tag,
|
||||
|
|
39
codiff.c
39
codiff.c
|
@ -57,7 +57,8 @@ static void usage(void)
|
|||
" without options all diffs are shown\n");
|
||||
}
|
||||
|
||||
static void diff_function(const struct cu *new_cu, struct function *function)
|
||||
static void diff_function(const struct cu *new_cu, struct function *function,
|
||||
struct cu *cu)
|
||||
{
|
||||
struct function *new_function;
|
||||
|
||||
|
@ -73,22 +74,22 @@ static void diff_function(const struct cu *new_cu, struct function *function)
|
|||
if (function->diff != 0) {
|
||||
const size_t len = strlen(function->name);
|
||||
|
||||
if (len > function->cu->max_len_changed_item)
|
||||
function->cu->max_len_changed_item = len;
|
||||
if (len > cu->max_len_changed_item)
|
||||
cu->max_len_changed_item = len;
|
||||
|
||||
++function->cu->nr_functions_changed;
|
||||
++cu->nr_functions_changed;
|
||||
if (function->diff > 0)
|
||||
function->cu->function_bytes_added += function->diff;
|
||||
cu->function_bytes_added += function->diff;
|
||||
else
|
||||
function->cu->function_bytes_removed += -function->diff;
|
||||
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;
|
||||
if (len > cu->max_len_changed_item)
|
||||
cu->max_len_changed_item = len;
|
||||
function->diff = -function__size(function);
|
||||
++function->cu->nr_functions_changed;
|
||||
function->cu->function_bytes_removed += -function->diff;
|
||||
++cu->nr_functions_changed;
|
||||
cu->function_bytes_removed += -function->diff;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -222,7 +223,7 @@ static int diff_tag_iterator(struct tag *tag, struct cu *cu, void *new_cu)
|
|||
if (tag->tag == DW_TAG_structure_type)
|
||||
diff_struct(new_cu, tag__class(tag));
|
||||
else if (tag->tag == DW_TAG_subprogram)
|
||||
diff_function(new_cu, tag__function(tag));
|
||||
diff_function(new_cu, tag__function(tag), cu);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -241,11 +242,11 @@ static int find_new_functions_iterator(struct tag *tfunction, struct cu *cu,
|
|||
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;
|
||||
if (len > cu->max_len_changed_item)
|
||||
cu->max_len_changed_item = len;
|
||||
function->diff = function__size(function);
|
||||
++function->cu->nr_functions_changed;
|
||||
function->cu->function_bytes_added += function->diff;
|
||||
++cu->nr_functions_changed;
|
||||
cu->function_bytes_added += function->diff;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -307,11 +308,11 @@ static int cu_diff_iterator(struct cu *cu, void *new_cus)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void show_diffs_function(const struct function *function)
|
||||
static void show_diffs_function(const struct function *function,
|
||||
const struct cu *cu)
|
||||
{
|
||||
printf(" %-*.*s | %+4d\n",
|
||||
function->cu->max_len_changed_item,
|
||||
function->cu->max_len_changed_item,
|
||||
cu->max_len_changed_item, cu->max_len_changed_item,
|
||||
function->name, function->diff);
|
||||
}
|
||||
|
||||
|
@ -423,7 +424,7 @@ static int show_function_diffs_iterator(struct tag *tag, struct cu *cu,
|
|||
struct function *function = tag__function(tag);
|
||||
|
||||
if (tag->tag == DW_TAG_subprogram && function->diff != 0)
|
||||
show_diffs_function(function);
|
||||
show_diffs_function(function, cu);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
28
ctracer.c
28
ctracer.c
|
@ -61,6 +61,7 @@ static int cu_find_methods_iterator(struct cu *cu, void *cookie)
|
|||
}
|
||||
|
||||
static int function__emit_kprobes(const struct function *self,
|
||||
const struct cu *cu,
|
||||
const struct tag *target)
|
||||
{
|
||||
char bf[128];
|
||||
|
@ -68,8 +69,8 @@ static int function__emit_kprobes(const struct function *self,
|
|||
char body[bodyl], *bodyp = body;
|
||||
char class_name[128], parm_name[256];
|
||||
struct parameter *pos;
|
||||
struct tag *type = cu__find_tag_by_id(self->cu, self->proto.tag.type);
|
||||
const char *stype = tag__name(type, self->cu, bf, sizeof(bf));
|
||||
struct tag *type = cu__find_tag_by_id(cu, self->proto.tag.type);
|
||||
const char *stype = tag__name(type, cu, bf, sizeof(bf));
|
||||
int first = 1;
|
||||
|
||||
body[0] = '\0';
|
||||
|
@ -77,8 +78,8 @@ static int function__emit_kprobes(const struct function *self,
|
|||
printf("static %s jprobe_entry__%s(", stype, self->name);
|
||||
|
||||
list_for_each_entry(pos, &self->proto.parms, tag.node) {
|
||||
type = cu__find_tag_by_id(self->cu, pos->tag.type);
|
||||
parameter__names(pos, self->cu, class_name, sizeof(class_name),
|
||||
type = cu__find_tag_by_id(cu, pos->tag.type);
|
||||
parameter__names(pos, cu, class_name, sizeof(class_name),
|
||||
parm_name, sizeof(parm_name));
|
||||
|
||||
if (!first)
|
||||
|
@ -91,7 +92,7 @@ static int function__emit_kprobes(const struct function *self,
|
|||
if (type->tag != DW_TAG_pointer_type)
|
||||
continue;
|
||||
|
||||
type = cu__find_tag_by_id(self->cu, type->type);
|
||||
type = cu__find_tag_by_id(cu, type->type);
|
||||
if (type == NULL || type->id != target->id)
|
||||
continue;
|
||||
|
||||
|
@ -116,8 +117,8 @@ static int cu_emit_kprobes_iterator(struct cu *cu, void *cookie)
|
|||
struct function *pos;
|
||||
|
||||
list_for_each_entry(pos, &cu->tool_list, tool_node) {
|
||||
cus__emit_ftype_definitions(cus, pos->cu, &pos->proto);
|
||||
function__emit_kprobes(pos, &target->tag);
|
||||
cus__emit_ftype_definitions(cus, cu, &pos->proto);
|
||||
function__emit_kprobes(pos, cu, &target->tag);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -170,25 +171,28 @@ static int cu_emit_kretprobes_table_iterator(struct cu *cu, void *cookie)
|
|||
|
||||
static void emit_function_defs(const char *fn)
|
||||
{
|
||||
struct function *f = cus__find_function_by_name(kprobes_cus, fn);
|
||||
struct cu *cu;
|
||||
struct function *f = cus__find_function_by_name(kprobes_cus, &cu, fn);
|
||||
|
||||
if (f != NULL) {
|
||||
cus__emit_ftype_definitions(kprobes_cus, f->cu, &f->proto);
|
||||
function__print(f, 0, 0, 0);
|
||||
cus__emit_ftype_definitions(kprobes_cus, cu, &f->proto);
|
||||
function__print(f, cu, 0, 0, 0);
|
||||
putchar('\n');
|
||||
}
|
||||
}
|
||||
|
||||
static void emit_struct_defs(const char *name)
|
||||
{
|
||||
struct class *c = cus__find_class_by_name(kprobes_cus, name);
|
||||
struct cu *cu;
|
||||
struct class *c = cus__find_class_by_name(kprobes_cus, &cu, name);
|
||||
if (c != NULL)
|
||||
cus__emit_struct_definitions(kprobes_cus, c, NULL, NULL);
|
||||
}
|
||||
|
||||
static void emit_class_fwd_decl(const char *name)
|
||||
{
|
||||
struct class *c = cus__find_class_by_name(kprobes_cus, name);
|
||||
struct cu *cu;
|
||||
struct class *c = cus__find_class_by_name(kprobes_cus, &cu, name);
|
||||
if (c != NULL)
|
||||
cus__emit_fwd_decl(kprobes_cus, c);
|
||||
}
|
||||
|
|
40
pfunct.c
40
pfunct.c
|
@ -25,17 +25,20 @@ static int show_cc_uninlined;
|
|||
struct fn_stats {
|
||||
struct list_head node;
|
||||
const struct function *function;
|
||||
const struct cu *cu;
|
||||
uint32_t nr_expansions;
|
||||
uint32_t size_expansions;
|
||||
uint32_t nr_files;
|
||||
};
|
||||
|
||||
static struct fn_stats *fn_stats__new(const struct function *function)
|
||||
static struct fn_stats *fn_stats__new(const struct function *function,
|
||||
const struct cu *cu)
|
||||
{
|
||||
struct fn_stats *self = malloc(sizeof(*self));
|
||||
|
||||
if (self != NULL) {
|
||||
self->function = function;
|
||||
self->cu = cu;
|
||||
self->nr_files = 1;
|
||||
self->nr_expansions = function->cu_total_nr_inline_expansions;
|
||||
self->size_expansions = function->cu_total_size_inline_expansions;
|
||||
|
@ -56,9 +59,9 @@ static struct fn_stats *fn_stats__find(const char *name)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static void fn_stats__add(const struct function *function)
|
||||
static void fn_stats__add(const struct function *function, const struct cu *cu)
|
||||
{
|
||||
struct fn_stats *inl = fn_stats__new(function);
|
||||
struct fn_stats *inl = fn_stats__new(function, cu);
|
||||
if (inl != NULL)
|
||||
list_add(&inl->node, &fn_stats__list);
|
||||
}
|
||||
|
@ -106,7 +109,8 @@ static void fn_stats_size_fmtr(const struct fn_stats *self)
|
|||
static void fn_stats_fmtr(const struct fn_stats *self)
|
||||
{
|
||||
if (verbose) {
|
||||
function__print(self->function, 1, show_variables, show_inline_expansions);
|
||||
function__print(self->function, self->cu, 1,
|
||||
show_variables, show_inline_expansions);
|
||||
printf("/* definitions: %u */\n", self->nr_files);
|
||||
putchar('\n');
|
||||
} else
|
||||
|
@ -138,14 +142,16 @@ static void print_total_inline_stats(void)
|
|||
}
|
||||
|
||||
static void fn_stats__dupmsg(const struct function *self,
|
||||
const struct function *dup, char *hdr,
|
||||
const char *fmt, ...)
|
||||
const struct cu *self_cu,
|
||||
const struct function *dup,
|
||||
const struct cu *dup_cu,
|
||||
char *hdr, const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
if (!*hdr)
|
||||
printf("function: %s\nfirst: %s\ncurrent: %s\n",
|
||||
self->name, self->cu->name, dup->cu->name);
|
||||
self->name, self_cu->name, dup_cu->name);
|
||||
|
||||
va_start(args, fmt);
|
||||
vprintf(fmt, args);
|
||||
|
@ -154,18 +160,22 @@ static void fn_stats__dupmsg(const struct function *self,
|
|||
}
|
||||
|
||||
static void fn_stats__chkdupdef(const struct function *self,
|
||||
const struct function *dup)
|
||||
const struct cu *self_cu,
|
||||
const struct function *dup,
|
||||
const struct cu *dup_cu)
|
||||
{
|
||||
char hdr = 0;
|
||||
const size_t self_size = function__size(self);
|
||||
const size_t dup_size = function__size(dup);
|
||||
|
||||
if (self_size != dup_size)
|
||||
fn_stats__dupmsg(self, dup, &hdr, "size: %zd != %zd\n",
|
||||
self_size, dup_size);
|
||||
fn_stats__dupmsg(self, self_cu, dup, dup_cu,
|
||||
&hdr, "size: %zd != %zd\n",
|
||||
self_size, dup_size);
|
||||
|
||||
if (self->proto.nr_parms != dup->proto.nr_parms)
|
||||
fn_stats__dupmsg(self, dup, &hdr, "nr_parms: %u != %u\n",
|
||||
fn_stats__dupmsg(self, self_cu, dup, dup_cu,
|
||||
&hdr, "nr_parms: %u != %u\n",
|
||||
self->proto.nr_parms, dup->proto.nr_parms);
|
||||
|
||||
/* XXX put more checks here: member types, member ordering, etc */
|
||||
|
@ -199,7 +209,7 @@ static struct tag *function__filter(struct tag *tag, struct cu *cu,
|
|||
|
||||
fstats = fn_stats__find(function->name);
|
||||
if (fstats != NULL && fstats->function->external) {
|
||||
fn_stats__chkdupdef(fstats->function, function);
|
||||
fn_stats__chkdupdef(fstats->function, fstats->cu, function, cu);
|
||||
fstats->nr_expansions += function->cu_total_nr_inline_expansions;
|
||||
fstats->size_expansions += function->cu_total_size_inline_expansions;
|
||||
fstats->nr_files++;
|
||||
|
@ -212,7 +222,7 @@ static struct tag *function__filter(struct tag *tag, struct cu *cu,
|
|||
static int unique_iterator(struct tag *tag, struct cu *cu, void *cookie)
|
||||
{
|
||||
if (tag->tag == DW_TAG_subprogram)
|
||||
fn_stats__add(tag__function(tag));
|
||||
fn_stats__add(tag__function(tag), cu);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -235,7 +245,7 @@ static int class_iterator(struct tag *tag, struct cu *cu, void *cookie)
|
|||
|
||||
if (ftype__has_parm_of_type(&function->proto, cookie, cu)) {
|
||||
if (verbose)
|
||||
function__print(function, 1, 0, 0);
|
||||
function__print(function, cu, 1, 0, 0);
|
||||
else
|
||||
printf("%s\n", function->name ?: "");
|
||||
}
|
||||
|
@ -262,7 +272,7 @@ static int function_iterator(struct tag *tag, struct cu *cu, void *cookie)
|
|||
function = tag__function(tag);
|
||||
if (function->name != NULL &&
|
||||
strcmp(function->name, cookie) == 0) {
|
||||
function__print(function, 1, show_variables,
|
||||
function__print(function, cu, 1, show_variables,
|
||||
show_inline_expansions);
|
||||
return 1;
|
||||
}
|
||||
|
|
20
prefcnt.c
20
prefcnt.c
|
@ -86,7 +86,7 @@ static void refcnt_tag(struct tag *tag)
|
|||
refcnt_member(member);
|
||||
}
|
||||
|
||||
static void refcnt_function(struct function *function)
|
||||
static void refcnt_function(struct function *function, const struct cu *cu)
|
||||
{
|
||||
struct parameter *parameter;
|
||||
struct tag *pos;
|
||||
|
@ -94,30 +94,30 @@ static void refcnt_function(struct function *function)
|
|||
function->proto.tag.refcnt++;
|
||||
|
||||
if (function->proto.tag.type != 0) /* if not void */ {
|
||||
struct tag *type = cu__find_tag_by_id(function->cu,
|
||||
function->proto.tag.type);
|
||||
struct tag *type =
|
||||
cu__find_tag_by_id(cu, function->proto.tag.type);
|
||||
if (type != NULL)
|
||||
refcnt_tag(type);
|
||||
}
|
||||
|
||||
list_for_each_entry(parameter, &function->proto.parms, tag.node)
|
||||
refcnt_parameter(parameter, function->cu);
|
||||
refcnt_parameter(parameter, cu);
|
||||
|
||||
list_for_each_entry(pos, &function->lexblock.tags, node)
|
||||
switch (pos->tag) {
|
||||
case DW_TAG_variable:
|
||||
refcnt_variable(tag__variable(pos), function->cu);
|
||||
refcnt_variable(tag__variable(pos), cu);
|
||||
break;
|
||||
case DW_TAG_inlined_subroutine:
|
||||
refcnt_inline_expansion(tag__inline_expansion(pos),
|
||||
function->cu);
|
||||
refcnt_inline_expansion(tag__inline_expansion(pos), cu);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static int refcnt_function_iterator(struct function *function, void *cookie)
|
||||
static int refcnt_function_iterator(struct function *function,
|
||||
const struct cu *cu, void *cookie)
|
||||
{
|
||||
refcnt_function(function);
|
||||
refcnt_function(function, cu);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -126,7 +126,7 @@ static int refcnt_tag_iterator(struct tag *tag, struct cu *cu, void *cookie)
|
|||
if (tag->tag == DW_TAG_structure_type)
|
||||
class__find_holes(tag__class(tag));
|
||||
else if (tag->tag == DW_TAG_structure_type)
|
||||
refcnt_function_iterator(tag__function(tag), cookie);
|
||||
refcnt_function_iterator(tag__function(tag), cu, cookie);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue