-
Notifications
You must be signed in to change notification settings - Fork 1
/
trace-options.c
113 lines (99 loc) · 2.61 KB
/
trace-options.c
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
/*
* Copyright (C) 2009, 2010 Red Hat Inc, Steven Rostedt <[email protected]>
*
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*
* 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; version 2 of the License (not later!)
*
* 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
*
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
#define _LARGEFILE64_SOURCE
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <getopt.h>
#include <unistd.h>
#include "trace-local.h"
enum {
OPT_kallsyms = 253,
OPT_events = 254,
OPT_cpu = 255,
};
struct option_list {
struct option_list *next;
struct plugin_option *op;
};
static struct plugin_list {
struct plugin_list *next;
const char *name;
struct option_list *ops;
} *plugin_list;
static void add_option(struct plugin_option *option)
{
struct plugin_list *pl;
struct option_list *po;
const char *name;
name = option->plugin_alias ? : option->file;
for (pl = plugin_list; pl; pl = pl->next) {
if (strcmp(name, pl->name) == 0)
break;
}
if (!pl) {
pl = malloc_or_die(sizeof(*pl));
memset(pl, 0, sizeof(*pl));
pl->name = name;
pl->next = plugin_list;
plugin_list = pl;
};
po = malloc_or_die(sizeof(*po));
po->next = pl->ops;
pl->ops = po;
po->op = option;
}
void trace_option (int argc, char **argv)
{
struct plugin_option *options;
struct plugin_option *op;
struct plugin_list *pl;
struct plugin_list *npl;
struct option_list *po;
struct option_list *npo;
if (argc < 2)
usage(argv);
if (strcmp(argv[1], "options") != 0)
usage(argv);
options = trace_util_read_plugin_options();
if (!options) {
printf("No plugin options found\n");
goto out;
}
/* Group them up according to aliases */
for (op = options; op; op = op->next)
add_option(op);
for (pl = plugin_list; pl; pl = npl) {
npl = pl->next;
printf("%s\n", pl->name);
for (po = pl->ops; po; po = npo) {
npo = po->next;
printf(" %s: %s\n",
po->op->name, po->op->description);
free(po);
}
free(pl);
}
out:
trace_util_free_options(options);
return;
}