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

Download this file

160 lines (125 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
155
156
157
158
159
/**
* @file daemon/opd_events.c
* Event details for each counter
*
* @remark Copyright 2002, 2003 OProfile authors
* @remark Read the file COPYING
*
* @author John Levon
* @author Philippe Elie
*/
#include "config.h"
#include "opd_events.h"
#include "opd_printf.h"
#include "oprofiled.h"
#include "op_string.h"
#include "op_config.h"
#include "op_cpufreq.h"
#include "op_cpu_type.h"
#include "op_libiberty.h"
#include "op_hw_config.h"
#include "op_sample_file.h"
#include <stdlib.h>
#include <stdio.h>
extern op_cpu cpu_type;
struct opd_event opd_events[OP_MAX_COUNTERS];
static double cpu_speed;
static void malformed_events(void)
{
fprintf(stderr, "oprofiled: malformed events passed "
"on the command line\n");
exit(EXIT_FAILURE);
}
static char * copy_token(char ** c, char delim)
{
char * tmp = *c;
char * tmp2 = *c;
char * str;
if (!**c)
return NULL;
while (*tmp2 && *tmp2 != delim)
++tmp2;
if (tmp2 == tmp)
return NULL;
str = op_xstrndup(tmp, tmp2 - tmp);
*c = tmp2;
if (**c)
++*c;
return str;
}
static unsigned long copy_ulong(char ** c, char delim)
{
unsigned long val = 0;
char * str = copy_token(c, delim);
if (!str)
malformed_events();
val = strtoul(str, NULL, 0);
free(str);
return val;
}
void opd_parse_events(char const * events)
{
char * ev = xstrdup(events);
char * c;
size_t cur = 0;
if (cpu_type == CPU_TIMER_INT) {
struct opd_event * event = &opd_events[0];
event->name = xstrdup("TIMER");
event->value = event->counter
= event->count = event->um = 0;
event->kernel = 1;
event->user = 1;
return;
}
if (!ev || !strlen(ev)) {
fprintf(stderr, "oprofiled: no events passed.\n");
exit(EXIT_FAILURE);
}
verbprintf("Events: %s\n", ev);
c = ev;
while (*c && cur < op_nr_counters) {
struct opd_event * event = &opd_events[cur];
if (!(event->name = copy_token(&c, ':')))
malformed_events();
event->value = copy_ulong(&c, ':');
event->counter = copy_ulong(&c, ':');
event->count = copy_ulong(&c, ':');
event->um = copy_ulong(&c, ':');
event->kernel = copy_ulong(&c, ':');
event->user = copy_ulong(&c, ',');
++cur;
}
if (*c) {
fprintf(stderr, "oprofiled: too many events passed.\n");
exit(EXIT_FAILURE);
}
free(ev);
cpu_speed = op_cpu_frequency();
}
struct opd_event * find_counter_event(unsigned long counter)
{
size_t i;
for (i = 0; i < op_nr_counters && opd_events[i].name; ++i) {
if (counter == opd_events[i].counter)
return &opd_events[i];
}
fprintf(stderr, "Unknown event for counter %lu\n", counter);
abort();
return NULL;
}
void fill_header(struct opd_header * header, unsigned long counter,
int is_kernel, int cg_to_is_kernel, time_t mtime)
{
struct opd_event * event = find_counter_event(counter);
memset(header, '\0', sizeof(struct opd_header));
header->version = OPD_VERSION;
memcpy(header->magic, OPD_MAGIC, sizeof(header->magic));
header->cpu_type = cpu_type;
header->ctr_event = event->value;
header->ctr_count = event->count;
header->ctr_um = event->um;
header->is_kernel = is_kernel;
header->cg_to_is_kernel = cg_to_is_kernel;
header->cpu_speed = cpu_speed;
header->mtime = mtime;
}

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

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks