[a8d9ee]: daemon / liblegacy / opd_sample_files.c  Maximize  Restore  History

Download this file

180 lines (141 with data), 3.8 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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/**
* @file opd_sample_files.c
* Management 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_sample_files.h"
#include "opd_image.h"
#include "opd_printf.h"
#include "opd_events.h"
#include "oprofiled.h"
#include "op_sample_file.h"
#include "op_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>
/** All sfiles are on this list. */
static LIST_HEAD(lru_list);
/* this value probably doesn't matter too much */
#define LRU_AMOUNT 1000
static int opd_24_sfile_lru_clear(void)
{
struct list_head * pos;
struct list_head * pos2;
struct opd_24_sfile * sfile;
int amount = LRU_AMOUNT;
verbprintf(vsfile, "image lru clear\n");
if (list_empty(&lru_list))
return 1;
list_for_each_safe(pos, pos2, &lru_list) {
if (!--amount)
break;
sfile = list_entry(pos, struct opd_24_sfile, lru_next);
odb_close(&sfile->sample_file);
list_del_init(&sfile->lru_next);
}
return 0;
}
void opd_24_sfile_lru(struct opd_24_sfile * sfile)
{
list_del(&sfile->lru_next);
list_add_tail(&sfile->lru_next, &lru_list);
}
static char * opd_mangle_filename(struct opd_image const * image, int counter,
int cpu_nr)
{
char * mangled;
struct mangle_values values;
struct opd_event * event = find_counter_event(counter);
values.flags = 0;
if (image->kernel)
values.flags |= MANGLE_KERNEL;
if (separate_thread) {
values.flags |= MANGLE_TGID | MANGLE_TID;
values.tid = image->tid;
values.tgid = image->tgid;
}
if (separate_cpu) {
values.flags |= MANGLE_CPU;
values.cpu = cpu_nr;
}
values.event_name = event->name;
values.count = event->count;
values.unit_mask = event->um;
values.image_name = image->name;
values.dep_name = separate_lib && image->app_name
? image->app_name : image->name;
mangled = op_mangle_filename(&values);
return mangled;
}
int opd_open_24_sample_file(struct opd_image * image, int counter, int cpu_nr)
{
char * mangled;
struct opd_24_sfile * sfile;
int err;
mangled = opd_mangle_filename(image, counter, cpu_nr);
verbprintf(vsfile, "Opening \"%s\"\n", mangled);
create_path(mangled);
sfile = image->sfiles[cpu_nr][counter];
if (!sfile) {
sfile = malloc(sizeof(struct opd_24_sfile));
list_init(&sfile->lru_next);
odb_init(&sfile->sample_file);
image->sfiles[cpu_nr][counter] = sfile;
}
list_del(&sfile->lru_next);
list_add_tail(&sfile->lru_next, &lru_list);
retry:
err = odb_open(&sfile->sample_file, mangled, ODB_RDWR,
sizeof(struct opd_header));
/* This can naturally happen when racing against opcontrol --reset. */
if (err) {
if (err == EMFILE) {
if (opd_24_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;
}
fill_header(odb_get_data(&sfile->sample_file), counter, 0, 0,
image->kernel, 0, 0, 0, image->mtime);
out:
free(mangled);
return err;
}
void opd_sync_samples_files(void)
{
struct list_head * pos;
struct opd_24_sfile * sfile;
list_for_each(pos, &lru_list) {
sfile = list_entry(pos, struct opd_24_sfile, lru_next);
odb_sync(&sfile->sample_file);
}
}
void opd_close_image_samples_files(struct opd_image * image)
{
uint i, j;
for (i = 0 ; i < op_nr_counters ; ++i) {
for (j = 0; j < NR_CPUS; ++j) {
if (image->sfiles[j] && image->sfiles[j][i]) {
odb_close(&image->sfiles[j][i]->sample_file);
list_del(&image->sfiles[j][i]->lru_next);
free(image->sfiles[j][i]);
image->sfiles[j][i] = 0;
}
}
}
}

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

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks