cregit-Linux how code gets into the kernel

Release 4.10 tools/perf/util/sort.c

Directory: tools/perf/util
#include <sys/mman.h>
#include "sort.h"
#include "hist.h"
#include "comm.h"
#include "symbol.h"
#include "evsel.h"
#include "evlist.h"
#include <traceevent/event-parse.h>
#include "mem-events.h"


regex_t		parent_regex;

const char	default_parent_pattern[] = "^sys_|^do_page_fault";

const char	*parent_pattern = default_parent_pattern;

const char	*default_sort_order = "comm,dso,symbol";

const char	default_branch_sort_order[] = "comm,dso_from,symbol_from,symbol_to,cycles";

const char	default_mem_sort_order[] = "local_weight,mem,sym,dso,symbol_daddr,dso_daddr,snoop,tlb,locked";

const char	default_top_sort_order[] = "dso,symbol";

const char	default_diff_sort_order[] = "dso,symbol";

const char	default_tracepoint_sort_order[] = "trace";

const char	*sort_order;

const char	*field_order;

regex_t		ignore_callees_regex;

int		have_ignore_callees = 0;

enum sort_mode	sort__mode = SORT_MODE__NORMAL;

/*
 * Replaces all occurrences of a char used with the:
 *
 * -t, --field-separator
 *
 * option, that uses a special separator character and don't pad with spaces,
 * replacing all occurances of this separator in symbol names (and other
 * output) with a '.' character, that thus it's the only non valid separator.
*/

static int repsep_snprintf(char *bf, size_t size, const char *fmt, ...) { int n; va_list ap; va_start(ap, fmt); n = vsnprintf(bf, size, fmt, ap); if (symbol_conf.field_sep && n > 0) { char *sep = bf; while (1) { sep = strchr(sep, *symbol_conf.field_sep); if (sep == NULL) break; *sep = '.'; } } va_end(ap); if (n >= (int)size) return size - 1; return n; }

Contributors

PersonTokensPropCommitsCommitProp
john kacurjohn kacur8674.14%125.00%
anton blanchardanton blanchard1412.07%125.00%
arnaldo carvalho de meloarnaldo carvalho de melo1210.34%125.00%
jiri olsajiri olsa43.45%125.00%
Total116100.00%4100.00%


static int64_t cmp_null(const void *l, const void *r) { if (!l && !r) return 0; else if (!l) return -1; else return 1; }

Contributors

PersonTokensPropCommitsCommitProp
frederic weisbeckerfrederic weisbecker41100.00%2100.00%
Total41100.00%2100.00%

/* --sort pid */
static int64_t sort__thread_cmp(struct hist_entry *left, struct hist_entry *right) { return right->thread->tid - left->thread->tid; }

Contributors

PersonTokensPropCommitsCommitProp
frederic weisbeckerfrederic weisbecker2793.10%150.00%
adrian hunteradrian hunter26.90%150.00%
Total29100.00%2100.00%


static int hist_entry__thread_snprintf(struct hist_entry *he, char *bf, size_t size, unsigned int width) { const char *comm = thread__comm_str(he->thread); width = max(7U, width) - 8; return repsep_snprintf(bf, size, "%7d:%-*.*s", he->thread->tid, width, width, comm ?: ""); }

Contributors

PersonTokensPropCommitsCommitProp
frederic weisbeckerfrederic weisbecker2941.43%225.00%
namhyung kimnamhyung kim1825.71%225.00%
arnaldo carvalho de meloarnaldo carvalho de melo1115.71%225.00%
john kacurjohn kacur1014.29%112.50%
jiri olsajiri olsa22.86%112.50%
Total70100.00%8100.00%


static int hist_entry__thread_filter(struct hist_entry *he, int type, const void *arg) { const struct thread *th = arg; if (type != HIST_FILTER__THREAD) return -1; return th && he->thread != th; }

Contributors

PersonTokensPropCommitsCommitProp
namhyung kimnamhyung kim46100.00%1100.00%
Total46100.00%1100.00%

struct sort_entry sort_thread = { .se_header = " Pid:Command", .se_cmp = sort__thread_cmp, .se_snprintf = hist_entry__thread_snprintf, .se_filter = hist_entry__thread_filter, .se_width_idx = HISTC_THREAD, }; /* --sort comm */
static int64_t sort__comm_cmp(struct hist_entry *left, struct hist_entry *right) { /* Compare the addr that should be unique among comm */ return strcmp(comm__str(right->comm), comm__str(left->comm)); }

Contributors

PersonTokensPropCommitsCommitProp
frederic weisbeckerfrederic weisbecker2777.14%250.00%
jiri olsajiri olsa411.43%125.00%
namhyung kimnamhyung kim411.43%125.00%
Total35100.00%4100.00%


static int64_t sort__comm_collapse(struct hist_entry *left, struct hist_entry *right) { /* Compare the addr that should be unique among comm */ return strcmp(comm__str(right->comm), comm__str(left->comm)); }

Contributors

PersonTokensPropCommitsCommitProp
frederic weisbeckerfrederic weisbecker1954.29%240.00%
namhyung kimnamhyung kim822.86%120.00%
john kacurjohn kacur411.43%120.00%
jiri olsajiri olsa411.43%120.00%
Total35100.00%5100.00%


static int64_t sort__comm_sort(struct hist_entry *left, struct hist_entry *right) { return strcmp(comm__str(right->comm), comm__str(left->comm)); }

Contributors

PersonTokensPropCommitsCommitProp
namhyung kimnamhyung kim34100.00%1100.00%
Total34100.00%1100.00%


static int hist_entry__comm_snprintf(struct hist_entry *he, char *bf, size_t size, unsigned int width) { return repsep_snprintf(bf, size, "%-*.*s", width, width, comm__str(he->comm)); }

Contributors

PersonTokensPropCommitsCommitProp
john kacurjohn kacur2046.51%116.67%
arnaldo carvalho de meloarnaldo carvalho de melo1637.21%233.33%
namhyung kimnamhyung kim511.63%233.33%
frederic weisbeckerfrederic weisbecker24.65%116.67%
Total43100.00%6100.00%

struct sort_entry sort_comm = { .se_header = "Command", .se_cmp = sort__comm_cmp, .se_collapse = sort__comm_collapse, .se_sort = sort__comm_sort, .se_snprintf = hist_entry__comm_snprintf, .se_filter = hist_entry__thread_filter, .se_width_idx = HISTC_COMM, }; /* --sort dso */
static int64_t _sort__dso_cmp(struct map *map_l, struct map *map_r) { struct dso *dso_l = map_l ? map_l->dso : NULL; struct dso *dso_r = map_r ? map_r->dso : NULL; const char *dso_name_l, *dso_name_r; if (!dso_l || !dso_r) return cmp_null(dso_r, dso_l); if (verbose) { dso_name_l = dso_l->long_name; dso_name_r = dso_r->long_name; } else { dso_name_l = dso_l->short_name; dso_name_r = dso_r->short_name; } return strcmp(dso_name_l, dso_name_r); }

Contributors

PersonTokensPropCommitsCommitProp
arnaldo carvalho de meloarnaldo carvalho de melo5147.66%120.00%
john kacurjohn kacur4441.12%120.00%
roberto agostino vitilloroberto agostino vitillo98.41%120.00%
namhyung kimnamhyung kim21.87%120.00%
frederic weisbeckerfrederic weisbecker10.93%120.00%
Total107100.00%5100.00%


static int64_t sort__dso_cmp(struct hist_entry *left, struct hist_entry *right) { return _sort__dso_cmp(right->ms.map, left->ms.map); }

Contributors

PersonTokensPropCommitsCommitProp
roberto agostino vitilloroberto agostino vitillo2578.12%125.00%
john kacurjohn kacur412.50%125.00%
namhyung kimnamhyung kim26.25%125.00%
arnaldo carvalho de meloarnaldo carvalho de melo13.12%125.00%
Total32100.00%4100.00%


static int _hist_entry__dso_snprintf(struct map *map, char *bf, size_t size, unsigned int width) { if (map && map->dso) { const char *dso_name = !verbose ? map->dso->short_name : map->dso->long_name; return repsep_snprintf(bf, size, "%-*.*s", width, width, dso_name); } return repsep_snprintf(bf, size, "%-*.*s", width, width, "[unknown]"); }

Contributors

PersonTokensPropCommitsCommitProp
arnaldo carvalho de meloarnaldo carvalho de melo4250.00%233.33%
john kacurjohn kacur2732.14%116.67%
roberto agostino vitilloroberto agostino vitillo89.52%116.67%
namhyung kimnamhyung kim67.14%116.67%
ian munsieian munsie11.19%116.67%
Total84100.00%6100.00%


static int hist_entry__dso_snprintf(struct hist_entry *he, char *bf, size_t size, unsigned int width) { return _hist_entry__dso_snprintf(he->ms.map, bf, size, width); }

Contributors

PersonTokensPropCommitsCommitProp
namhyung kimnamhyung kim1539.47%120.00%
roberto agostino vitilloroberto agostino vitillo1334.21%120.00%
john kacurjohn kacur718.42%120.00%
arnaldo carvalho de meloarnaldo carvalho de melo25.26%120.00%
anton blanchardanton blanchard12.63%120.00%
Total38100.00%5100.00%


static int hist_entry__dso_filter(struct hist_entry *he, int type, const void *arg) { const struct dso *dso = arg; if (type != HIST_FILTER__DSO) return -1; return dso && (!he->ms.map || he->ms.map->dso != dso); }

Contributors

PersonTokensPropCommitsCommitProp
namhyung kimnamhyung kim59100.00%1100.00%
Total59100.00%1100.00%

struct sort_entry sort_dso = { .se_header = "Shared Object", .se_cmp = sort__dso_cmp, .se_snprintf = hist_entry__dso_snprintf, .se_filter = hist_entry__dso_filter, .se_width_idx = HISTC_DSO, }; /* --sort symbol */
static int64_t _sort__addr_cmp(u64 left_ip, u64 right_ip) { return (int64_t)(right_ip - left_ip); }

Contributors

PersonTokensPropCommitsCommitProp
namhyung kimnamhyung kim22100.00%1100.00%
Total22100.00%1100.00%


static int64_t _sort__sym_cmp(struct symbol *sym_l, struct symbol *sym_r) { if (!sym_l || !sym_r) return cmp_null(sym_l, sym_r); if (sym_l == sym_r) return 0; if (sym_l->start != sym_r->start) return (int64_t)(sym_r->start - sym_l->start); return (int64_t)(sym_r->end - sym_l->end); }

Contributors

PersonTokensPropCommitsCommitProp
namhyung kimnamhyung kim5569.62%266.67%
yannick brosseauyannick brosseau2430.38%133.33%
Total79100.00%3100.00%


static int64_t sort__sym_cmp(struct hist_entry *left, struct hist_entry *right) { int64_t ret; if (!left->ms.sym && !right->ms.sym) return _sort__addr_cmp(left->ip, right->ip); /* * comparing symbol address alone is not enough since it's a * relative address within a dso. */ if (!hists__has(left->hists, dso) || hists__has(right->hists, dso)) { ret = sort__dso_cmp(left, right); if (ret != 0) return ret; } return _sort__sym_cmp(left->ms.sym, right->ms.sym); }

Contributors

PersonTokensPropCommitsCommitProp
namhyung kimnamhyung kim8076.19%450.00%
jiri olsajiri olsa1716.19%112.50%
john kacurjohn kacur43.81%112.50%
anton blanchardanton blanchard21.90%112.50%
arnaldo carvalho de meloarnaldo carvalho de melo21.90%112.50%
Total105100.00%8100.00%


static int64_t sort__sym_sort(struct hist_entry *left, struct hist_entry *right) { if (!left->ms.sym || !right->ms.sym) return cmp_null(left->ms.sym, right->ms.sym); return strcmp(right->ms.sym->name, left->ms.sym->name); }

Contributors

PersonTokensPropCommitsCommitProp
namhyung kimnamhyung kim68100.00%1100.00%
Total68100.00%1100.00%


static int _hist_entry__sym_snprintf(struct map *map, struct symbol *sym, u64 ip, char level, char *bf, size_t size, unsigned int width) { size_t ret = 0; if (verbose) { char o = map ? dso__symtab_origin(map->dso) : '!'; ret += repsep_snprintf(bf, size, "%-#*llx %c ", BITS_PER_LONG / 4 + 2, ip, o); } ret += repsep_snprintf(bf + ret, size - ret, "[%c] ", level); if (sym && map) { if (map->type == MAP__VARIABLE) { ret += repsep_snprintf(bf + ret, size - ret, "%s", sym->name); ret += repsep_snprintf(bf + ret, size - ret, "+0x%llx", ip - map->unmap_ip(map, sym->start)); } else { ret += repsep_snprintf(bf + ret, size - ret, "%.*s", width - ret, sym->name); } } else { size_t len = BITS_PER_LONG / 4; ret += repsep_snprintf(bf + ret, size - ret, "%-#.*llx", len, ip); } return ret; }

Contributors

PersonTokensPropCommitsCommitProp
stephane eranianstephane eranian5726.03%18.33%
john kacurjohn kacur4721.46%18.33%
arnaldo carvalho de meloarnaldo carvalho de melo4420.09%433.33%
frederic weisbeckerfrederic weisbecker3114.16%18.33%
roberto agostino vitilloroberto agostino vitillo2913.24%18.33%
namhyung kimnamhyung kim104.57%325.00%
ian munsieian munsie10.46%18.33%
Total219100.00%12100.00%


static int hist_entry__sym_snprintf(struct hist_entry *he, char *bf, size_t size, unsigned int width) { return _hist_entry__sym_snprintf(he->ms.map, he->ms.sym, he->ip, he->level, bf, size, width); }

Contributors

PersonTokensPropCommitsCommitProp
roberto agostino vitilloroberto agostino vitillo4178.85%125.00%
john kacurjohn kacur59.62%125.00%
arnaldo carvalho de meloarnaldo carvalho de melo59.62%125.00%
frederic weisbeckerfrederic weisbecker11.92%125.00%
Total52100.00%4100.00%


static int hist_entry__sym_filter(struct hist_entry *he, int type, const void *arg) { const char *sym = arg; if (type != HIST_FILTER__SYMBOL) return -1; return sym && (!he->ms.sym || !strstr(he->ms.sym->name, sym)); }

Contributors

PersonTokensPropCommitsCommitProp
namhyung kimnamhyung kim62100.00%1100.00%
Total62100.00%1100.00%

struct sort_entry sort_sym = { .se_header = "Symbol", .se_cmp = sort__sym_cmp, .se_sort = sort__sym_sort, .se_snprintf = hist_entry__sym_snprintf, .se_filter = hist_entry__sym_filter, .se_width_idx = HISTC_SYMBOL, }; /* --sort srcline */
char *hist_entry__get_srcline(struct hist_entry *he) { struct map *map = he->ms.map; if (!map) return SRCLINE_UNKNOWN; return get_srcline(map->dso, map__rip_2objdump(map, he->ip), he->ms.sym, true); }

Contributors

PersonTokensPropCommitsCommitProp
namhyung kimnamhyung kim3970.91%240.00%
arnaldo carvalho de meloarnaldo carvalho de melo814.55%120.00%
andi kleenandi kleen712.73%120.00%
thomas jaroschthomas jarosch11.82%120.00%
Total55100.00%5100.00%


static int64_t sort__srcline_cmp(struct hist_entry *left, struct hist_entry *right) { if (!left->srcline) left->srcline = hist_entry__get_srcline(left); if (!right->srcline) right->srcline = hist_entry__get_srcline(right); return strcmp(right->srcline, left->srcline); }

Contributors

PersonTokensPropCommitsCommitProp
namhyung kimnamhyung kim5185.00%562.50%
arnaldo carvalho de meloarnaldo carvalho de melo610.00%112.50%
thomas jaroschthomas jarosch23.33%112.50%
andi kleenandi kleen11.67%112.50%
Total60100.00%8100.00%


static int hist_entry__srcline_snprintf(struct hist_entry *he, char *bf, size_t size, unsigned int width) { if (!he->srcline) he->srcline = hist_entry__get_srcline(he); return repsep_snprintf(bf, size, "%-.*s", width, he->srcline); }

Contributors

PersonTokensPropCommitsCommitProp
namhyung kimnamhyung kim4074.07%466.67%
arnaldo carvalho de meloarnaldo carvalho de melo1425.93%233.33%
Total54100.00%6100.00%

struct sort_entry sort_srcline = { .se_header = "Source:Line", .se_cmp = sort__srcline_cmp, .se_snprintf = hist_entry__srcline_snprintf, .se_width_idx = HISTC_SRCLINE, }; /* --sort srcline_from */
static int64_t sort__srcline_from_cmp(struct hist_entry *left, struct hist_entry *right) { if (!left->branch_info->srcline_from) { struct map *map = left->branch_info->from.map; if (!map) left->branch_info->srcline_from = SRCLINE_UNKNOWN; else left->branch_info->srcline_from = get_srcline(map->dso, map__rip_2objdump(map, left->branch_info->from.al_addr), left->branch_info->from.sym, true); } if (!right->branch_info->srcline_from) { struct map *map = right->branch_info->from.map; if (!map) right->branch_info->srcline_from = SRCLINE_UNKNOWN; else right->branch_info->srcline_from = get_srcline(map->dso, map__rip_2objdump(map, right->branch_info->from.al_addr), right->branch_info->from.sym, true); } return strcmp(right->branch_info->srcline_from, left->branch_info->srcline_from); }

Contributors

PersonTokensPropCommitsCommitProp
andi kleenandi kleen180100.00%1100.00%
Total180100.00%1100.00%


static int hist_entry__srcline_from_snprintf(struct hist_entry *he, char *bf, size_t size, unsigned int width) { return repsep_snprintf(bf, size, "%-*.*s", width, width, he->branch_info->srcline_from); }

Contributors

PersonTokensPropCommitsCommitProp
andi kleenandi kleen42100.00%1100.00%
Total42100.00%1100.00%

struct sort_entry sort_srcline_from = { .se_header = "From Source:Line", .se_cmp = sort__srcline_from_cmp, .se_snprintf = hist_entry__srcline_from_snprintf, .se_width_idx = HISTC_SRCLINE_FROM, }; /* --sort srcline_to */
static int64_t sort__srcline_to_cmp(struct hist_entry *left, struct hist_entry *right) { if (!left->branch_info->srcline_to) { struct map *map = left->branch_info->to.map; if (!map) left->branch_info->srcline_to = SRCLINE_UNKNOWN; else left->branch_info->srcline_to = get_srcline(map->dso, map__rip_2objdump(map, left->branch_info->to.al_addr), left->branch_info->from.sym, true); } if (!right->branch_info->srcline_to) { struct map *map = right->branch_info->to.map; if (!map) right->branch_info->srcline_to = SRCLINE_UNKNOWN; else right->branch_info->srcline_to = get_srcline(map->dso, map__rip_2objdump(map, right->branch_info->to.al_addr), right->branch_info->to.sym, true); } return strcmp(right->branch_info->srcline_to, left->branch_info->srcline_to); }

Contributors

PersonTokensPropCommitsCommitProp
andi kleenandi kleen180100.00%1100.00%
Total180100.00%1100.00%


static int hist_entry__srcline_to_snprintf(struct hist_entry *he, char *bf, size_t size, unsigned int width) { return repsep_snprintf(bf, size, "%-*.*s", width, width, he->branch_info->srcline_to); }

Contributors

PersonTokensPropCommitsCommitProp
andi kleenandi kleen42100.00%1100.00%
Total42100.00%1100.00%

struct sort_entry sort_srcline_to = { .se_header = "To Source:Line", .se_cmp = sort__srcline_to_cmp, .se_snprintf = hist_entry__srcline_to_snprintf, .se_width_idx = HISTC_SRCLINE_TO, }; /* --sort srcfile */ static char no_srcfile[1];
static char *hist_entry__get_srcfile(struct hist_entry *e) { char *sf, *p; struct map *map = e->ms.map; if (!map) return no_srcfile; sf = __get_srcline(map->dso, map__rip_2objdump(map, e->ip), e->ms.sym, false, true); if (!strcmp(sf, SRCLINE_UNKNOWN)) return no_srcfile; p = strchr(sf, ':'); if (p && *sf) { *p = 0; return sf; } free(sf); return no_srcfile; }

Contributors

PersonTokensPropCommitsCommitProp
andi kleenandi kleen10492.04%375.00%
namhyung kimnamhyung kim97.96%125.00%
Total113100.00%4100.00%


static int64_t sort__srcfile_cmp(struct hist_entry *left, struct hist_entry *right) { if (!left->srcfile) left->srcfile = hist_entry__get_srcfile(left); if (!right->srcfile) right->srcfile = hist_entry__get_srcfile(right); return strcmp(right->srcfile, left->srcfile); }

Contributors

PersonTokensPropCommitsCommitProp
andi kleenandi kleen5896.67%150.00%
namhyung kimnamhyung kim23.33%150.00%
Total60100.00%2100.00%


static int hist_entry__srcfile_snprintf(struct hist_entry *he, char *bf, size_t size, unsigned int width) { if (!he->srcfile) he->srcfile = hist_entry__get_srcfile(he); return repsep_snprintf(bf, size, "%-.*s", width, he->srcfile); }

Contributors

PersonTokensPropCommitsCommitProp
andi kleenandi kleen3768.52%133.33%
namhyung kimnamhyung kim1731.48%266.67%
Total54100.00%3100.00%

struct sort_entry sort_srcfile = { .se_header = "Source File", .se_cmp = sort__srcfile_cmp, .se_snprintf = hist_entry__srcfile_snprintf, .se_width_idx = HISTC_SRCFILE, }; /* --sort parent */
static int64_t sort__parent_cmp(struct hist_entry *left, struct hist_entry *right) { struct symbol *sym_l = left->parent; struct symbol *sym_r = right->parent; if (!sym_l || !sym_r) return cmp_null(sym_l, sym_r); return strcmp(sym_r->name, sym_l->name); }

Contributors

PersonTokensPropCommitsCommitProp
john kacurjohn kacur5791.94%133.33%
roberto agostino vitilloroberto agostino vitillo34.84%133.33%
namhyung kimnamhyung kim23.23%133.33%
Total62100.00%3100.00%


static int hist_entry__parent_snprintf(struct hist_entry *he, char *bf, size_t size, unsigned int width) { return repsep_snprintf(bf, size, "%-*.*s", width, width, he->parent ? he->parent->name : "[other]"); }

Contributors

PersonTokensPropCommitsCommitProp
john kacurjohn kacur2858.33%125.00%
arnaldo carvalho de meloarnaldo carvalho de melo1735.42%250.00%
namhyung kimnamhyung kim36.25%125.00%
Total48100.00%4100.00%

struct sort_entry sort_parent = { .se_header = "Parent symbol", .se_cmp = sort__parent_cmp, .se_snprintf = hist_entry__parent_snprintf, .se_width_idx = HISTC_PARENT, }; /* --sort cpu */
static int64_t sort__cpu_cmp(struct hist_entry *left, struct hist_entry *right) { return right->cpu - left->cpu; }

Contributors

PersonTokensPropCommitsCommitProp
arun sharmaarun sharma1456.00%133.33%
roberto agostino vitilloroberto agostino vitillo1040.00%133.33%
frederic weisbeckerfrederic weisbecker14.00%133.33%
Total25100.00%3100.00%


static int hist_entry__cpu_snprintf(struct hist_entry *he, char *bf, size_t size, unsigned int width) { return repsep_snprintf(bf, size, "%*.*d", width, width, he->cpu); }

Contributors

PersonTokensPropCommitsCommitProp
roberto agostino vitilloroberto agostino vitillo3587.50%133.33%
namhyung kimnamhyung kim37.50%133.33%
arnaldo carvalho de meloarnaldo carvalho de melo25.00%133.33%
Total40100.00%3100.00%

struct sort_entry sort_cpu = { .se_header = "CPU", .se_cmp = sort__cpu_cmp, .se_snprintf = hist_entry__cpu_snprintf, .se_width_idx = HISTC_CPU, }; /* --sort socket */
static int64_t sort__socket_cmp(struct hist_entry *left, struct hist_entry *right)