1 /** 2 * @file op_mangle.c 3 * Mangling of sample file names 4 * 5 * @remark Copyright 2002 OProfile authors 6 * @remark Read the file COPYING 7 * 8 * @author John Levon 9 * @author Philippe Elie 10 */ 11 12 #include "op_mangle.h" 13 14 #include <string.h> 15 #include <stdio.h> 16 17 #include "op_libiberty.h" 18 19 #include "op_sample_file.h" 20 #include "op_config.h" 21 22 static void append_image(char * dest, int flags, int anon, char const * name, char const * anon_name) 23 { 24 if ((flags & MANGLE_KERNEL) && !strchr(name, '/')) { 25 strcat(dest, "{kern}/"); 26 } else if (anon) { 27 strcat(dest, "{anon:"); 28 strcat(dest, anon_name); 29 strcat(dest,"}/"); 30 } else { 31 strcat(dest, "{root}/"); 32 } 33 34 strcat(dest, name); 35 strcat(dest, "/"); 36 } 37 38 char * op_mangle_filename(struct mangle_values const * values) 39 { 40 char * mangled; 41 size_t len; 42 int anon = values->flags & MANGLE_ANON; 43 int cg_anon = values->flags & MANGLE_CG_ANON; 44 /* if dep_name != image_name we need to invert them (and so revert them 45 * unconditionally because if they are equal it doesn't hurt to invert 46 * them), see P:3, FIXME: this is a bit weirds, we prolly need to 47 * reword pp_interface */ 48 char const * image_name = values->dep_name; 49 char const * anon_name = values->anon_name; 50 char const * dep_name = values->image_name; 51 char const * cg_image_name = values->cg_image_name; 52 53 len = strlen(op_samples_current_dir) + strlen(dep_name) + 1 54 + strlen(values->event_name) + 1 + strlen(image_name) + 1; 55 56 if (values->flags & MANGLE_CALLGRAPH) 57 len += strlen(cg_image_name) + 1; 58 59 if (anon || cg_anon) 60 len += strlen(anon_name); 61 62 /* provision for tgid, tid, unit_mask, cpu and some {root}, {dep}, 63 * {kern}, {anon} and {cg} marker */ 64 /* FIXME: too ugly */ 65 len += 256; 66 67 mangled = xmalloc(len); 68 69 strcpy(mangled, op_samples_current_dir); 70 append_image(mangled, values->flags, 0, image_name, anon_name); 71 72 strcat(mangled, "{dep}" "/"); 73 append_image(mangled, values->flags, anon, dep_name, anon_name); 74 75 if (values->flags & MANGLE_CALLGRAPH) { 76 strcat(mangled, "{cg}" "/"); 77 append_image(mangled, values->flags, cg_anon, 78 cg_image_name, anon_name); 79 } 80 81 strcat(mangled, values->event_name); 82 sprintf(mangled + strlen(mangled), ".%d.%d.", 83 values->count, values->unit_mask); 84 85 if (values->flags & MANGLE_TGID) { 86 sprintf(mangled + strlen(mangled), "%d.", values->tgid); 87 } else { 88 sprintf(mangled + strlen(mangled), "%s.", "all"); 89 } 90 91 if (values->flags & MANGLE_TID) { 92 sprintf(mangled + strlen(mangled), "%d.", values->tid); 93 } else { 94 sprintf(mangled + strlen(mangled), "%s.", "all"); 95 } 96 97 if (values->flags & MANGLE_CPU) { 98 sprintf(mangled + strlen(mangled), "%d", values->cpu); 99 } else { 100 sprintf(mangled + strlen(mangled), "%s", "all"); 101 } 102 103 return mangled; 104 } 105