17
17
#include <subcmd/parse-options.h>
18
18
#include "evlist.h"
19
19
#include "target.h"
20
+ #include "cpumap.h"
20
21
#include "thread_map.h"
21
22
#include "util/config.h"
22
23
@@ -96,6 +97,8 @@ static int append_tracing_file(const char *name, const char *val)
96
97
return __write_tracing_file (name , val , true);
97
98
}
98
99
100
+ static int reset_tracing_cpu (void );
101
+
99
102
static int reset_tracing_files (struct perf_ftrace * ftrace __maybe_unused )
100
103
{
101
104
if (write_tracing_file ("tracing_on" , "0" ) < 0 )
@@ -107,6 +110,9 @@ static int reset_tracing_files(struct perf_ftrace *ftrace __maybe_unused)
107
110
if (write_tracing_file ("set_ftrace_pid" , " " ) < 0 )
108
111
return -1 ;
109
112
113
+ if (reset_tracing_cpu () < 0 )
114
+ return -1 ;
115
+
110
116
return 0 ;
111
117
}
112
118
@@ -127,6 +133,51 @@ static int set_tracing_pid(struct perf_ftrace *ftrace)
127
133
return 0 ;
128
134
}
129
135
136
+ static int set_tracing_cpumask (struct cpu_map * cpumap )
137
+ {
138
+ char * cpumask ;
139
+ size_t mask_size ;
140
+ int ret ;
141
+ int last_cpu ;
142
+
143
+ last_cpu = cpu_map__cpu (cpumap , cpumap -> nr - 1 );
144
+ mask_size = (last_cpu + 3 ) / 4 + 1 ;
145
+ mask_size += last_cpu / 32 ; /* ',' is needed for every 32th cpus */
146
+
147
+ cpumask = malloc (mask_size );
148
+ if (cpumask == NULL ) {
149
+ pr_debug ("failed to allocate cpu mask\n" );
150
+ return -1 ;
151
+ }
152
+
153
+ cpu_map__snprint_mask (cpumap , cpumask , mask_size );
154
+
155
+ ret = write_tracing_file ("tracing_cpumask" , cpumask );
156
+
157
+ free (cpumask );
158
+ return ret ;
159
+ }
160
+
161
+ static int set_tracing_cpu (struct perf_ftrace * ftrace )
162
+ {
163
+ struct cpu_map * cpumap = ftrace -> evlist -> cpus ;
164
+
165
+ if (!target__has_cpu (& ftrace -> target ))
166
+ return 0 ;
167
+
168
+ return set_tracing_cpumask (cpumap );
169
+ }
170
+
171
+ static int reset_tracing_cpu (void )
172
+ {
173
+ struct cpu_map * cpumap = cpu_map__new (NULL );
174
+ int ret ;
175
+
176
+ ret = set_tracing_cpumask (cpumap );
177
+ cpu_map__put (cpumap );
178
+ return ret ;
179
+ }
180
+
130
181
static int __cmd_ftrace (struct perf_ftrace * ftrace , int argc , const char * * argv )
131
182
{
132
183
char * trace_file ;
@@ -163,6 +214,11 @@ static int __cmd_ftrace(struct perf_ftrace *ftrace, int argc, const char **argv)
163
214
goto out_reset ;
164
215
}
165
216
217
+ if (set_tracing_cpu (ftrace ) < 0 ) {
218
+ pr_err ("failed to set tracing cpumask\n" );
219
+ goto out_reset ;
220
+ }
221
+
166
222
if (write_tracing_file ("current_tracer" , ftrace -> tracer ) < 0 ) {
167
223
pr_err ("failed to set current_tracer to %s\n" , ftrace -> tracer );
168
224
goto out_reset ;
@@ -264,6 +320,10 @@ int cmd_ftrace(int argc, const char **argv, const char *prefix __maybe_unused)
264
320
"trace on existing process id" ),
265
321
OPT_INCR ('v' , "verbose" , & verbose ,
266
322
"be more verbose" ),
323
+ OPT_BOOLEAN ('a' , "all-cpus" , & ftrace .target .system_wide ,
324
+ "system-wide collection from all CPUs" ),
325
+ OPT_STRING ('C' , "cpu" , & ftrace .target .cpu_list , "cpu" ,
326
+ "list of cpus to monitor" ),
267
327
OPT_END ()
268
328
};
269
329
0 commit comments