diff options
author | Ingo Molnar <mingo@kernel.org> | 2012-09-07 01:36:59 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@kernel.org> | 2012-09-07 01:36:59 -0400 |
commit | 479d875835a49e849683743ec50c30b6a429696b (patch) | |
tree | 616b96197e489d3fbd5ef8bdde5a59a50d6dcd76 /tools/perf/builtin-script.c | |
parent | bab57e994d6311298b4e3915d2c75296cd81638c (diff) | |
parent | 275ef3878f698941353780440fec6926107a320b (diff) |
Merge tag 'perf-core-for-mingo' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux into perf/core
Pull perf/core improvements and fixes from Arnaldo Carvalho de Melo:
- Rename libtraceevent 'private' struct member to 'priv' so that it works
in C++, from Steven Rostedt
- Remove lots of exit()/die() calls from tools so that the main perf exit
routine can take place, from David Ahern
- Fix x86 build on x86-64, from David Ahern.
- Remove some headers that prevented perf from building on Android,
from David Ahern
- {int,str,rb}list fixes from Suzuki K Poulose
- perf.data header fixes from Namhyung Kim
- Replace needless mempcpy with memcpy, to allow build on Android, from Irina Tirdea
- Allow user to indicate objdump path, needed in cross environments, from
Maciek Borzecki
- Fix hardware cache event name generation, fix from Jiri Olsa
- Add round trip test for sw, hw and cache event names, catching the
problem Jiri fixed, after Jiri's patch, the test passes successfully.
- Clean target should do clean for lib/traceevent too, fix from David Ahern
- Check the right variable for allocation failure, fix from Namhyung Kim
- Set up evsel->tp_format regardless of evsel->name being set already,
fix from Namhyung Kim
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'tools/perf/builtin-script.c')
-rw-r--r-- | tools/perf/builtin-script.c | 60 |
1 files changed, 41 insertions, 19 deletions
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index 2d6e3b226aad..c350cfee3157 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c | |||
@@ -1153,18 +1153,23 @@ static const struct option options[] = { | |||
1153 | OPT_END() | 1153 | OPT_END() |
1154 | }; | 1154 | }; |
1155 | 1155 | ||
1156 | static bool have_cmd(int argc, const char **argv) | 1156 | static int have_cmd(int argc, const char **argv) |
1157 | { | 1157 | { |
1158 | char **__argv = malloc(sizeof(const char *) * argc); | 1158 | char **__argv = malloc(sizeof(const char *) * argc); |
1159 | 1159 | ||
1160 | if (!__argv) | 1160 | if (!__argv) { |
1161 | die("malloc"); | 1161 | pr_err("malloc failed\n"); |
1162 | return -1; | ||
1163 | } | ||
1164 | |||
1162 | memcpy(__argv, argv, sizeof(const char *) * argc); | 1165 | memcpy(__argv, argv, sizeof(const char *) * argc); |
1163 | argc = parse_options(argc, (const char **)__argv, record_options, | 1166 | argc = parse_options(argc, (const char **)__argv, record_options, |
1164 | NULL, PARSE_OPT_STOP_AT_NON_OPTION); | 1167 | NULL, PARSE_OPT_STOP_AT_NON_OPTION); |
1165 | free(__argv); | 1168 | free(__argv); |
1166 | 1169 | ||
1167 | return argc != 0; | 1170 | system_wide = (argc == 0); |
1171 | |||
1172 | return 0; | ||
1168 | } | 1173 | } |
1169 | 1174 | ||
1170 | int cmd_script(int argc, const char **argv, const char *prefix __used) | 1175 | int cmd_script(int argc, const char **argv, const char *prefix __used) |
@@ -1231,13 +1236,13 @@ int cmd_script(int argc, const char **argv, const char *prefix __used) | |||
1231 | 1236 | ||
1232 | if (pipe(live_pipe) < 0) { | 1237 | if (pipe(live_pipe) < 0) { |
1233 | perror("failed to create pipe"); | 1238 | perror("failed to create pipe"); |
1234 | exit(-1); | 1239 | return -1; |
1235 | } | 1240 | } |
1236 | 1241 | ||
1237 | pid = fork(); | 1242 | pid = fork(); |
1238 | if (pid < 0) { | 1243 | if (pid < 0) { |
1239 | perror("failed to fork"); | 1244 | perror("failed to fork"); |
1240 | exit(-1); | 1245 | return -1; |
1241 | } | 1246 | } |
1242 | 1247 | ||
1243 | if (!pid) { | 1248 | if (!pid) { |
@@ -1249,13 +1254,18 @@ int cmd_script(int argc, const char **argv, const char *prefix __used) | |||
1249 | if (is_top_script(argv[0])) { | 1254 | if (is_top_script(argv[0])) { |
1250 | system_wide = true; | 1255 | system_wide = true; |
1251 | } else if (!system_wide) { | 1256 | } else if (!system_wide) { |
1252 | system_wide = !have_cmd(argc - rep_args, | 1257 | if (have_cmd(argc - rep_args, &argv[rep_args]) != 0) { |
1253 | &argv[rep_args]); | 1258 | err = -1; |
1259 | goto out; | ||
1260 | } | ||
1254 | } | 1261 | } |
1255 | 1262 | ||
1256 | __argv = malloc((argc + 6) * sizeof(const char *)); | 1263 | __argv = malloc((argc + 6) * sizeof(const char *)); |
1257 | if (!__argv) | 1264 | if (!__argv) { |
1258 | die("malloc"); | 1265 | pr_err("malloc failed\n"); |
1266 | err = -ENOMEM; | ||
1267 | goto out; | ||
1268 | } | ||
1259 | 1269 | ||
1260 | __argv[j++] = "/bin/sh"; | 1270 | __argv[j++] = "/bin/sh"; |
1261 | __argv[j++] = rec_script_path; | 1271 | __argv[j++] = rec_script_path; |
@@ -1277,8 +1287,12 @@ int cmd_script(int argc, const char **argv, const char *prefix __used) | |||
1277 | close(live_pipe[1]); | 1287 | close(live_pipe[1]); |
1278 | 1288 | ||
1279 | __argv = malloc((argc + 4) * sizeof(const char *)); | 1289 | __argv = malloc((argc + 4) * sizeof(const char *)); |
1280 | if (!__argv) | 1290 | if (!__argv) { |
1281 | die("malloc"); | 1291 | pr_err("malloc failed\n"); |
1292 | err = -ENOMEM; | ||
1293 | goto out; | ||
1294 | } | ||
1295 | |||
1282 | j = 0; | 1296 | j = 0; |
1283 | __argv[j++] = "/bin/sh"; | 1297 | __argv[j++] = "/bin/sh"; |
1284 | __argv[j++] = rep_script_path; | 1298 | __argv[j++] = rep_script_path; |
@@ -1303,12 +1317,20 @@ int cmd_script(int argc, const char **argv, const char *prefix __used) | |||
1303 | 1317 | ||
1304 | if (!rec_script_path) | 1318 | if (!rec_script_path) |
1305 | system_wide = false; | 1319 | system_wide = false; |
1306 | else if (!system_wide) | 1320 | else if (!system_wide) { |
1307 | system_wide = !have_cmd(argc - 1, &argv[1]); | 1321 | if (have_cmd(argc - 1, &argv[1]) != 0) { |
1322 | err = -1; | ||
1323 | goto out; | ||
1324 | } | ||
1325 | } | ||
1308 | 1326 | ||
1309 | __argv = malloc((argc + 2) * sizeof(const char *)); | 1327 | __argv = malloc((argc + 2) * sizeof(const char *)); |
1310 | if (!__argv) | 1328 | if (!__argv) { |
1311 | die("malloc"); | 1329 | pr_err("malloc failed\n"); |
1330 | err = -ENOMEM; | ||
1331 | goto out; | ||
1332 | } | ||
1333 | |||
1312 | __argv[j++] = "/bin/sh"; | 1334 | __argv[j++] = "/bin/sh"; |
1313 | __argv[j++] = script_path; | 1335 | __argv[j++] = script_path; |
1314 | if (system_wide) | 1336 | if (system_wide) |
@@ -1357,18 +1379,18 @@ int cmd_script(int argc, const char **argv, const char *prefix __used) | |||
1357 | input = open(session->filename, O_RDONLY); /* input_name */ | 1379 | input = open(session->filename, O_RDONLY); /* input_name */ |
1358 | if (input < 0) { | 1380 | if (input < 0) { |
1359 | perror("failed to open file"); | 1381 | perror("failed to open file"); |
1360 | exit(-1); | 1382 | return -1; |
1361 | } | 1383 | } |
1362 | 1384 | ||
1363 | err = fstat(input, &perf_stat); | 1385 | err = fstat(input, &perf_stat); |
1364 | if (err < 0) { | 1386 | if (err < 0) { |
1365 | perror("failed to stat file"); | 1387 | perror("failed to stat file"); |
1366 | exit(-1); | 1388 | return -1; |
1367 | } | 1389 | } |
1368 | 1390 | ||
1369 | if (!perf_stat.st_size) { | 1391 | if (!perf_stat.st_size) { |
1370 | fprintf(stderr, "zero-sized file, nothing to do!\n"); | 1392 | fprintf(stderr, "zero-sized file, nothing to do!\n"); |
1371 | exit(0); | 1393 | return 0; |
1372 | } | 1394 | } |
1373 | 1395 | ||
1374 | scripting_ops = script_spec__lookup(generate_script_lang); | 1396 | scripting_ops = script_spec__lookup(generate_script_lang); |