[de0c3c]: events / op_help.c Maximize Restore History

Download this file

op_help.c    174 lines (144 with data), 4.4 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
/* $Id: op_help.c,v 1.5 2002/03/01 21:30:02 phil_e Exp $ */
/* COPYRIGHT (C) 2000 THE VICTORIA UNIVERSITY OF MANCHESTER and John Levon
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc., 59 Temple
* Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/* Adapted from libpperf 0.5 by M. Patrick Goda and Michael S. Warren */
/* See IA32 Vol. 3 Appendix A */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include "../op_user.h"
#include "../util/op_popt.h"
static op_cpu cpu_type = CPU_NO_GOOD;
/**
* help_for_event - output event name and description
* @i: event number
*
* output an help string for the event @i
*/
static void help_for_event(int i)
{
uint j,k;
op_cpu cpu;
uint mask;
printf("%s", op_events[i].name);
printf(": (counter: ");
if (op_events[i].counter_mask == CTR_ALL) {
printf("all");
} else {
mask = op_events[i].counter_mask;
for (k = 0; k < CHAR_BIT * sizeof(op_events[i].counter_mask); ++k) {
if (mask & (1 << k)) {
printf("%d", k);
mask &= ~(1 << k);
if (mask)
printf(", ");
}
}
}
printf(")");
printf(" (supported cpu: ");
mask = op_events[i].cpu_mask;
for (cpu = 0; cpu < MAX_CPU_TYPE; ++cpu) {
if (mask & (1 << cpu)) {
printf("%s", op_get_cpu_type_str(cpu));
mask &= ~(1 << cpu);
if (mask)
printf(", ");
}
}
printf(")\n\t%s (min count: %d)\n", op_event_descs[i], op_events[i].min_count);
if (op_events[i].unit) {
int unit_idx = op_events[i].unit;
printf("\tUnit masks\n");
printf("\t----------\n");
for (j=0; j < op_unit_masks[unit_idx].num; j++) {
printf("\t%.2x: %s\n",
op_unit_masks[unit_idx].um[j],
op_unit_descs[unit_idx].desc[j]);
}
}
}
static int showvers;
static int get_cpu_type;
static const char * event_name;
static struct poptOption options[] = {
{ "cpu-type", 'c', POPT_ARG_INT, &cpu_type, 0,
"force cpu type", "cpu type", },
{ "get-cpu-type", 'r', POPT_ARG_NONE, &get_cpu_type, 0,
"show the auto detected cpu type", NULL, },
{ "version", 'v', POPT_ARG_NONE, &showvers, 0, "show version", NULL, },
POPT_AUTOHELP
{ NULL, 0, 0, NULL, 0, NULL, NULL, },
};
/**
* get_options - process command line
* @argc: program arg count
* @argv: program arg array
*
* Process the arguments, fatally complaining on error.
*/
static void get_options(int argc, char const * argv[])
{
poptContext optcon;
optcon = opd_poptGetContext(NULL, argc, argv, options, 0);
if (showvers) {
show_version(argv[0]);
}
/* non-option, must be a valid event name */
event_name = poptGetArg(optcon);
poptFreeContext(optcon);
}
int main(int argc, char const *argv[])
{
int cpu_type_mask;
uint j;
cpu_type = op_get_cpu_type();
get_options(argc, argv);
if (cpu_type < 0 || cpu_type >= MAX_CPU_TYPE) {
fprintf(stderr, "invalid cpu type %d !\n", cpu_type);
exit(EXIT_FAILURE);
}
if (get_cpu_type) {
printf("%d\n", cpu_type);
exit(EXIT_SUCCESS);
}
if (event_name) {
cpu_type_mask = 1 << cpu_type;
for (j=0; j < op_nr_events; j++) {
if (!strcmp(op_events[j].name, event_name) &&
(op_events[j].cpu_mask & cpu_type_mask)) {
printf("%d\n", op_events[j].val);
exit(EXIT_SUCCESS);
}
}
fprintf(stderr, "No such event \"%s\"\n", event_name);
exit(EXIT_FAILURE);
}
printf("oprofile: available events\n");
printf("--------------------------\n\n");
if (cpu_type == CPU_ATHLON)
printf ("See AMD document x86 optimisation guide (22007.pdf), Appendix D\n\n");
else
printf("See Intel Architecture Developer's Manual\nVol. 3 (), Appendix A\n\n");
cpu_type_mask = 1 << cpu_type;
for (j = 0; j < op_nr_events; j++) {
if ((op_events[j].cpu_mask & cpu_type_mask) != 0) {
help_for_event(j);
}
}
return EXIT_SUCCESS;
}