tools lib traceevent: Add pevent_unregister_print_function()
[platform/adaptation/renesas_rcar/renesas_kernel.git] / tools / perf / util / annotate.c
index cf6242c..469eb67 100644 (file)
@@ -26,10 +26,10 @@ static int disasm_line__parse(char *line, char **namep, char **rawp);
 
 static void ins__delete(struct ins_operands *ops)
 {
-       free(ops->source.raw);
-       free(ops->source.name);
-       free(ops->target.raw);
-       free(ops->target.name);
+       zfree(&ops->source.raw);
+       zfree(&ops->source.name);
+       zfree(&ops->target.raw);
+       zfree(&ops->target.name);
 }
 
 static int ins__raw_scnprintf(struct ins *ins, char *bf, size_t size,
@@ -185,8 +185,7 @@ static int lock__parse(struct ins_operands *ops)
        return 0;
 
 out_free_ops:
-       free(ops->locked.ops);
-       ops->locked.ops = NULL;
+       zfree(&ops->locked.ops);
        return 0;
 }
 
@@ -205,9 +204,9 @@ static int lock__scnprintf(struct ins *ins, char *bf, size_t size,
 
 static void lock__delete(struct ins_operands *ops)
 {
-       free(ops->locked.ops);
-       free(ops->target.raw);
-       free(ops->target.name);
+       zfree(&ops->locked.ops);
+       zfree(&ops->target.raw);
+       zfree(&ops->target.name);
 }
 
 static struct ins_ops lock_ops = {
@@ -256,8 +255,7 @@ static int mov__parse(struct ins_operands *ops)
        return 0;
 
 out_free_source:
-       free(ops->source.raw);
-       ops->source.raw = NULL;
+       zfree(&ops->source.raw);
        return -1;
 }
 
@@ -464,17 +462,12 @@ void symbol__annotate_zero_histograms(struct symbol *sym)
        pthread_mutex_unlock(&notes->lock);
 }
 
-int symbol__inc_addr_samples(struct symbol *sym, struct map *map,
-                            int evidx, u64 addr)
+static int __symbol__inc_addr_samples(struct symbol *sym, struct map *map,
+                                     struct annotation *notes, int evidx, u64 addr)
 {
        unsigned offset;
-       struct annotation *notes;
        struct sym_hist *h;
 
-       notes = symbol__annotation(sym);
-       if (notes->src == NULL)
-               return -ENOMEM;
-
        pr_debug3("%s: addr=%#" PRIx64 "\n", __func__, map->unmap_ip(map, addr));
 
        if (addr < sym->start || addr > sym->end)
@@ -491,6 +484,33 @@ int symbol__inc_addr_samples(struct symbol *sym, struct map *map,
        return 0;
 }
 
+static int symbol__inc_addr_samples(struct symbol *sym, struct map *map,
+                                   int evidx, u64 addr)
+{
+       struct annotation *notes;
+
+       if (sym == NULL || use_browser != 1 || !sort__has_sym)
+               return 0;
+
+       notes = symbol__annotation(sym);
+       if (notes->src == NULL) {
+               if (symbol__alloc_hist(sym) < 0)
+                       return -ENOMEM;
+       }
+
+       return __symbol__inc_addr_samples(sym, map, notes, evidx, addr);
+}
+
+int addr_map_symbol__inc_samples(struct addr_map_symbol *ams, int evidx)
+{
+       return symbol__inc_addr_samples(ams->sym, ams->map, evidx, ams->al_addr);
+}
+
+int hist_entry__inc_addr_samples(struct hist_entry *he, int evidx, u64 ip)
+{
+       return symbol__inc_addr_samples(he->ms.sym, he->ms.map, evidx, ip);
+}
+
 static void disasm_line__init_ins(struct disasm_line *dl)
 {
        dl->ins = ins__find(dl->name);
@@ -538,8 +558,7 @@ static int disasm_line__parse(char *line, char **namep, char **rawp)
        return 0;
 
 out_free_name:
-       free(*namep);
-       *namep = NULL;
+       zfree(namep);
        return -1;
 }
 
@@ -564,7 +583,7 @@ static struct disasm_line *disasm_line__new(s64 offset, char *line, size_t privs
        return dl;
 
 out_free_line:
-       free(dl->line);
+       zfree(&dl->line);
 out_delete:
        free(dl);
        return NULL;
@@ -572,8 +591,8 @@ out_delete:
 
 void disasm_line__free(struct disasm_line *dl)
 {
-       free(dl->line);
-       free(dl->name);
+       zfree(&dl->line);
+       zfree(&dl->name);
        if (dl->ins && dl->ins->ops->free)
                dl->ins->ops->free(&dl->ops);
        else
@@ -900,7 +919,7 @@ fallback:
                 * cache, or is just a kallsyms file, well, lets hope that this
                 * DSO is the same as when 'perf record' ran.
                 */
-               filename = dso->long_name;
+               filename = (char *)dso->long_name;
                snprintf(symfs_filename, sizeof(symfs_filename), "%s%s",
                         symbol_conf.symfs, filename);
                free_filename = false;
@@ -1091,8 +1110,7 @@ static void symbol__free_source_line(struct symbol *sym, int len)
                src_line = (void *)src_line + sizeof_src_line;
        }
 
-       free(notes->src->lines);
-       notes->src->lines = NULL;
+       zfree(&notes->src->lines);
 }
 
 /* Get the filename:line for the colored entries */
@@ -1376,3 +1394,8 @@ int symbol__tty_annotate(struct symbol *sym, struct map *map,
 
        return 0;
 }
+
+int hist_entry__annotate(struct hist_entry *he, size_t privsize)
+{
+       return symbol__annotate(he->ms.sym, he->ms.map, privsize);
+}