builtin-script.c 33 KB

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