op_mangle.c
Go to the documentation of this file.00001
00012 #include "op_mangle.h"
00013
00014 #include <string.h>
00015 #include <stdio.h>
00016
00017 #include "op_libiberty.h"
00018
00019 #include "op_sample_file.h"
00020 #include "op_config.h"
00021
00022 static void append_image(char * dest, int flags, int anon, char const * name, char const * anon_name)
00023 {
00024 if ((flags & MANGLE_KERNEL) && !strchr(name, '/')) {
00025 strcat(dest, "{kern}/");
00026 } else if (anon) {
00027 strcat(dest, "{anon:");
00028 strcat(dest, anon_name);
00029 strcat(dest,"}/");
00030 } else {
00031 strcat(dest, "{root}/");
00032 }
00033
00034 strcat(dest, name);
00035 strcat(dest, "/");
00036 }
00037
00038 char * op_mangle_filename(struct mangle_values const * values)
00039 {
00040 char * mangled;
00041 size_t len;
00042 int anon = values->flags & MANGLE_ANON;
00043 int cg_anon = values->flags & MANGLE_CG_ANON;
00044
00045
00046
00047
00048 char const * image_name = values->dep_name;
00049 char const * anon_name = values->anon_name;
00050 char const * dep_name = values->image_name;
00051 char const * cg_image_name = values->cg_image_name;
00052
00053 len = strlen(op_samples_current_dir) + strlen(dep_name) + 1
00054 + strlen(values->event_name) + 1 + strlen(image_name) + 1;
00055
00056 if (values->flags & MANGLE_CALLGRAPH)
00057 len += strlen(cg_image_name) + 1;
00058
00059 if (anon || cg_anon)
00060 len += strlen(anon_name);
00061
00062
00063
00064
00065 len += 256;
00066
00067 mangled = xmalloc(len);
00068
00069 strcpy(mangled, op_samples_current_dir);
00070 append_image(mangled, values->flags, 0, image_name, anon_name);
00071
00072 strcat(mangled, "{dep}" "/");
00073 append_image(mangled, values->flags, anon, dep_name, anon_name);
00074
00075 if (values->flags & MANGLE_CALLGRAPH) {
00076 strcat(mangled, "{cg}" "/");
00077 append_image(mangled, values->flags, cg_anon,
00078 cg_image_name, anon_name);
00079 }
00080
00081 strcat(mangled, values->event_name);
00082 sprintf(mangled + strlen(mangled), ".%d.%d.",
00083 values->count, values->unit_mask);
00084
00085 if (values->flags & MANGLE_TGID) {
00086 sprintf(mangled + strlen(mangled), "%d.", values->tgid);
00087 } else {
00088 sprintf(mangled + strlen(mangled), "%s.", "all");
00089 }
00090
00091 if (values->flags & MANGLE_TID) {
00092 sprintf(mangled + strlen(mangled), "%d.", values->tid);
00093 } else {
00094 sprintf(mangled + strlen(mangled), "%s.", "all");
00095 }
00096
00097 if (values->flags & MANGLE_CPU) {
00098 sprintf(mangled + strlen(mangled), "%d", values->cpu);
00099 } else {
00100 sprintf(mangled + strlen(mangled), "%s", "all");
00101 }
00102
00103 return mangled;
00104 }