builtin-script.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411
  1. #include "builtin.h"
  2. #include "perf.h"
  3. #include "util/cache.h"
  4. #include "util/debug.h"
  5. #include "util/exec_cmd.h"
  6. #include "util/header.h"
  7. #include "util/parse-options.h"
  8. #include "util/session.h"
  9. #include "util/tool.h"
  10. #include "util/symbol.h"
  11. #include "util/thread.h"
  12. #include "util/trace-event.h"
  13. #include "util/util.h"
  14. #include "util/evlist.h"
  15. #include "util/evsel.h"
  16. #include <linux/bitmap.h>
  17. static char const *script_name;
  18. static char const *generate_script_lang;
  19. static bool debug_mode;
  20. static u64 last_timestamp;
  21. static u64 nr_unordered;
  22. extern const struct option record_options[];
  23. static bool no_callchain;
  24. static bool show_full_info;
  25. static bool system_wide;
  26. static const char *cpu_list;
  27. static DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS);
  28. enum perf_output_field {
  29. PERF_OUTPUT_COMM = 1U << 0,
  30. PERF_OUTPUT_TID = 1U << 1,
  31. PERF_OUTPUT_PID = 1U << 2,
  32. PERF_OUTPUT_TIME = 1U << 3,
  33. PERF_OUTPUT_CPU = 1U << 4,
  34. PERF_OUTPUT_EVNAME = 1U << 5,
  35. PERF_OUTPUT_TRACE = 1U << 6,
  36. PERF_OUTPUT_IP = 1U << 7,
  37. PERF_OUTPUT_SYM = 1U << 8,
  38. PERF_OUTPUT_DSO = 1U << 9,
  39. PERF_OUTPUT_ADDR = 1U << 10,
  40. PERF_OUTPUT_SYMOFFSET = 1U << 11,
  41. };
  42. struct output_option {
  43. const char *str;
  44. enum perf_output_field field;
  45. } all_output_options[] = {
  46. {.str = "comm", .field = PERF_OUTPUT_COMM},
  47. {.str = "tid", .field = PERF_OUTPUT_TID},
  48. {.str = "pid", .field = PERF_OUTPUT_PID},
  49. {.str = "time", .field = PERF_OUTPUT_TIME},
  50. {.str = "cpu", .field = PERF_OUTPUT_CPU},
  51. {.str = "event", .field = PERF_OUTPUT_EVNAME},
  52. {.str = "trace", .field = PERF_OUTPUT_TRACE},
  53. {.str = "ip", .field = PERF_OUTPUT_IP},
  54. {.str = "sym", .field = PERF_OUTPUT_SYM},
  55. {.str = "dso", .field = PERF_OUTPUT_DSO},
  56. {.str = "addr", .field = PERF_OUTPUT_ADDR},
  57. {.str = "symoff", .field = PERF_OUTPUT_SYMOFFSET},
  58. };
  59. /* default set to maintain compatibility with current format */
  60. static struct {
  61. bool user_set;
  62. bool wildcard_set;
  63. u64 fields;
  64. u64 invalid_fields;
  65. } output[PERF_TYPE_MAX] = {
  66. [PERF_TYPE_HARDWARE] = {
  67. .user_set = false,
  68. .fields = PERF_OUTPUT_COMM | PERF_OUTPUT_TID |
  69. PERF_OUTPUT_CPU | PERF_OUTPUT_TIME |
  70. PERF_OUTPUT_EVNAME | PERF_OUTPUT_IP |
  71. PERF_OUTPUT_SYM | PERF_OUTPUT_DSO,
  72. .invalid_fields = PERF_OUTPUT_TRACE,
  73. },
  74. [PERF_TYPE_SOFTWARE] = {
  75. .user_set = false,
  76. .fields = PERF_OUTPUT_COMM | PERF_OUTPUT_TID |
  77. PERF_OUTPUT_CPU | PERF_OUTPUT_TIME |
  78. PERF_OUTPUT_EVNAME | PERF_OUTPUT_IP |
  79. PERF_OUTPUT_SYM | PERF_OUTPUT_DSO,
  80. .invalid_fields = PERF_OUTPUT_TRACE,
  81. },
  82. [PERF_TYPE_TRACEPOINT] = {
  83. .user_set = false,
  84. .fields = PERF_OUTPUT_COMM | PERF_OUTPUT_TID |
  85. PERF_OUTPUT_CPU | PERF_OUTPUT_TIME |
  86. PERF_OUTPUT_EVNAME | PERF_OUTPUT_TRACE,
  87. },
  88. [PERF_TYPE_RAW] = {
  89. .user_set = false,
  90. .fields = PERF_OUTPUT_COMM | PERF_OUTPUT_TID |
  91. PERF_OUTPUT_CPU | PERF_OUTPUT_TIME |
  92. PERF_OUTPUT_EVNAME | PERF_OUTPUT_IP |
  93. PERF_OUTPUT_SYM | PERF_OUTPUT_DSO,
  94. .invalid_fields = PERF_OUTPUT_TRACE,
  95. },
  96. };
  97. static bool output_set_by_user(void)
  98. {
  99. int j;
  100. for (j = 0; j < PERF_TYPE_MAX; ++j) {
  101. if (output[j].user_set)
  102. return true;
  103. }
  104. return false;
  105. }
  106. static const char *output_field2str(enum perf_output_field field)
  107. {
  108. int i, imax = ARRAY_SIZE(all_output_options);
  109. const char *str = "";
  110. for (i = 0; i < imax; ++i) {
  111. if (all_output_options[i].field == field) {
  112. str = all_output_options[i].str;
  113. break;
  114. }
  115. }
  116. return str;
  117. }
  118. #define PRINT_FIELD(x) (output[attr->type].fields & PERF_OUTPUT_##x)
  119. static int perf_event_attr__check_stype(struct perf_event_attr *attr,
  120. u64 sample_type, const char *sample_msg,
  121. enum perf_output_field field)
  122. {
  123. int type = attr->type;
  124. const char *evname;
  125. if (attr->sample_type & sample_type)
  126. return 0;
  127. if (output[type].user_set) {
  128. evname = __event_name(attr->type, attr->config, NULL);
  129. pr_err("Samples for '%s' event do not have %s attribute set. "
  130. "Cannot print '%s' field.\n",
  131. evname, sample_msg, output_field2str(field));
  132. return -1;
  133. }
  134. /* user did not ask for it explicitly so remove from the default list */
  135. output[type].fields &= ~field;
  136. evname = __event_name(attr->type, attr->config, NULL);
  137. pr_debug("Samples for '%s' event do not have %s attribute set. "
  138. "Skipping '%s' field.\n",
  139. evname, sample_msg, output_field2str(field));
  140. return 0;
  141. }
  142. static int perf_evsel__check_attr(struct perf_evsel *evsel,
  143. struct perf_session *session)
  144. {
  145. struct perf_event_attr *attr = &evsel->attr;
  146. if (PRINT_FIELD(TRACE) &&
  147. !perf_session__has_traces(session, "record -R"))
  148. return -EINVAL;
  149. if (PRINT_FIELD(IP)) {
  150. if (perf_event_attr__check_stype(attr, PERF_SAMPLE_IP, "IP",
  151. PERF_OUTPUT_IP))
  152. return -EINVAL;
  153. if (!no_callchain &&
  154. !(attr->sample_type & PERF_SAMPLE_CALLCHAIN))
  155. symbol_conf.use_callchain = false;
  156. }
  157. if (PRINT_FIELD(ADDR) &&
  158. perf_event_attr__check_stype(attr, PERF_SAMPLE_ADDR, "ADDR",
  159. PERF_OUTPUT_ADDR))
  160. return -EINVAL;
  161. if (PRINT_FIELD(SYM) && !PRINT_FIELD(IP) && !PRINT_FIELD(ADDR)) {
  162. pr_err("Display of symbols requested but neither sample IP nor "
  163. "sample address\nis selected. Hence, no addresses to convert "
  164. "to symbols.\n");
  165. return -EINVAL;
  166. }
  167. if (PRINT_FIELD(SYMOFFSET) && !PRINT_FIELD(SYM)) {
  168. pr_err("Display of offsets requested but symbol is not"
  169. "selected.\n");
  170. return -EINVAL;
  171. }
  172. if (PRINT_FIELD(DSO) && !PRINT_FIELD(IP) && !PRINT_FIELD(ADDR)) {
  173. pr_err("Display of DSO requested but neither sample IP nor "
  174. "sample address\nis selected. Hence, no addresses to convert "
  175. "to DSO.\n");
  176. return -EINVAL;
  177. }
  178. if ((PRINT_FIELD(PID) || PRINT_FIELD(TID)) &&
  179. perf_event_attr__check_stype(attr, PERF_SAMPLE_TID, "TID",
  180. PERF_OUTPUT_TID|PERF_OUTPUT_PID))
  181. return -EINVAL;
  182. if (PRINT_FIELD(TIME) &&
  183. perf_event_attr__check_stype(attr, PERF_SAMPLE_TIME, "TIME",
  184. PERF_OUTPUT_TIME))
  185. return -EINVAL;
  186. if (PRINT_FIELD(CPU) &&
  187. perf_event_attr__check_stype(attr, PERF_SAMPLE_CPU, "CPU",
  188. PERF_OUTPUT_CPU))
  189. return -EINVAL;
  190. return 0;
  191. }
  192. /*
  193. * verify all user requested events exist and the samples
  194. * have the expected data
  195. */
  196. static int perf_session__check_output_opt(struct perf_session *session)
  197. {
  198. int j;
  199. struct perf_evsel *evsel;
  200. for (j = 0; j < PERF_TYPE_MAX; ++j) {
  201. evsel = perf_session__find_first_evtype(session, j);
  202. /*
  203. * even if fields is set to 0 (ie., show nothing) event must
  204. * exist if user explicitly includes it on the command line
  205. */
  206. if (!evsel && output[j].user_set && !output[j].wildcard_set) {
  207. pr_err("%s events do not exist. "
  208. "Remove corresponding -f option to proceed.\n",
  209. event_type(j));
  210. return -1;
  211. }
  212. if (evsel && output[j].fields &&
  213. perf_evsel__check_attr(evsel, session))
  214. return -1;
  215. }
  216. return 0;
  217. }
  218. static void print_sample_start(struct perf_sample *sample,
  219. struct thread *thread,
  220. struct perf_event_attr *attr)
  221. {
  222. int type;
  223. struct event *event;
  224. const char *evname = NULL;
  225. unsigned long secs;
  226. unsigned long usecs;
  227. unsigned long long nsecs;
  228. if (PRINT_FIELD(COMM)) {
  229. if (latency_format)
  230. printf("%8.8s ", thread->comm);
  231. else if (PRINT_FIELD(IP) && symbol_conf.use_callchain)
  232. printf("%s ", thread->comm);
  233. else
  234. printf("%16s ", thread->comm);
  235. }
  236. if (PRINT_FIELD(PID) && PRINT_FIELD(TID))
  237. printf("%5d/%-5d ", sample->pid, sample->tid);
  238. else if (PRINT_FIELD(PID))
  239. printf("%5d ", sample->pid);
  240. else if (PRINT_FIELD(TID))
  241. printf("%5d ", sample->tid);
  242. if (PRINT_FIELD(CPU)) {
  243. if (latency_format)
  244. printf("%3d ", sample->cpu);
  245. else
  246. printf("[%03d] ", sample->cpu);
  247. }
  248. if (PRINT_FIELD(TIME)) {
  249. nsecs = sample->time;
  250. secs = nsecs / NSECS_PER_SEC;
  251. nsecs -= secs * NSECS_PER_SEC;
  252. usecs = nsecs / NSECS_PER_USEC;
  253. printf("%5lu.%06lu: ", secs, usecs);
  254. }
  255. if (PRINT_FIELD(EVNAME)) {
  256. if (attr->type == PERF_TYPE_TRACEPOINT) {
  257. type = trace_parse_common_type(sample->raw_data);
  258. event = trace_find_event(type);
  259. if (event)
  260. evname = event->name;
  261. } else
  262. evname = __event_name(attr->type, attr->config, NULL);
  263. printf("%s: ", evname ? evname : "[unknown]");
  264. }
  265. }
  266. static bool is_bts_event(struct perf_event_attr *attr)
  267. {
  268. return ((attr->type == PERF_TYPE_HARDWARE) &&
  269. (attr->config & PERF_COUNT_HW_BRANCH_INSTRUCTIONS) &&
  270. (attr->sample_period == 1));
  271. }
  272. static bool sample_addr_correlates_sym(struct perf_event_attr *attr)
  273. {
  274. if ((attr->type == PERF_TYPE_SOFTWARE) &&
  275. ((attr->config == PERF_COUNT_SW_PAGE_FAULTS) ||
  276. (attr->config == PERF_COUNT_SW_PAGE_FAULTS_MIN) ||
  277. (attr->config == PERF_COUNT_SW_PAGE_FAULTS_MAJ)))
  278. return true;
  279. if (is_bts_event(attr))
  280. return true;
  281. return false;
  282. }
  283. static void print_sample_addr(union perf_event *event,
  284. struct perf_sample *sample,
  285. struct machine *machine,
  286. struct thread *thread,
  287. struct perf_event_attr *attr)
  288. {
  289. struct addr_location al;
  290. u8 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
  291. printf("%16" PRIx64, sample->addr);
  292. if (!sample_addr_correlates_sym(attr))
  293. return;
  294. thread__find_addr_map(thread, machine, cpumode, MAP__FUNCTION,
  295. sample->addr, &al);
  296. if (!al.map)
  297. thread__find_addr_map(thread, machine, cpumode, MAP__VARIABLE,
  298. sample->addr, &al);
  299. al.cpu = sample->cpu;
  300. al.sym = NULL;
  301. if (al.map)
  302. al.sym = map__find_symbol(al.map, al.addr, NULL);
  303. if (PRINT_FIELD(SYM)) {
  304. printf(" ");
  305. if (PRINT_FIELD(SYMOFFSET))
  306. symbol__fprintf_symname_offs(al.sym, &al, stdout);
  307. else
  308. symbol__fprintf_symname(al.sym, stdout);
  309. }
  310. if (PRINT_FIELD(DSO)) {
  311. printf(" (");
  312. map__fprintf_dsoname(al.map, stdout);
  313. printf(")");
  314. }
  315. }
  316. static void print_sample_bts(union perf_event *event,
  317. struct perf_sample *sample,
  318. struct perf_evsel *evsel,
  319. struct machine *machine,
  320. struct thread *thread)
  321. {
  322. struct perf_event_attr *attr = &evsel->attr;
  323. /* print branch_from information */
  324. if (PRINT_FIELD(IP)) {
  325. if (!symbol_conf.use_callchain)
  326. printf(" ");
  327. else
  328. printf("\n");
  329. perf_event__print_ip(event, sample, machine, evsel,
  330. PRINT_FIELD(SYM), PRINT_FIELD(DSO),
  331. PRINT_FIELD(SYMOFFSET));
  332. }
  333. printf(" => ");
  334. /* print branch_to information */
  335. if (PRINT_FIELD(ADDR))
  336. print_sample_addr(event, sample, machine, thread, attr);
  337. printf("\n");
  338. }
  339. static void process_event(union perf_event *event __unused,
  340. struct perf_sample *sample,
  341. struct perf_evsel *evsel,
  342. struct machine *machine,
  343. struct thread *thread)
  344. {
  345. struct perf_event_attr *attr = &evsel->attr;
  346. if (output[attr->type].fields == 0)
  347. return;
  348. print_sample_start(sample, thread, attr);
  349. if (is_bts_event(attr)) {
  350. print_sample_bts(event, sample, evsel, machine, thread);
  351. return;
  352. }
  353. if (PRINT_FIELD(TRACE))
  354. print_trace_event(sample->cpu, sample->raw_data,
  355. sample->raw_size);
  356. if (PRINT_FIELD(ADDR))
  357. print_sample_addr(event, sample, machine, thread, attr);
  358. if (PRINT_FIELD(IP)) {
  359. if (!symbol_conf.use_callchain)
  360. printf(" ");
  361. else
  362. printf("\n");
  363. perf_event__print_ip(event, sample, machine, evsel,
  364. PRINT_FIELD(SYM), PRINT_FIELD(DSO),
  365. PRINT_FIELD(SYMOFFSET));
  366. }
  367. printf("\n");
  368. }
  369. static int default_start_script(const char *script __unused,
  370. int argc __unused,
  371. const char **argv __unused)
  372. {
  373. return 0;
  374. }
  375. static int default_stop_script(void)
  376. {
  377. return 0;
  378. }
  379. static int default_generate_script(const char *outfile __unused)
  380. {
  381. return 0;
  382. }
  383. static struct scripting_ops default_scripting_ops = {
  384. .start_script = default_start_script,
  385. .stop_script = default_stop_script,
  386. .process_event = process_event,
  387. .generate_script = default_generate_script,
  388. };
  389. static struct scripting_ops *scripting_ops;
  390. static void setup_scripting(void)
  391. {
  392. setup_perl_scripting();
  393. setup_python_scripting();
  394. setup_json_export();
  395. scripting_ops = &default_scripting_ops;
  396. }
  397. static int cleanup_scripting(void)
  398. {
  399. pr_debug("\nperf script stopped\n");
  400. return scripting_ops->stop_script();
  401. }
  402. static const char *input_name;
  403. static int process_sample_event(struct perf_tool *tool __used,
  404. union perf_event *event,
  405. struct perf_sample *sample,
  406. struct perf_evsel *evsel,
  407. struct machine *machine)
  408. {
  409. struct addr_location al;
  410. struct thread *thread = machine__findnew_thread(machine, event->ip.tid);
  411. if (thread == NULL) {
  412. pr_debug("problem processing %d event, skipping it.\n",
  413. event->header.type);
  414. return -1;
  415. }
  416. if (debug_mode) {
  417. if (sample->time < last_timestamp) {
  418. pr_err("Samples misordered, previous: %" PRIu64
  419. " this: %" PRIu64 "\n", last_timestamp,
  420. sample->time);
  421. nr_unordered++;
  422. }
  423. last_timestamp = sample->time;
  424. return 0;
  425. }
  426. if (perf_event__preprocess_sample(event, machine, &al, sample, 0) < 0) {
  427. pr_err("problem processing %d event, skipping it.\n",
  428. event->header.type);
  429. return -1;
  430. }
  431. if (al.filtered)
  432. return 0;
  433. if (cpu_list && !test_bit(sample->cpu, cpu_bitmap))
  434. return 0;
  435. scripting_ops->process_event(event, sample, evsel, machine, thread);
  436. evsel->hists.stats.total_period += sample->period;
  437. return 0;
  438. }
  439. static struct perf_tool perf_script = {
  440. .sample = process_sample_event,
  441. .mmap = perf_event__process_mmap,
  442. .comm = perf_event__process_comm,
  443. .exit = perf_event__process_task,
  444. .fork = perf_event__process_task,
  445. .attr = perf_event__process_attr,
  446. .event_type = perf_event__process_event_type,
  447. .tracing_data = perf_event__process_tracing_data,
  448. .build_id = perf_event__process_build_id,
  449. .ordered_samples = true,
  450. .ordering_requires_timestamps = true,
  451. };
  452. extern volatile int session_done;
  453. static void sig_handler(int sig __unused)
  454. {
  455. session_done = 1;
  456. }
  457. static int __cmd_script(struct perf_session *session)
  458. {
  459. int ret;
  460. signal(SIGINT, sig_handler);
  461. ret = perf_session__process_events(session, &perf_script);
  462. if (debug_mode)
  463. pr_err("Misordered timestamps: %" PRIu64 "\n", nr_unordered);
  464. return ret;
  465. }
  466. struct script_spec {
  467. struct list_head node;
  468. struct scripting_ops *ops;
  469. char spec[0];
  470. };
  471. static LIST_HEAD(script_specs);
  472. static struct script_spec *script_spec__new(const char *spec,
  473. struct scripting_ops *ops)
  474. {
  475. struct script_spec *s = malloc(sizeof(*s) + strlen(spec) + 1);
  476. if (s != NULL) {
  477. strcpy(s->spec, spec);
  478. s->ops = ops;
  479. }
  480. return s;
  481. }
  482. static void script_spec__add(struct script_spec *s)
  483. {
  484. list_add_tail(&s->node, &script_specs);
  485. }
  486. static struct script_spec *script_spec__find(const char *spec)
  487. {
  488. struct script_spec *s;
  489. list_for_each_entry(s, &script_specs, node)
  490. if (strcasecmp(s->spec, spec) == 0)
  491. return s;
  492. return NULL;
  493. }
  494. static struct script_spec *script_spec__findnew(const char *spec,
  495. struct scripting_ops *ops)
  496. {
  497. struct script_spec *s = script_spec__find(spec);
  498. if (s)
  499. return s;
  500. s = script_spec__new(spec, ops);
  501. if (!s)
  502. return NULL;
  503. script_spec__add(s);
  504. return s;
  505. }
  506. int script_spec_register(const char *spec, struct scripting_ops *ops)
  507. {
  508. struct script_spec *s;
  509. s = script_spec__find(spec);
  510. if (s)
  511. return -1;
  512. s = script_spec__findnew(spec, ops);
  513. if (!s)
  514. return -1;
  515. return 0;
  516. }
  517. static struct scripting_ops *script_spec__lookup(const char *spec)
  518. {
  519. struct script_spec *s = script_spec__find(spec);
  520. if (!s)
  521. return NULL;
  522. return s->ops;
  523. }
  524. static void list_available_languages(void)
  525. {
  526. struct script_spec *s;
  527. fprintf(stderr, "\n");
  528. fprintf(stderr, "Scripting language extensions (used in "
  529. "perf script -s [spec:]script.[spec]):\n\n");
  530. list_for_each_entry(s, &script_specs, node)
  531. fprintf(stderr, " %-42s [%s]\n", s->spec, s->ops->name);
  532. fprintf(stderr, "\n");
  533. }
  534. static int parse_scriptname(const struct option *opt __used,
  535. const char *str, int unset __used)
  536. {
  537. char spec[PATH_MAX];
  538. const char *script, *ext;
  539. int len;
  540. if (strcmp(str, "lang") == 0) {
  541. list_available_languages();
  542. exit(0);
  543. }
  544. script = strchr(str, ':');
  545. if (script) {
  546. len = script - str;
  547. if (len >= PATH_MAX) {
  548. fprintf(stderr, "invalid language specifier");
  549. return -1;
  550. }
  551. strncpy(spec, str, len);
  552. spec[len] = '\0';
  553. scripting_ops = script_spec__lookup(spec);
  554. if (!scripting_ops) {
  555. fprintf(stderr, "invalid language specifier");
  556. return -1;
  557. }
  558. script++;
  559. } else {
  560. script = str;
  561. ext = strrchr(script, '.');
  562. if (!ext) {
  563. fprintf(stderr, "invalid script extension");
  564. return -1;
  565. }
  566. scripting_ops = script_spec__lookup(++ext);
  567. if (!scripting_ops) {
  568. fprintf(stderr, "invalid script extension");
  569. return -1;
  570. }
  571. }
  572. script_name = strdup(script);
  573. return 0;
  574. }
  575. static int parse_output_fields(const struct option *opt __used,
  576. const char *arg, int unset __used)
  577. {
  578. char *tok;
  579. int i, imax = sizeof(all_output_options) / sizeof(struct output_option);
  580. int j;
  581. int rc = 0;
  582. char *str = strdup(arg);
  583. int type = -1;
  584. if (!str)
  585. return -ENOMEM;
  586. /* first word can state for which event type the user is specifying
  587. * the fields. If no type exists, the specified fields apply to all
  588. * event types found in the file minus the invalid fields for a type.
  589. */
  590. tok = strchr(str, ':');
  591. if (tok) {
  592. *tok = '\0';
  593. tok++;
  594. if (!strcmp(str, "hw"))
  595. type = PERF_TYPE_HARDWARE;
  596. else if (!strcmp(str, "sw"))
  597. type = PERF_TYPE_SOFTWARE;
  598. else if (!strcmp(str, "trace"))
  599. type = PERF_TYPE_TRACEPOINT;
  600. else if (!strcmp(str, "raw"))
  601. type = PERF_TYPE_RAW;
  602. else {
  603. fprintf(stderr, "Invalid event type in field string.\n");
  604. rc = -EINVAL;
  605. goto out;
  606. }
  607. if (output[type].user_set)
  608. pr_warning("Overriding previous field request for %s events.\n",
  609. event_type(type));
  610. output[type].fields = 0;
  611. output[type].user_set = true;
  612. output[type].wildcard_set = false;
  613. } else {
  614. tok = str;
  615. if (strlen(str) == 0) {
  616. fprintf(stderr,
  617. "Cannot set fields to 'none' for all event types.\n");
  618. rc = -EINVAL;
  619. goto out;
  620. }
  621. if (output_set_by_user())
  622. pr_warning("Overriding previous field request for all events.\n");
  623. for (j = 0; j < PERF_TYPE_MAX; ++j) {
  624. output[j].fields = 0;
  625. output[j].user_set = true;
  626. output[j].wildcard_set = true;
  627. }
  628. }
  629. tok = strtok(tok, ",");
  630. while (tok) {
  631. for (i = 0; i < imax; ++i) {
  632. if (strcmp(tok, all_output_options[i].str) == 0)
  633. break;
  634. }
  635. if (i == imax) {
  636. fprintf(stderr, "Invalid field requested.\n");
  637. rc = -EINVAL;
  638. goto out;
  639. }
  640. if (type == -1) {
  641. /* add user option to all events types for
  642. * which it is valid
  643. */
  644. for (j = 0; j < PERF_TYPE_MAX; ++j) {
  645. if (output[j].invalid_fields & all_output_options[i].field) {
  646. pr_warning("\'%s\' not valid for %s events. Ignoring.\n",
  647. all_output_options[i].str, event_type(j));
  648. } else
  649. output[j].fields |= all_output_options[i].field;
  650. }
  651. } else {
  652. if (output[type].invalid_fields & all_output_options[i].field) {
  653. fprintf(stderr, "\'%s\' not valid for %s events.\n",
  654. all_output_options[i].str, event_type(type));
  655. rc = -EINVAL;
  656. goto out;
  657. }
  658. output[type].fields |= all_output_options[i].field;
  659. }
  660. tok = strtok(NULL, ",");
  661. }
  662. if (type >= 0) {
  663. if (output[type].fields == 0) {
  664. pr_debug("No fields requested for %s type. "
  665. "Events will not be displayed.\n", event_type(type));
  666. }
  667. }
  668. out:
  669. free(str);
  670. return rc;
  671. }
  672. /* Helper function for filesystems that return a dent->d_type DT_UNKNOWN */
  673. static int is_directory(const char *base_path, const struct dirent *dent)
  674. {
  675. char path[PATH_MAX];
  676. struct stat st;
  677. sprintf(path, "%s/%s", base_path, dent->d_name);
  678. if (stat(path, &st))
  679. return 0;
  680. return S_ISDIR(st.st_mode);
  681. }
  682. #define for_each_lang(scripts_path, scripts_dir, lang_dirent, lang_next)\
  683. while (!readdir_r(scripts_dir, &lang_dirent, &lang_next) && \
  684. lang_next) \
  685. if ((lang_dirent.d_type == DT_DIR || \
  686. (lang_dirent.d_type == DT_UNKNOWN && \
  687. is_directory(scripts_path, &lang_dirent))) && \
  688. (strcmp(lang_dirent.d_name, ".")) && \
  689. (strcmp(lang_dirent.d_name, "..")))
  690. #define for_each_script(lang_path, lang_dir, script_dirent, script_next)\
  691. while (!readdir_r(lang_dir, &script_dirent, &script_next) && \
  692. script_next) \
  693. if (script_dirent.d_type != DT_DIR && \
  694. (script_dirent.d_type != DT_UNKNOWN || \
  695. !is_directory(lang_path, &script_dirent)))
  696. #define RECORD_SUFFIX "-record"
  697. #define REPORT_SUFFIX "-report"
  698. struct script_desc {
  699. struct list_head node;
  700. char *name;
  701. char *half_liner;
  702. char *args;
  703. };
  704. static LIST_HEAD(script_descs);
  705. static struct script_desc *script_desc__new(const char *name)
  706. {
  707. struct script_desc *s = zalloc(sizeof(*s));
  708. if (s != NULL && name)
  709. s->name = strdup(name);
  710. return s;
  711. }
  712. static void script_desc__delete(struct script_desc *s)
  713. {
  714. free(s->name);
  715. free(s->half_liner);
  716. free(s->args);
  717. free(s);
  718. }
  719. static void script_desc__add(struct script_desc *s)
  720. {
  721. list_add_tail(&s->node, &script_descs);
  722. }
  723. static struct script_desc *script_desc__find(const char *name)
  724. {
  725. struct script_desc *s;
  726. list_for_each_entry(s, &script_descs, node)
  727. if (strcasecmp(s->name, name) == 0)
  728. return s;
  729. return NULL;
  730. }
  731. static struct script_desc *script_desc__findnew(const char *name)
  732. {
  733. struct script_desc *s = script_desc__find(name);
  734. if (s)
  735. return s;
  736. s = script_desc__new(name);
  737. if (!s)
  738. goto out_delete_desc;
  739. script_desc__add(s);
  740. return s;
  741. out_delete_desc:
  742. script_desc__delete(s);
  743. return NULL;
  744. }
  745. static const char *ends_with(const char *str, const char *suffix)
  746. {
  747. size_t suffix_len = strlen(suffix);
  748. const char *p = str;
  749. if (strlen(str) > suffix_len) {
  750. p = str + strlen(str) - suffix_len;
  751. if (!strncmp(p, suffix, suffix_len))
  752. return p;
  753. }
  754. return NULL;
  755. }
  756. static char *ltrim(char *str)
  757. {
  758. int len = strlen(str);
  759. while (len && isspace(*str)) {
  760. len--;
  761. str++;
  762. }
  763. return str;
  764. }
  765. static int read_script_info(struct script_desc *desc, const char *filename)
  766. {
  767. char line[BUFSIZ], *p;
  768. FILE *fp;
  769. fp = fopen(filename, "r");
  770. if (!fp)
  771. return -1;
  772. while (fgets(line, sizeof(line), fp)) {
  773. p = ltrim(line);
  774. if (strlen(p) == 0)
  775. continue;
  776. if (*p != '#')
  777. continue;
  778. p++;
  779. if (strlen(p) && *p == '!')
  780. continue;
  781. p = ltrim(p);
  782. if (strlen(p) && p[strlen(p) - 1] == '\n')
  783. p[strlen(p) - 1] = '\0';
  784. if (!strncmp(p, "description:", strlen("description:"))) {
  785. p += strlen("description:");
  786. desc->half_liner = strdup(ltrim(p));
  787. continue;
  788. }
  789. if (!strncmp(p, "args:", strlen("args:"))) {
  790. p += strlen("args:");
  791. desc->args = strdup(ltrim(p));
  792. continue;
  793. }
  794. }
  795. fclose(fp);
  796. return 0;
  797. }
  798. static char *get_script_root(struct dirent *script_dirent, const char *suffix)
  799. {
  800. char *script_root, *str;
  801. script_root = strdup(script_dirent->d_name);
  802. if (!script_root)
  803. return NULL;
  804. str = (char *)ends_with(script_root, suffix);
  805. if (!str) {
  806. free(script_root);
  807. return NULL;
  808. }
  809. *str = '\0';
  810. return script_root;
  811. }
  812. static int list_available_scripts(const struct option *opt __used,
  813. const char *s __used, int unset __used)
  814. {
  815. struct dirent *script_next, *lang_next, script_dirent, lang_dirent;
  816. char scripts_path[MAXPATHLEN];
  817. DIR *scripts_dir, *lang_dir;
  818. char script_path[MAXPATHLEN];
  819. char lang_path[MAXPATHLEN];
  820. struct script_desc *desc;
  821. char first_half[BUFSIZ];
  822. char *script_root;
  823. snprintf(scripts_path, MAXPATHLEN, "%s/scripts", perf_exec_path());
  824. scripts_dir = opendir(scripts_path);
  825. if (!scripts_dir)
  826. return -1;
  827. for_each_lang(scripts_path, scripts_dir, lang_dirent, lang_next) {
  828. snprintf(lang_path, MAXPATHLEN, "%s/%s/bin", scripts_path,
  829. lang_dirent.d_name);
  830. lang_dir = opendir(lang_path);
  831. if (!lang_dir)
  832. continue;
  833. for_each_script(lang_path, lang_dir, script_dirent, script_next) {
  834. script_root = get_script_root(&script_dirent, REPORT_SUFFIX);
  835. if (script_root) {
  836. desc = script_desc__findnew(script_root);
  837. snprintf(script_path, MAXPATHLEN, "%s/%s",
  838. lang_path, script_dirent.d_name);
  839. read_script_info(desc, script_path);
  840. free(script_root);
  841. }
  842. }
  843. }
  844. fprintf(stdout, "List of available trace scripts:\n");
  845. list_for_each_entry(desc, &script_descs, node) {
  846. sprintf(first_half, "%s %s", desc->name,
  847. desc->args ? desc->args : "");
  848. fprintf(stdout, " %-36s %s\n", first_half,
  849. desc->half_liner ? desc->half_liner : "");
  850. }
  851. exit(0);
  852. }
  853. static char *get_script_path(const char *script_root, const char *suffix)
  854. {
  855. struct dirent *script_next, *lang_next, script_dirent, lang_dirent;
  856. char scripts_path[MAXPATHLEN];
  857. char script_path[MAXPATHLEN];
  858. DIR *scripts_dir, *lang_dir;
  859. char lang_path[MAXPATHLEN];
  860. char *__script_root;
  861. snprintf(scripts_path, MAXPATHLEN, "%s/scripts", perf_exec_path());
  862. scripts_dir = opendir(scripts_path);
  863. if (!scripts_dir)
  864. return NULL;
  865. for_each_lang(scripts_path, scripts_dir, lang_dirent, lang_next) {
  866. snprintf(lang_path, MAXPATHLEN, "%s/%s/bin", scripts_path,
  867. lang_dirent.d_name);
  868. lang_dir = opendir(lang_path);
  869. if (!lang_dir)
  870. continue;
  871. for_each_script(lang_path, lang_dir, script_dirent, script_next) {
  872. __script_root = get_script_root(&script_dirent, suffix);
  873. if (__script_root && !strcmp(script_root, __script_root)) {
  874. free(__script_root);
  875. closedir(lang_dir);
  876. closedir(scripts_dir);
  877. snprintf(script_path, MAXPATHLEN, "%s/%s",
  878. lang_path, script_dirent.d_name);
  879. return strdup(script_path);
  880. }
  881. free(__script_root);
  882. }
  883. closedir(lang_dir);
  884. }
  885. closedir(scripts_dir);
  886. return NULL;
  887. }
  888. static bool is_top_script(const char *script_path)
  889. {
  890. return ends_with(script_path, "top") == NULL ? false : true;
  891. }
  892. static int has_required_arg(char *script_path)
  893. {
  894. struct script_desc *desc;
  895. int n_args = 0;
  896. char *p;
  897. desc = script_desc__new(NULL);
  898. if (read_script_info(desc, script_path))
  899. goto out;
  900. if (!desc->args)
  901. goto out;
  902. for (p = desc->args; *p; p++)
  903. if (*p == '<')
  904. n_args++;
  905. out:
  906. script_desc__delete(desc);
  907. return n_args;
  908. }
  909. static const char * const script_usage[] = {
  910. "perf script [<options>]",
  911. "perf script [<options>] record <script> [<record-options>] <command>",
  912. "perf script [<options>] report <script> [script-args]",
  913. "perf script [<options>] <script> [<record-options>] <command>",
  914. "perf script [<options>] <top-script> [script-args]",
  915. NULL
  916. };
  917. static const struct option options[] = {
  918. OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace,
  919. "dump raw trace in ASCII"),
  920. OPT_INCR('v', "verbose", &verbose,
  921. "be more verbose (show symbol address, etc)"),
  922. OPT_BOOLEAN('L', "Latency", &latency_format,
  923. "show latency attributes (irqs/preemption disabled, etc)"),
  924. OPT_CALLBACK_NOOPT('l', "list", NULL, NULL, "list available scripts",
  925. list_available_scripts),
  926. OPT_CALLBACK('s', "script", NULL, "name",
  927. "script file name (lang:script name, script name, or *)",
  928. parse_scriptname),
  929. OPT_STRING('g', "gen-script", &generate_script_lang, "lang",
  930. "generate perf-script.xx script in specified language"),
  931. OPT_STRING('i', "input", &input_name, "file",
  932. "input file name"),
  933. OPT_BOOLEAN('d', "debug-mode", &debug_mode,
  934. "do various checks like samples ordering and lost events"),
  935. OPT_STRING('k', "vmlinux", &symbol_conf.vmlinux_name,
  936. "file", "vmlinux pathname"),
  937. OPT_STRING(0, "kallsyms", &symbol_conf.kallsyms_name,
  938. "file", "kallsyms pathname"),
  939. OPT_BOOLEAN('G', "hide-call-graph", &no_callchain,
  940. "When printing symbols do not display call chain"),
  941. OPT_STRING(0, "symfs", &symbol_conf.symfs, "directory",
  942. "Look for files with symbols relative to this directory"),
  943. OPT_CALLBACK('f', "fields", NULL, "str",
  944. "comma separated output fields prepend with 'type:'. "
  945. "Valid types: hw,sw,trace,raw. "
  946. "Fields: comm,tid,pid,time,cpu,event,trace,ip,sym,dso,"
  947. "addr,symoff",
  948. parse_output_fields),
  949. OPT_BOOLEAN('a', "all-cpus", &system_wide,
  950. "system-wide collection from all CPUs"),
  951. OPT_STRING('C', "cpu", &cpu_list, "cpu", "list of cpus to profile"),
  952. OPT_STRING('c', "comms", &symbol_conf.comm_list_str, "comm[,comm...]",
  953. "only display events for these comms"),
  954. OPT_BOOLEAN('I', "show-info", &show_full_info,
  955. "display extended information from perf.data file"),
  956. OPT_BOOLEAN('\0', "show-kernel-path", &symbol_conf.show_kernel_path,
  957. "Show the path of [kernel.kallsyms]"),
  958. OPT_END()
  959. };
  960. static bool have_cmd(int argc, const char **argv)
  961. {
  962. char **__argv = malloc(sizeof(const char *) * argc);
  963. if (!__argv)
  964. die("malloc");
  965. memcpy(__argv, argv, sizeof(const char *) * argc);
  966. argc = parse_options(argc, (const char **)__argv, record_options,
  967. NULL, PARSE_OPT_STOP_AT_NON_OPTION);
  968. free(__argv);
  969. return argc != 0;
  970. }
  971. int cmd_script(int argc, const char **argv, const char *prefix __used)
  972. {
  973. char *rec_script_path = NULL;
  974. char *rep_script_path = NULL;
  975. struct perf_session *session;
  976. char *script_path = NULL;
  977. const char **__argv;
  978. int i, j, err;
  979. setup_scripting();
  980. argc = parse_options(argc, argv, options, script_usage,
  981. PARSE_OPT_STOP_AT_NON_OPTION);
  982. if (argc > 1 && !strncmp(argv[0], "rec", strlen("rec"))) {
  983. rec_script_path = get_script_path(argv[1], RECORD_SUFFIX);
  984. if (!rec_script_path)
  985. return cmd_record(argc, argv, NULL);
  986. }
  987. if (argc > 1 && !strncmp(argv[0], "rep", strlen("rep"))) {
  988. rep_script_path = get_script_path(argv[1], REPORT_SUFFIX);
  989. if (!rep_script_path) {
  990. fprintf(stderr,
  991. "Please specify a valid report script"
  992. "(see 'perf script -l' for listing)\n");
  993. return -1;
  994. }
  995. }
  996. /* make sure PERF_EXEC_PATH is set for scripts */
  997. perf_set_argv_exec_path(perf_exec_path());
  998. if (argc && !script_name && !rec_script_path && !rep_script_path) {
  999. int live_pipe[2];
  1000. int rep_args;
  1001. pid_t pid;
  1002. rec_script_path = get_script_path(argv[0], RECORD_SUFFIX);
  1003. rep_script_path = get_script_path(argv[0], REPORT_SUFFIX);
  1004. if (!rec_script_path && !rep_script_path) {
  1005. fprintf(stderr, " Couldn't find script %s\n\n See perf"
  1006. " script -l for available scripts.\n", argv[0]);
  1007. usage_with_options(script_usage, options);
  1008. }
  1009. if (is_top_script(argv[0])) {
  1010. rep_args = argc - 1;
  1011. } else {
  1012. int rec_args;
  1013. rep_args = has_required_arg(rep_script_path);
  1014. rec_args = (argc - 1) - rep_args;
  1015. if (rec_args < 0) {
  1016. fprintf(stderr, " %s script requires options."
  1017. "\n\n See perf script -l for available "
  1018. "scripts and options.\n", argv[0]);
  1019. usage_with_options(script_usage, options);
  1020. }
  1021. }
  1022. if (pipe(live_pipe) < 0) {
  1023. perror("failed to create pipe");
  1024. exit(-1);
  1025. }
  1026. pid = fork();
  1027. if (pid < 0) {
  1028. perror("failed to fork");
  1029. exit(-1);
  1030. }
  1031. if (!pid) {
  1032. j = 0;
  1033. dup2(live_pipe[1], 1);
  1034. close(live_pipe[0]);
  1035. if (is_top_script(argv[0])) {
  1036. system_wide = true;
  1037. } else if (!system_wide) {
  1038. system_wide = !have_cmd(argc - rep_args,
  1039. &argv[rep_args]);
  1040. }
  1041. __argv = malloc((argc + 6) * sizeof(const char *));
  1042. if (!__argv)
  1043. die("malloc");
  1044. __argv[j++] = "/bin/sh";
  1045. __argv[j++] = rec_script_path;
  1046. if (system_wide)
  1047. __argv[j++] = "-a";
  1048. __argv[j++] = "-q";
  1049. __argv[j++] = "-o";
  1050. __argv[j++] = "-";
  1051. for (i = rep_args + 1; i < argc; i++)
  1052. __argv[j++] = argv[i];
  1053. __argv[j++] = NULL;
  1054. execvp("/bin/sh", (char **)__argv);
  1055. free(__argv);
  1056. exit(-1);
  1057. }
  1058. dup2(live_pipe[0], 0);
  1059. close(live_pipe[1]);
  1060. __argv = malloc((argc + 4) * sizeof(const char *));
  1061. if (!__argv)
  1062. die("malloc");
  1063. j = 0;
  1064. __argv[j++] = "/bin/sh";
  1065. __argv[j++] = rep_script_path;
  1066. for (i = 1; i < rep_args + 1; i++)
  1067. __argv[j++] = argv[i];
  1068. __argv[j++] = "-i";
  1069. __argv[j++] = "-";
  1070. __argv[j++] = NULL;
  1071. execvp("/bin/sh", (char **)__argv);
  1072. free(__argv);
  1073. exit(-1);
  1074. }
  1075. if (rec_script_path)
  1076. script_path = rec_script_path;
  1077. if (rep_script_path)
  1078. script_path = rep_script_path;
  1079. if (script_path) {
  1080. j = 0;
  1081. if (!rec_script_path)
  1082. system_wide = false;
  1083. else if (!system_wide)
  1084. system_wide = !have_cmd(argc - 1, &argv[1]);
  1085. __argv = malloc((argc + 2) * sizeof(const char *));
  1086. if (!__argv)
  1087. die("malloc");
  1088. __argv[j++] = "/bin/sh";
  1089. __argv[j++] = script_path;
  1090. if (system_wide)
  1091. __argv[j++] = "-a";
  1092. for (i = 2; i < argc; i++)
  1093. __argv[j++] = argv[i];
  1094. __argv[j++] = NULL;
  1095. execvp("/bin/sh", (char **)__argv);
  1096. free(__argv);
  1097. exit(-1);
  1098. }
  1099. if (symbol__init() < 0)
  1100. return -1;
  1101. if (!script_name)
  1102. setup_pager();
  1103. session = perf_session__new(input_name, O_RDONLY, 0, false, &perf_script);
  1104. if (session == NULL)
  1105. return -ENOMEM;
  1106. if (cpu_list) {
  1107. if (perf_session__cpu_bitmap(session, cpu_list, cpu_bitmap))
  1108. return -1;
  1109. }
  1110. perf_session__fprintf_info(session, stdout, show_full_info);
  1111. if (!no_callchain)
  1112. symbol_conf.use_callchain = true;
  1113. else
  1114. symbol_conf.use_callchain = false;
  1115. if (generate_script_lang) {
  1116. struct stat perf_stat;
  1117. int input;
  1118. if (output_set_by_user()) {
  1119. fprintf(stderr,
  1120. "custom fields not supported for generated scripts");
  1121. return -1;
  1122. }
  1123. input = open(session->filename, O_RDONLY); /* input_name */
  1124. if (input < 0) {
  1125. perror("failed to open file");
  1126. exit(-1);
  1127. }
  1128. err = fstat(input, &perf_stat);
  1129. if (err < 0) {
  1130. perror("failed to stat file");
  1131. exit(-1);
  1132. }
  1133. if (!perf_stat.st_size) {
  1134. fprintf(stderr, "zero-sized file, nothing to do!\n");
  1135. exit(0);
  1136. }
  1137. scripting_ops = script_spec__lookup(generate_script_lang);
  1138. if (!scripting_ops) {
  1139. fprintf(stderr, "invalid language specifier");
  1140. return -1;
  1141. }
  1142. err = scripting_ops->generate_script("perf-script");
  1143. goto out;
  1144. }
  1145. if (script_name) {
  1146. err = scripting_ops->start_script(script_name, argc, argv);
  1147. if (err)
  1148. goto out;
  1149. pr_debug("perf script started with script %s\n\n", script_name);
  1150. }
  1151. err = perf_session__check_output_opt(session);
  1152. if (err < 0)
  1153. goto out;
  1154. err = __cmd_script(session);
  1155. perf_session__delete(session);
  1156. cleanup_scripting();
  1157. out:
  1158. return err;
  1159. }