[0d0e60]: daemon / opd_mangling.c  Maximize  Restore  History

Download this file

155 lines (121 with data), 3.2 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/**
* @file daemon/opd_mangling.c
* Mangling and opening of sample files
*
* @remark Copyright 2002 OProfile authors
* @remark Read the file COPYING
*
* @author John Levon
* @author Philippe Elie
*/
#include <sys/types.h>
#include "opd_mangling.h"
#include "opd_kernel.h"
#include "opd_cookie.h"
#include "opd_sfile.h"
#include "opd_printf.h"
#include "opd_events.h"
#include "oprofiled.h"
#include "op_file.h"
#include "op_sample_file.h"
#include "op_config.h"
#include "op_mangle.h"
#include "op_events.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
static char const * get_dep_name(struct sfile const * sf)
{
/* avoid to call find_cookie(), caller can recover using image_name */
if (sf->cookie == sf->app_cookie)
return NULL;
if (!separate_kernel && !(separate_lib && !sf->kernel))
return NULL;
/* this will fail if e.g. kernel thread */
if (sf->app_cookie == 0)
return NULL;
return find_cookie(sf->app_cookie);
}
static char *
mangle_filename(struct sfile * last, struct sfile const * sf, int counter, int cg)
{
char * mangled;
struct mangle_values values;
struct opd_event * event = find_counter_event(counter);
values.flags = 0;
if (sf->kernel) {
values.image_name = sf->kernel->name;
values.flags |= MANGLE_KERNEL;
} else {
values.image_name = find_cookie(sf->cookie);
}
/* FIXME: log */
if (!values.image_name)
return NULL;
values.dep_name = get_dep_name(sf);
if (!values.dep_name)
values.dep_name = values.image_name;
if (separate_thread) {
values.flags |= MANGLE_TGID | MANGLE_TID;
values.tid = sf->tid;
values.tgid = sf->tgid;
}
if (separate_cpu) {
values.flags |= MANGLE_CPU;
values.cpu = sf->cpu;
}
if (cg) {
values.flags |= MANGLE_CALLGRAPH;
if (last->kernel)
values.cg_image_name = last->kernel->name;
else
values.cg_image_name = find_cookie(last->cookie);
if (!values.cg_image_name)
return NULL;
}
values.event_name = event->name;
values.count = event->count;
values.unit_mask = event->um;
mangled = op_mangle_filename(&values);
return mangled;
}
int opd_open_sample_file(samples_odb_t * file, struct sfile * last,
struct sfile * sf, int counter, int cg)
{
char * mangled;
char const * binary;
int err;
mangled = mangle_filename(last, sf, counter, cg);
if (!mangled)
return EINVAL;
verbprintf("Opening \"%s\"\n", mangled);
create_path(mangled);
sfile_get(sf); /* locking sf will lock associated cg files too */
retry:
err = odb_open(file, mangled, ODB_RDWR, sizeof(struct opd_header));
/* This can naturally happen when racing against opcontrol --reset. */
if (err) {
if (err == EMFILE) {
if (sfile_lru_clear()) {
printf("LRU cleared but odb_open() fails for %s.\n", mangled);
abort();
}
goto retry;
}
fprintf(stderr, "oprofiled: open of %s failed: %s\n",
mangled, strerror(err));
goto out;
}
if (!sf->kernel)
binary = find_cookie(sf->cookie);
else
binary = sf->kernel->name;
fill_header(file->base_memory, counter, !!sf->kernel,
last ? !!last->kernel : 0,
binary ? op_get_mtime(binary) : 0);
out:
sfile_put(sf);
free(mangled);
return err;
}

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks