builtin-script.c 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409
  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);
  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);
  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);
  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. scripting_ops = &default_scripting_ops;
  395. }
  396. static int cleanup_scripting(void)
  397. {
  398. pr_debug("\nperf script stopped\n");
  399. return scripting_ops->stop_script();
  400. }
  401. static const char *input_name;
  402. static int process_sample_event(struct perf_tool *tool __used,
  403. union perf_event *event,
  404. struct perf_sample *sample,
  405. struct perf_evsel *evsel,
  406. struct machine *machine)
  407. {
  408. struct addr_location al;
  409. struct thread *thread = machine__findnew_thread(machine, event->ip.tid);
  410. if (thread == NULL) {
  411. pr_debug("problem processing %d event, skipping it.\n",
  412. event->header.type);
  413. return -1;
  414. }
  415. if (debug_mode) {
  416. if (sample->time < last_timestamp) {
  417. pr_err("Samples misordered, previous: %" PRIu64
  418. " this: %" PRIu64 "\n", last_timestamp,
  419. sample->time);
  420. nr_unordered++;
  421. }
  422. last_timestamp = sample->time;
  423. return 0;
  424. }
  425. if (perf_event__preprocess_sample(event, machine, &al, sample, 0) < 0) {
  426. pr_err("problem processing %d event, skipping it.\n",
  427. event->header.type);
  428. return -1;
  429. }
  430. if (al.filtered)
  431. return 0;
  432. if (cpu_list && !test_bit(sample->cpu, cpu_bitmap))
  433. return 0;
  434. scripting_ops->process_event(event, sample, evsel, machine, thread);
  435. evsel->hists.stats.total_period += sample->period;
  436. return 0;
  437. }
  438. static struct perf_tool perf_script = {
  439. .sample = process_sample_event,
  440. .mmap = perf_event__process_mmap,
  441. .comm = perf_event__process_comm,
  442. .exit = perf_event__process_task,
  443. .fork = perf_event__process_task,
  444. .attr = perf_event__process_attr,
  445. .event_type = perf_event__process_event_type,
  446. .tracing_data = perf_event__process_tracing_data,
  447. .build_id = perf_event__process_build_id,
  448. .ordered_samples = true,
  449. .ordering_requires_timestamps = true,
  450. };
  451. extern volatile int session_done;
  452. static void sig_handler(int sig __unused)
  453. {
  454. session_done = 1;
  455. }
  456. static int __cmd_script(struct perf_session *session)
  457. {
  458. int ret;
  459. signal(SIGINT, sig_handler);
  460. ret = perf_session__process_events(session, &perf_script);
  461. if (debug_mode)
  462. pr_err("Misordered timestamps: %" PRIu64 "\n", nr_unordered);
  463. return ret;
  464. }
  465. struct script_spec {
  466. struct list_head node;
  467. struct scripting_ops *ops;
  468. char spec[0];
  469. };
  470. static LIST_HEAD(script_specs);
  471. static struct script_spec *script_spec__new(const char *spec,
  472. struct scripting_ops *ops)
  473. {
  474. struct script_spec *s = malloc(sizeof(*s) + strlen(spec) + 1);
  475. if (s != NULL) {
  476. strcpy(s->spec, spec);
  477. s->ops = ops;
  478. }
  479. return s;
  480. }
  481. static void script_spec__add(struct script_spec *s)
  482. {
  483. list_add_tail(&s->node, &script_specs);
  484. }
  485. static struct script_spec *script_spec__find(const char *spec)
  486. {
  487. struct script_spec *s;
  488. list_for_each_entry(s, &script_specs, node)
  489. if (strcasecmp(s->spec, spec) == 0)
  490. return s;
  491. return NULL;
  492. }
  493. static struct script_spec *script_spec__findnew(const char *spec,
  494. struct scripting_ops *ops)
  495. {
  496. struct script_spec *s = script_spec__find(spec);
  497. if (s)
  498. return s;
  499. s = script_spec__new(spec, ops);
  500. if (!s)
  501. return NULL;
  502. script_spec__add(s);
  503. return s;
  504. }
  505. int script_spec_register(const char *spec, struct scripting_ops *ops)
  506. {
  507. struct script_spec *s;
  508. s = script_spec__find(spec);
  509. if (s)
  510. return -1;
  511. s = script_spec__findnew(spec, ops);
  512. if (!s)
  513. return -1;
  514. return 0;
  515. }
  516. static struct scripting_ops *script_spec__lookup(const char *spec)
  517. {
  518. struct script_spec *s = script_spec__find(spec);
  519. if (!s)
  520. return NULL;
  521. return s->ops;
  522. }
  523. static void list_available_languages(void)
  524. {
  525. struct script_spec *s;
  526. fprintf(stderr, "\n");
  527. fprintf(stderr, "Scripting language extensions (used in "
  528. "perf script -s [spec:]script.[spec]):\n\n");
  529. list_for_each_entry(s, &script_specs, node)
  530. fprintf(stderr, " %-42s [%s]\n", s->spec, s->ops->name);
  531. fprintf(stderr, "\n");
  532. }
  533. static int parse_scriptname(const struct option *opt __used,
  534. const char *str, int unset __used)
  535. {
  536. char spec[PATH_MAX];
  537. const char *script, *ext;
  538. int len;
  539. if (strcmp(str, "lang") == 0) {
  540. list_available_languages();
  541. exit(0);
  542. }
  543. script = strchr(str, ':');
  544. if (script) {
  545. len = script - str;
  546. if (len >= PATH_MAX) {
  547. fprintf(stderr, "invalid language specifier");
  548. return -1;
  549. }
  550. strncpy(spec, str, len);
  551. spec[len] = '\0';
  552. scripting_ops = script_spec__lookup(spec);
  553. if (!scripting_ops) {
  554. fprintf(stderr, "invalid language specifier");
  555. return -1;
  556. }
  557. script++;
  558. } else {
  559. script = str;
  560. ext = strrchr(script, '.');
  561. if (!ext) {
  562. fprintf(stderr, "invalid script extension");
  563. return -1;
  564. }
  565. scripting_ops = script_spec__lookup(++ext);
  566. if (!scripting_ops) {
  567. fprintf(stderr, "invalid script extension");
  568. return -1;
  569. }
  570. }
  571. script_name = strdup(script);
  572. return 0;
  573. }
  574. static int parse_output_fields(const struct option *opt __used,
  575. const char *arg, int unset __used)
  576. {
  577. char *tok;
  578. int i, imax = sizeof(all_output_options) / sizeof(struct output_option);
  579. int j;
  580. int rc = 0;
  581. char *str = strdup(arg);
  582. int type = -1;
  583. if (!str)
  584. return -ENOMEM;
  585. /* first word can state for which event type the user is specifying
  586. * the fields. If no type exists, the specified fields apply to all
  587. * event types found in the file minus the invalid fields for a type.
  588. */
  589. tok = strchr(str, ':');
  590. if (tok) {
  591. *tok = '\0';
  592. tok++;
  593. if (!strcmp(str, "hw"))
  594. type = PERF_TYPE_HARDWARE;
  595. else if (!strcmp(str, "sw"))
  596. type = PERF_TYPE_SOFTWARE;
  597. else if (!strcmp(str, "trace"))
  598. type = PERF_TYPE_TRACEPOINT;
  599. else if (!strcmp(str, "raw"))
  600. type = PERF_TYPE_RAW;
  601. else {
  602. fprintf(stderr, "Invalid event type in field string.\n");
  603. rc = -EINVAL;
  604. goto out;
  605. }
  606. if (output[type].user_set)
  607. pr_warning("Overriding previous field request for %s events.\n",
  608. event_type(type));
  609. output[type].fields = 0;
  610. output[type].user_set = true;
  611. output[type].wildcard_set = false;
  612. } else {
  613. tok = str;
  614. if (strlen(str) == 0) {
  615. fprintf(stderr,
  616. "Cannot set fields to 'none' for all event types.\n");
  617. rc = -EINVAL;
  618. goto out;
  619. }
  620. if (output_set_by_user())
  621. pr_warning("Overriding previous field request for all events.\n");
  622. for (j = 0; j < PERF_TYPE_MAX; ++j) {
  623. output[j].fields = 0;
  624. output[j].user_set = true;
  625. output[j].wildcard_set = true;
  626. }
  627. }
  628. tok = strtok(tok, ",");
  629. while (tok) {
  630. for (i = 0; i < imax; ++i) {
  631. if (strcmp(tok, all_output_options[i].str) == 0)
  632. break;
  633. }
  634. if (i == imax) {
  635. fprintf(stderr, "Invalid field requested.\n");
  636. rc = -EINVAL;
  637. goto out;
  638. }
  639. if (type == -1) {
  640. /* add user option to all events types for
  641. * which it is valid
  642. */
  643. for (j = 0; j < PERF_TYPE_MAX; ++j) {
  644. if (output[j].invalid_fields & all_output_options[i].field) {
  645. pr_warning("\'%s\' not valid for %s events. Ignoring.\n",
  646. all_output_options[i].str, event_type(j));
  647. } else
  648. output[j].fields |= all_output_options[i].field;
  649. }
  650. } else {
  651. if (output[type].invalid_fields & all_output_options[i].field) {
  652. fprintf(stderr, "\'%s\' not valid for %s events.\n",
  653. all_output_options[i].str, event_type(type));
  654. rc = -EINVAL;
  655. goto out;
  656. }
  657. output[type].fields |= all_output_options[i].field;
  658. }
  659. tok = strtok(NULL, ",");
  660. }
  661. if (type >= 0) {
  662. if (output[type].fields == 0) {
  663. pr_debug("No fields requested for %s type. "
  664. "Events will not be displayed.\n", event_type(type));
  665. }
  666. }
  667. out:
  668. free(str);
  669. return rc;
  670. }
  671. /* Helper function for filesystems that return a dent->d_type DT_UNKNOWN */
  672. static int is_directory(const char *base_path, const struct dirent *dent)
  673. {
  674. char path[PATH_MAX];
  675. struct stat st;
  676. sprintf(path, "%s/%s", base_path, dent->d_name);
  677. if (stat(path, &st))
  678. return 0;
  679. return S_ISDIR(st.st_mode);
  680. }
  681. #define for_each_lang(scripts_path, scripts_dir, lang_dirent, lang_next)\
  682. while (!readdir_r(scripts_dir, &lang_dirent, &lang_next) && \
  683. lang_next) \
  684. if ((lang_dirent.d_type == DT_DIR || \
  685. (lang_dirent.d_type == DT_UNKNOWN && \
  686. is_directory(scripts_path, &lang_dirent))) && \
  687. (strcmp(lang_dirent.d_name, ".")) && \
  688. (strcmp(lang_dirent.d_name, "..")))
  689. #define for_each_script(lang_path, lang_dir, script_dirent, script_next)\
  690. while (!readdir_r(lang_dir, &script_dirent, &script_next) && \
  691. script_next) \
  692. if (script_dirent.d_type != DT_DIR && \
  693. (script_dirent.d_type != DT_UNKNOWN || \
  694. !is_directory(lang_path, &script_dirent)))
  695. #define RECORD_SUFFIX "-record"
  696. #define REPORT_SUFFIX "-report"
  697. struct script_desc {
  698. struct list_head node;
  699. char *name;
  700. char *half_liner;
  701. char *args;
  702. };
  703. static LIST_HEAD(script_descs);
  704. static struct script_desc *script_desc__new(const char *name)
  705. {
  706. struct script_desc *s = zalloc(sizeof(*s));
  707. if (s != NULL && name)
  708. s->name = strdup(name);
  709. return s;
  710. }
  711. static void script_desc__delete(struct script_desc *s)
  712. {
  713. free(s->name);
  714. free(s->half_liner);
  715. free(s->args);
  716. free(s);
  717. }
  718. static void script_desc__add(struct script_desc *s)
  719. {
  720. list_add_tail(&s->node, &script_descs);
  721. }
  722. static struct script_desc *script_desc__find(const char *name)
  723. {
  724. struct script_desc *s;
  725. list_for_each_entry(s, &script_descs, node)
  726. if (strcasecmp(s->name, name) == 0)
  727. return s;
  728. return NULL;
  729. }
  730. static struct script_desc *script_desc__findnew(const char *name)
  731. {
  732. struct script_desc *s = script_desc__find(name);
  733. if (s)
  734. return s;
  735. s = script_desc__new(name);
  736. if (!s)
  737. goto out_delete_desc;
  738. script_desc__add(s);
  739. return s;
  740. out_delete_desc:
  741. script_desc__delete(s);
  742. return NULL;
  743. }
  744. static const char *ends_with(const char *str, const char *suffix)
  745. {
  746. size_t suffix_len = strlen(suffix);
  747. const char *p = str;
  748. if (strlen(str) > suffix_len) {
  749. p = str + strlen(str) - suffix_len;
  750. if (!strncmp(p, suffix, suffix_len))
  751. return p;
  752. }
  753. return NULL;
  754. }
  755. static char *ltrim(char *str)
  756. {
  757. int len = strlen(str);
  758. while (len && isspace(*str)) {
  759. len--;
  760. str++;
  761. }
  762. return str;
  763. }
  764. static int read_script_info(struct script_desc *desc, const char *filename)
  765. {
  766. char line[BUFSIZ], *p;
  767. FILE *fp;
  768. fp = fopen(filename, "r");
  769. if (!fp)
  770. return -1;
  771. while (fgets(line, sizeof(line), fp)) {
  772. p = ltrim(line);
  773. if (strlen(p) == 0)
  774. continue;
  775. if (*p != '#')
  776. continue;
  777. p++;
  778. if (strlen(p) && *p == '!')
  779. continue;
  780. p = ltrim(p);
  781. if (strlen(p) && p[strlen(p) - 1] == '\n')
  782. p[strlen(p) - 1] = '\0';
  783. if (!strncmp(p, "description:", strlen("description:"))) {
  784. p += strlen("description:");
  785. desc->half_liner = strdup(ltrim(p));
  786. continue;
  787. }
  788. if (!strncmp(p, "args:", strlen("args:"))) {
  789. p += strlen("args:");
  790. desc->args = strdup(ltrim(p));
  791. continue;
  792. }
  793. }
  794. fclose(fp);
  795. return 0;
  796. }
  797. static char *get_script_root(struct dirent *script_dirent, const char *suffix)
  798. {
  799. char *script_root, *str;
  800. script_root = strdup(script_dirent->d_name);
  801. if (!script_root)
  802. return NULL;
  803. str = (char *)ends_with(script_root, suffix);
  804. if (!str) {
  805. free(script_root);
  806. return NULL;
  807. }
  808. *str = '\0';
  809. return script_root;
  810. }
  811. static int list_available_scripts(const struct option *opt __used,
  812. const char *s __used, int unset __used)
  813. {
  814. struct dirent *script_next, *lang_next, script_dirent, lang_dirent;
  815. char scripts_path[MAXPATHLEN];
  816. DIR *scripts_dir, *lang_dir;
  817. char script_path[MAXPATHLEN];
  818. char lang_path[MAXPATHLEN];
  819. struct script_desc *desc;
  820. char first_half[BUFSIZ];
  821. char *script_root;
  822. snprintf(scripts_path, MAXPATHLEN, "%s/scripts", perf_exec_path());
  823. scripts_dir = opendir(scripts_path);
  824. if (!scripts_dir)
  825. return -1;
  826. for_each_lang(scripts_path, scripts_dir, lang_dirent, lang_next) {
  827. snprintf(lang_path, MAXPATHLEN, "%s/%s/bin", scripts_path,
  828. lang_dirent.d_name);
  829. lang_dir = opendir(lang_path);
  830. if (!lang_dir)
  831. continue;
  832. for_each_script(lang_path, lang_dir, script_dirent, script_next) {
  833. script_root = get_script_root(&script_dirent, REPORT_SUFFIX);
  834. if (script_root) {
  835. desc = script_desc__findnew(script_root);
  836. snprintf(script_path, MAXPATHLEN, "%s/%s",
  837. lang_path, script_dirent.d_name);
  838. read_script_info(desc, script_path);
  839. free(script_root);
  840. }
  841. }
  842. }
  843. fprintf(stdout, "List of available trace scripts:\n");
  844. list_for_each_entry(desc, &script_descs, node) {
  845. sprintf(first_half, "%s %s", desc->name,
  846. desc->args ? desc->args : "");
  847. fprintf(stdout, " %-36s %s\n", first_half,
  848. desc->half_liner ? desc->half_liner : "");
  849. }
  850. exit(0);
  851. }
  852. static char *get_script_path(const char *script_root, const char *suffix)
  853. {
  854. struct dirent *script_next, *lang_next, script_dirent, lang_dirent;
  855. char scripts_path[MAXPATHLEN];
  856. char script_path[MAXPATHLEN];
  857. DIR *scripts_dir, *lang_dir;
  858. char lang_path[MAXPATHLEN];
  859. char *__script_root;
  860. snprintf(scripts_path, MAXPATHLEN, "%s/scripts", perf_exec_path());
  861. scripts_dir = opendir(scripts_path);
  862. if (!scripts_dir)
  863. return NULL;
  864. for_each_lang(scripts_path, scripts_dir, lang_dirent, lang_next) {
  865. snprintf(lang_path, MAXPATHLEN, "%s/%s/bin", scripts_path,
  866. lang_dirent.d_name);
  867. lang_dir = opendir(lang_path);
  868. if (!lang_dir)
  869. continue;
  870. for_each_script(lang_path, lang_dir, script_dirent, script_next) {
  871. __script_root = get_script_root(&script_dirent, suffix);
  872. if (__script_root && !strcmp(script_root, __script_root)) {
  873. free(__script_root);
  874. closedir(lang_dir);
  875. closedir(scripts_dir);
  876. snprintf(script_path, MAXPATHLEN, "%s/%s",
  877. lang_path, script_dirent.d_name);
  878. return strdup(script_path);
  879. }
  880. free(__script_root);
  881. }
  882. closedir(lang_dir);
  883. }
  884. closedir(scripts_dir);
  885. return NULL;
  886. }
  887. static bool is_top_script(const char *script_path)
  888. {
  889. return ends_with(script_path, "top") == NULL ? false : true;
  890. }
  891. static int has_required_arg(char *script_path)
  892. {
  893. struct script_desc *desc;
  894. int n_args = 0;
  895. char *p;
  896. desc = script_desc__new(NULL);
  897. if (read_script_info(desc, script_path))
  898. goto out;
  899. if (!desc->args)
  900. goto out;
  901. for (p = desc->args; *p; p++)
  902. if (*p == '<')
  903. n_args++;
  904. out:
  905. script_desc__delete(desc);
  906. return n_args;
  907. }
  908. static const char * const script_usage[] = {
  909. "perf script [<options>]",
  910. "perf script [<options>] record <script> [<record-options>] <command>",
  911. "perf script [<options>] report <script> [script-args]",
  912. "perf script [<options>] <script> [<record-options>] <command>",
  913. "perf script [<options>] <top-script> [script-args]",
  914. NULL
  915. };
  916. static const struct option options[] = {
  917. OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace,
  918. "dump raw trace in ASCII"),
  919. OPT_INCR('v', "verbose", &verbose,
  920. "be more verbose (show symbol address, etc)"),
  921. OPT_BOOLEAN('L', "Latency", &latency_format,
  922. "show latency attributes (irqs/preemption disabled, etc)"),
  923. OPT_CALLBACK_NOOPT('l', "list", NULL, NULL, "list available scripts",
  924. list_available_scripts),
  925. OPT_CALLBACK('s', "script", NULL, "name",
  926. "script file name (lang:script name, script name, or *)",
  927. parse_scriptname),
  928. OPT_STRING('g', "gen-script", &generate_script_lang, "lang",
  929. "generate perf-script.xx script in specified language"),
  930. OPT_STRING('i', "input", &input_name, "file",
  931. "input file name"),
  932. OPT_BOOLEAN('d', "debug-mode", &debug_mode,
  933. "do various checks like samples ordering and lost events"),
  934. OPT_STRING('k', "vmlinux", &symbol_conf.vmlinux_name,
  935. "file", "vmlinux pathname"),
  936. OPT_STRING(0, "kallsyms", &symbol_conf.kallsyms_name,
  937. "file", "kallsyms pathname"),
  938. OPT_BOOLEAN('G', "hide-call-graph", &no_callchain,
  939. "When printing symbols do not display call chain"),
  940. OPT_STRING(0, "symfs", &symbol_conf.symfs, "directory",
  941. "Look for files with symbols relative to this directory"),
  942. OPT_CALLBACK('f', "fields", NULL, "str",
  943. "comma separated output fields prepend with 'type:'. "
  944. "Valid types: hw,sw,trace,raw. "
  945. "Fields: comm,tid,pid,time,cpu,event,trace,ip,sym,dso,"
  946. "addr,symoff",
  947. parse_output_fields),
  948. OPT_BOOLEAN('a', "all-cpus", &system_wide,
  949. "system-wide collection from all CPUs"),
  950. OPT_STRING('C', "cpu", &cpu_list, "cpu", "list of cpus to profile"),
  951. OPT_STRING('c', "comms", &symbol_conf.comm_list_str, "comm[,comm...]",
  952. "only display events for these comms"),
  953. OPT_BOOLEAN('I', "show-info", &show_full_info,
  954. "display extended information from perf.data file"),
  955. OPT_BOOLEAN('\0', "show-kernel-path", &symbol_conf.show_kernel_path,
  956. "Show the path of [kernel.kallsyms]"),
  957. OPT_END()
  958. };
  959. static bool have_cmd(int argc, const char **argv)
  960. {
  961. char **__argv = malloc(sizeof(const char *) * argc);
  962. if (!__argv)
  963. die("malloc");
  964. memcpy(__argv, argv, sizeof(const char *) * argc);
  965. argc = parse_options(argc, (const char **)__argv, record_options,
  966. NULL, PARSE_OPT_STOP_AT_NON_OPTION);
  967. free(__argv);
  968. return argc != 0;
  969. }
  970. int cmd_script(int argc, const char **argv, const char *prefix __used)
  971. {
  972. char *rec_script_path = NULL;
  973. char *rep_script_path = NULL;
  974. struct perf_session *session;
  975. char *script_path = NULL;
  976. const char **__argv;
  977. int i, j, err;
  978. setup_scripting();
  979. argc = parse_options(argc, argv, options, script_usage,
  980. PARSE_OPT_STOP_AT_NON_OPTION);
  981. if (argc > 1 && !strncmp(argv[0], "rec", strlen("rec"))) {
  982. rec_script_path = get_script_path(argv[1], RECORD_SUFFIX);
  983. if (!rec_script_path)
  984. return cmd_record(argc, argv, NULL);
  985. }
  986. if (argc > 1 && !strncmp(argv[0], "rep", strlen("rep"))) {
  987. rep_script_path = get_script_path(argv[1], REPORT_SUFFIX);
  988. if (!rep_script_path) {
  989. fprintf(stderr,
  990. "Please specify a valid report script"
  991. "(see 'perf script -l' for listing)\n");
  992. return -1;
  993. }
  994. }
  995. /* make sure PERF_EXEC_PATH is set for scripts */
  996. perf_set_argv_exec_path(perf_exec_path());
  997. if (argc && !script_name && !rec_script_path && !rep_script_path) {
  998. int live_pipe[2];
  999. int rep_args;
  1000. pid_t pid;
  1001. rec_script_path = get_script_path(argv[0], RECORD_SUFFIX);
  1002. rep_script_path = get_script_path(argv[0], REPORT_SUFFIX);
  1003. if (!rec_script_path && !rep_script_path) {
  1004. fprintf(stderr, " Couldn't find script %s\n\n See perf"
  1005. " script -l for available scripts.\n", argv[0]);
  1006. usage_with_options(script_usage, options);
  1007. }
  1008. if (is_top_script(argv[0])) {
  1009. rep_args = argc - 1;
  1010. } else {
  1011. int rec_args;
  1012. rep_args = has_required_arg(rep_script_path);
  1013. rec_args = (argc - 1) - rep_args;
  1014. if (rec_args < 0) {
  1015. fprintf(stderr, " %s script requires options."
  1016. "\n\n See perf script -l for available "
  1017. "scripts and options.\n", argv[0]);
  1018. usage_with_options(script_usage, options);
  1019. }
  1020. }
  1021. if (pipe(live_pipe) < 0) {
  1022. perror("failed to create pipe");
  1023. exit(-1);
  1024. }
  1025. pid = fork();
  1026. if (pid < 0) {
  1027. perror("failed to fork");
  1028. exit(-1);
  1029. }
  1030. if (!pid) {
  1031. j = 0;
  1032. dup2(live_pipe[1], 1);
  1033. close(live_pipe[0]);
  1034. if (is_top_script(argv[0])) {
  1035. system_wide = true;
  1036. } else if (!system_wide) {
  1037. system_wide = !have_cmd(argc - rep_args,
  1038. &argv[rep_args]);
  1039. }
  1040. __argv = malloc((argc + 6) * sizeof(const char *));
  1041. if (!__argv)
  1042. die("malloc");
  1043. __argv[j++] = "/bin/sh";
  1044. __argv[j++] = rec_script_path;
  1045. if (system_wide)
  1046. __argv[j++] = "-a";
  1047. __argv[j++] = "-q";
  1048. __argv[j++] = "-o";
  1049. __argv[j++] = "-";
  1050. for (i = rep_args + 1; i < argc; i++)
  1051. __argv[j++] = argv[i];
  1052. __argv[j++] = NULL;
  1053. execvp("/bin/sh", (char **)__argv);
  1054. free(__argv);
  1055. exit(-1);
  1056. }
  1057. dup2(live_pipe[0], 0);
  1058. close(live_pipe[1]);
  1059. __argv = malloc((argc + 4) * sizeof(const char *));
  1060. if (!__argv)
  1061. die("malloc");
  1062. j = 0;
  1063. __argv[j++] = "/bin/sh";
  1064. __argv[j++] = rep_script_path;
  1065. for (i = 1; i < rep_args + 1; i++)
  1066. __argv[j++] = argv[i];
  1067. __argv[j++] = "-i";
  1068. __argv[j++] = "-";
  1069. __argv[j++] = NULL;
  1070. execvp("/bin/sh", (char **)__argv);
  1071. free(__argv);
  1072. exit(-1);
  1073. }
  1074. if (rec_script_path)
  1075. script_path = rec_script_path;
  1076. if (rep_script_path)
  1077. script_path = rep_script_path;
  1078. if (script_path) {
  1079. j = 0;
  1080. if (!rec_script_path)
  1081. system_wide = false;
  1082. else if (!system_wide)
  1083. system_wide = !have_cmd(argc - 1, &argv[1]);
  1084. __argv = malloc((argc + 2) * sizeof(const char *));
  1085. if (!__argv)
  1086. die("malloc");
  1087. __argv[j++] = "/bin/sh";
  1088. __argv[j++] = script_path;
  1089. if (system_wide)
  1090. __argv[j++] = "-a";
  1091. for (i = 2; i < argc; i++)
  1092. __argv[j++] = argv[i];
  1093. __argv[j++] = NULL;
  1094. execvp("/bin/sh", (char **)__argv);
  1095. free(__argv);
  1096. exit(-1);
  1097. }
  1098. if (symbol__init() < 0)
  1099. return -1;
  1100. if (!script_name)
  1101. setup_pager();
  1102. session = perf_session__new(input_name, O_RDONLY, 0, false, &perf_script);
  1103. if (session == NULL)
  1104. return -ENOMEM;
  1105. if (cpu_list) {
  1106. if (perf_session__cpu_bitmap(session, cpu_list, cpu_bitmap))
  1107. return -1;
  1108. }
  1109. perf_session__fprintf_info(session, stdout, show_full_info);
  1110. if (!no_callchain)
  1111. symbol_conf.use_callchain = true;
  1112. else
  1113. symbol_conf.use_callchain = false;
  1114. if (generate_script_lang) {
  1115. struct stat perf_stat;
  1116. int input;
  1117. if (output_set_by_user()) {
  1118. fprintf(stderr,
  1119. "custom fields not supported for generated scripts");
  1120. return -1;
  1121. }
  1122. input = open(session->filename, O_RDONLY); /* input_name */
  1123. if (input < 0) {
  1124. perror("failed to open file");
  1125. exit(-1);
  1126. }
  1127. err = fstat(input, &perf_stat);
  1128. if (err < 0) {
  1129. perror("failed to stat file");
  1130. exit(-1);
  1131. }
  1132. if (!perf_stat.st_size) {
  1133. fprintf(stderr, "zero-sized file, nothing to do!\n");
  1134. exit(0);
  1135. }
  1136. scripting_ops = script_spec__lookup(generate_script_lang);
  1137. if (!scripting_ops) {
  1138. fprintf(stderr, "invalid language specifier");
  1139. return -1;
  1140. }
  1141. err = scripting_ops->generate_script("perf-script");
  1142. goto out;
  1143. }
  1144. if (script_name) {
  1145. err = scripting_ops->start_script(script_name, argc, argv);
  1146. if (err)
  1147. goto out;
  1148. pr_debug("perf script started with script %s\n\n", script_name);
  1149. }
  1150. err = perf_session__check_output_opt(session);
  1151. if (err < 0)
  1152. goto out;
  1153. err = __cmd_script(session);
  1154. perf_session__delete(session);
  1155. cleanup_scripting();
  1156. out:
  1157. return err;
  1158. }