trace-event-parse.c 63 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159
  1. /*
  2. * Copyright (C) 2009, Steven Rostedt <srostedt@redhat.com>
  3. *
  4. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; version 2 of the License (not later!)
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. *
  19. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  20. *
  21. * The parts for function graph printing was taken and modified from the
  22. * Linux Kernel that were written by Frederic Weisbecker.
  23. */
  24. #define _GNU_SOURCE
  25. #include <stdio.h>
  26. #include <stdlib.h>
  27. #include <string.h>
  28. #include <ctype.h>
  29. #include <errno.h>
  30. #undef _GNU_SOURCE
  31. #include "../perf.h"
  32. #include "util.h"
  33. #include "trace-event.h"
  34. int header_page_ts_offset;
  35. int header_page_ts_size;
  36. int header_page_size_offset;
  37. int header_page_size_size;
  38. int header_page_data_offset;
  39. int header_page_data_size;
  40. static char *input_buf;
  41. static unsigned long long input_buf_ptr;
  42. static unsigned long long input_buf_siz;
  43. static int cpus;
  44. static int long_size;
  45. static void init_input_buf(char *buf, unsigned long long size)
  46. {
  47. input_buf = buf;
  48. input_buf_siz = size;
  49. input_buf_ptr = 0;
  50. }
  51. struct cmdline {
  52. char *comm;
  53. int pid;
  54. };
  55. static struct cmdline *cmdlines;
  56. static int cmdline_count;
  57. static int cmdline_cmp(const void *a, const void *b)
  58. {
  59. const struct cmdline *ca = a;
  60. const struct cmdline *cb = b;
  61. if (ca->pid < cb->pid)
  62. return -1;
  63. if (ca->pid > cb->pid)
  64. return 1;
  65. return 0;
  66. }
  67. void parse_cmdlines(char *file, int size __unused)
  68. {
  69. struct cmdline_list {
  70. struct cmdline_list *next;
  71. char *comm;
  72. int pid;
  73. } *list = NULL, *item;
  74. char *line;
  75. char *next = NULL;
  76. int i;
  77. line = strtok_r(file, "\n", &next);
  78. while (line) {
  79. item = malloc_or_die(sizeof(*item));
  80. sscanf(line, "%d %as", &item->pid,
  81. (float *)(void *)&item->comm); /* workaround gcc warning */
  82. item->next = list;
  83. list = item;
  84. line = strtok_r(NULL, "\n", &next);
  85. cmdline_count++;
  86. }
  87. cmdlines = malloc_or_die(sizeof(*cmdlines) * cmdline_count);
  88. i = 0;
  89. while (list) {
  90. cmdlines[i].pid = list->pid;
  91. cmdlines[i].comm = list->comm;
  92. i++;
  93. item = list;
  94. list = list->next;
  95. free(item);
  96. }
  97. qsort(cmdlines, cmdline_count, sizeof(*cmdlines), cmdline_cmp);
  98. }
  99. static struct func_map {
  100. unsigned long long addr;
  101. char *func;
  102. char *mod;
  103. } *func_list;
  104. static unsigned int func_count;
  105. static int func_cmp(const void *a, const void *b)
  106. {
  107. const struct func_map *fa = a;
  108. const struct func_map *fb = b;
  109. if (fa->addr < fb->addr)
  110. return -1;
  111. if (fa->addr > fb->addr)
  112. return 1;
  113. return 0;
  114. }
  115. void parse_proc_kallsyms(char *file, unsigned int size __unused)
  116. {
  117. struct func_list {
  118. struct func_list *next;
  119. unsigned long long addr;
  120. char *func;
  121. char *mod;
  122. } *list = NULL, *item;
  123. char *line;
  124. char *next = NULL;
  125. char *addr_str;
  126. char ch;
  127. int ret;
  128. int i;
  129. line = strtok_r(file, "\n", &next);
  130. while (line) {
  131. item = malloc_or_die(sizeof(*item));
  132. item->mod = NULL;
  133. ret = sscanf(line, "%as %c %as\t[%as",
  134. (float *)(void *)&addr_str, /* workaround gcc warning */
  135. &ch,
  136. (float *)(void *)&item->func,
  137. (float *)(void *)&item->mod);
  138. item->addr = strtoull(addr_str, NULL, 16);
  139. free(addr_str);
  140. /* truncate the extra ']' */
  141. if (item->mod)
  142. item->mod[strlen(item->mod) - 1] = 0;
  143. item->next = list;
  144. list = item;
  145. line = strtok_r(NULL, "\n", &next);
  146. func_count++;
  147. }
  148. func_list = malloc_or_die(sizeof(*func_list) * func_count + 1);
  149. i = 0;
  150. while (list) {
  151. func_list[i].func = list->func;
  152. func_list[i].addr = list->addr;
  153. func_list[i].mod = list->mod;
  154. i++;
  155. item = list;
  156. list = list->next;
  157. free(item);
  158. }
  159. qsort(func_list, func_count, sizeof(*func_list), func_cmp);
  160. /*
  161. * Add a special record at the end.
  162. */
  163. func_list[func_count].func = NULL;
  164. func_list[func_count].addr = 0;
  165. func_list[func_count].mod = NULL;
  166. }
  167. /*
  168. * We are searching for a record in between, not an exact
  169. * match.
  170. */
  171. static int func_bcmp(const void *a, const void *b)
  172. {
  173. const struct func_map *fa = a;
  174. const struct func_map *fb = b;
  175. if ((fa->addr == fb->addr) ||
  176. (fa->addr > fb->addr &&
  177. fa->addr < (fb+1)->addr))
  178. return 0;
  179. if (fa->addr < fb->addr)
  180. return -1;
  181. return 1;
  182. }
  183. static struct func_map *find_func(unsigned long long addr)
  184. {
  185. struct func_map *func;
  186. struct func_map key;
  187. key.addr = addr;
  188. func = bsearch(&key, func_list, func_count, sizeof(*func_list),
  189. func_bcmp);
  190. return func;
  191. }
  192. void print_funcs(void)
  193. {
  194. int i;
  195. for (i = 0; i < (int)func_count; i++) {
  196. printf("%016llx %s",
  197. func_list[i].addr,
  198. func_list[i].func);
  199. if (func_list[i].mod)
  200. printf(" [%s]\n", func_list[i].mod);
  201. else
  202. printf("\n");
  203. }
  204. }
  205. static struct printk_map {
  206. unsigned long long addr;
  207. char *printk;
  208. } *printk_list;
  209. static unsigned int printk_count;
  210. static int printk_cmp(const void *a, const void *b)
  211. {
  212. const struct func_map *fa = a;
  213. const struct func_map *fb = b;
  214. if (fa->addr < fb->addr)
  215. return -1;
  216. if (fa->addr > fb->addr)
  217. return 1;
  218. return 0;
  219. }
  220. static struct printk_map *find_printk(unsigned long long addr)
  221. {
  222. struct printk_map *printk;
  223. struct printk_map key;
  224. key.addr = addr;
  225. printk = bsearch(&key, printk_list, printk_count, sizeof(*printk_list),
  226. printk_cmp);
  227. return printk;
  228. }
  229. void parse_ftrace_printk(char *file, unsigned int size __unused)
  230. {
  231. struct printk_list {
  232. struct printk_list *next;
  233. unsigned long long addr;
  234. char *printk;
  235. } *list = NULL, *item;
  236. char *line;
  237. char *next = NULL;
  238. char *addr_str;
  239. char *fmt;
  240. int i;
  241. line = strtok_r(file, "\n", &next);
  242. while (line) {
  243. item = malloc_or_die(sizeof(*item));
  244. addr_str = strtok_r(line, ":", &fmt);
  245. item->addr = strtoull(addr_str, NULL, 16);
  246. /* fmt still has a space, skip it */
  247. item->printk = strdup(fmt+1);
  248. item->next = list;
  249. list = item;
  250. line = strtok_r(NULL, "\n", &next);
  251. printk_count++;
  252. }
  253. printk_list = malloc_or_die(sizeof(*printk_list) * printk_count + 1);
  254. i = 0;
  255. while (list) {
  256. printk_list[i].printk = list->printk;
  257. printk_list[i].addr = list->addr;
  258. i++;
  259. item = list;
  260. list = list->next;
  261. free(item);
  262. }
  263. qsort(printk_list, printk_count, sizeof(*printk_list), printk_cmp);
  264. }
  265. void print_printk(void)
  266. {
  267. int i;
  268. for (i = 0; i < (int)printk_count; i++) {
  269. printf("%016llx %s\n",
  270. printk_list[i].addr,
  271. printk_list[i].printk);
  272. }
  273. }
  274. static struct event *alloc_event(void)
  275. {
  276. struct event *event;
  277. event = malloc_or_die(sizeof(*event));
  278. memset(event, 0, sizeof(*event));
  279. return event;
  280. }
  281. enum event_type {
  282. EVENT_ERROR,
  283. EVENT_NONE,
  284. EVENT_SPACE,
  285. EVENT_NEWLINE,
  286. EVENT_OP,
  287. EVENT_DELIM,
  288. EVENT_ITEM,
  289. EVENT_DQUOTE,
  290. EVENT_SQUOTE,
  291. };
  292. static struct event *event_list;
  293. static void add_event(struct event *event)
  294. {
  295. event->next = event_list;
  296. event_list = event;
  297. }
  298. static int event_item_type(enum event_type type)
  299. {
  300. switch (type) {
  301. case EVENT_ITEM ... EVENT_SQUOTE:
  302. return 1;
  303. case EVENT_ERROR ... EVENT_DELIM:
  304. default:
  305. return 0;
  306. }
  307. }
  308. static void free_arg(struct print_arg *arg)
  309. {
  310. if (!arg)
  311. return;
  312. switch (arg->type) {
  313. case PRINT_ATOM:
  314. if (arg->atom.atom)
  315. free(arg->atom.atom);
  316. break;
  317. case PRINT_NULL:
  318. case PRINT_FIELD ... PRINT_OP:
  319. default:
  320. /* todo */
  321. break;
  322. }
  323. free(arg);
  324. }
  325. static enum event_type get_type(int ch)
  326. {
  327. if (ch == '\n')
  328. return EVENT_NEWLINE;
  329. if (isspace(ch))
  330. return EVENT_SPACE;
  331. if (isalnum(ch) || ch == '_')
  332. return EVENT_ITEM;
  333. if (ch == '\'')
  334. return EVENT_SQUOTE;
  335. if (ch == '"')
  336. return EVENT_DQUOTE;
  337. if (!isprint(ch))
  338. return EVENT_NONE;
  339. if (ch == '(' || ch == ')' || ch == ',')
  340. return EVENT_DELIM;
  341. return EVENT_OP;
  342. }
  343. static int __read_char(void)
  344. {
  345. if (input_buf_ptr >= input_buf_siz)
  346. return -1;
  347. return input_buf[input_buf_ptr++];
  348. }
  349. static int __peek_char(void)
  350. {
  351. if (input_buf_ptr >= input_buf_siz)
  352. return -1;
  353. return input_buf[input_buf_ptr];
  354. }
  355. static enum event_type __read_token(char **tok)
  356. {
  357. char buf[BUFSIZ];
  358. int ch, last_ch, quote_ch, next_ch;
  359. int i = 0;
  360. int tok_size = 0;
  361. enum event_type type;
  362. *tok = NULL;
  363. ch = __read_char();
  364. if (ch < 0)
  365. return EVENT_NONE;
  366. type = get_type(ch);
  367. if (type == EVENT_NONE)
  368. return type;
  369. buf[i++] = ch;
  370. switch (type) {
  371. case EVENT_NEWLINE:
  372. case EVENT_DELIM:
  373. *tok = malloc_or_die(2);
  374. (*tok)[0] = ch;
  375. (*tok)[1] = 0;
  376. return type;
  377. case EVENT_OP:
  378. switch (ch) {
  379. case '-':
  380. next_ch = __peek_char();
  381. if (next_ch == '>') {
  382. buf[i++] = __read_char();
  383. break;
  384. }
  385. /* fall through */
  386. case '+':
  387. case '|':
  388. case '&':
  389. case '>':
  390. case '<':
  391. last_ch = ch;
  392. ch = __peek_char();
  393. if (ch != last_ch)
  394. goto test_equal;
  395. buf[i++] = __read_char();
  396. switch (last_ch) {
  397. case '>':
  398. case '<':
  399. goto test_equal;
  400. default:
  401. break;
  402. }
  403. break;
  404. case '!':
  405. case '=':
  406. goto test_equal;
  407. default: /* what should we do instead? */
  408. break;
  409. }
  410. buf[i] = 0;
  411. *tok = strdup(buf);
  412. return type;
  413. test_equal:
  414. ch = __peek_char();
  415. if (ch == '=')
  416. buf[i++] = __read_char();
  417. break;
  418. case EVENT_DQUOTE:
  419. case EVENT_SQUOTE:
  420. /* don't keep quotes */
  421. i--;
  422. quote_ch = ch;
  423. last_ch = 0;
  424. do {
  425. if (i == (BUFSIZ - 1)) {
  426. buf[i] = 0;
  427. if (*tok) {
  428. *tok = realloc(*tok, tok_size + BUFSIZ);
  429. if (!*tok)
  430. return EVENT_NONE;
  431. strcat(*tok, buf);
  432. } else
  433. *tok = strdup(buf);
  434. if (!*tok)
  435. return EVENT_NONE;
  436. tok_size += BUFSIZ;
  437. i = 0;
  438. }
  439. last_ch = ch;
  440. ch = __read_char();
  441. buf[i++] = ch;
  442. /* the '\' '\' will cancel itself */
  443. if (ch == '\\' && last_ch == '\\')
  444. last_ch = 0;
  445. } while (ch != quote_ch || last_ch == '\\');
  446. /* remove the last quote */
  447. i--;
  448. goto out;
  449. case EVENT_ERROR ... EVENT_SPACE:
  450. case EVENT_ITEM:
  451. default:
  452. break;
  453. }
  454. while (get_type(__peek_char()) == type) {
  455. if (i == (BUFSIZ - 1)) {
  456. buf[i] = 0;
  457. if (*tok) {
  458. *tok = realloc(*tok, tok_size + BUFSIZ);
  459. if (!*tok)
  460. return EVENT_NONE;
  461. strcat(*tok, buf);
  462. } else
  463. *tok = strdup(buf);
  464. if (!*tok)
  465. return EVENT_NONE;
  466. tok_size += BUFSIZ;
  467. i = 0;
  468. }
  469. ch = __read_char();
  470. buf[i++] = ch;
  471. }
  472. out:
  473. buf[i] = 0;
  474. if (*tok) {
  475. *tok = realloc(*tok, tok_size + i);
  476. if (!*tok)
  477. return EVENT_NONE;
  478. strcat(*tok, buf);
  479. } else
  480. *tok = strdup(buf);
  481. if (!*tok)
  482. return EVENT_NONE;
  483. return type;
  484. }
  485. static void free_token(char *tok)
  486. {
  487. if (tok)
  488. free(tok);
  489. }
  490. static enum event_type read_token(char **tok)
  491. {
  492. enum event_type type;
  493. for (;;) {
  494. type = __read_token(tok);
  495. if (type != EVENT_SPACE)
  496. return type;
  497. free_token(*tok);
  498. }
  499. /* not reached */
  500. return EVENT_NONE;
  501. }
  502. /* no newline */
  503. static enum event_type read_token_item(char **tok)
  504. {
  505. enum event_type type;
  506. for (;;) {
  507. type = __read_token(tok);
  508. if (type != EVENT_SPACE && type != EVENT_NEWLINE)
  509. return type;
  510. free_token(*tok);
  511. }
  512. /* not reached */
  513. return EVENT_NONE;
  514. }
  515. static int test_type(enum event_type type, enum event_type expect)
  516. {
  517. if (type != expect) {
  518. warning("Error: expected type %d but read %d",
  519. expect, type);
  520. return -1;
  521. }
  522. return 0;
  523. }
  524. static int test_type_token(enum event_type type, char *token,
  525. enum event_type expect, const char *expect_tok)
  526. {
  527. if (type != expect) {
  528. warning("Error: expected type %d but read %d",
  529. expect, type);
  530. return -1;
  531. }
  532. if (strcmp(token, expect_tok) != 0) {
  533. warning("Error: expected '%s' but read '%s'",
  534. expect_tok, token);
  535. return -1;
  536. }
  537. return 0;
  538. }
  539. static int __read_expect_type(enum event_type expect, char **tok, int newline_ok)
  540. {
  541. enum event_type type;
  542. if (newline_ok)
  543. type = read_token(tok);
  544. else
  545. type = read_token_item(tok);
  546. return test_type(type, expect);
  547. }
  548. static int read_expect_type(enum event_type expect, char **tok)
  549. {
  550. return __read_expect_type(expect, tok, 1);
  551. }
  552. static int __read_expected(enum event_type expect, const char *str, int newline_ok)
  553. {
  554. enum event_type type;
  555. char *token;
  556. int ret;
  557. if (newline_ok)
  558. type = read_token(&token);
  559. else
  560. type = read_token_item(&token);
  561. ret = test_type_token(type, token, expect, str);
  562. free_token(token);
  563. return ret;
  564. }
  565. static int read_expected(enum event_type expect, const char *str)
  566. {
  567. return __read_expected(expect, str, 1);
  568. }
  569. static int read_expected_item(enum event_type expect, const char *str)
  570. {
  571. return __read_expected(expect, str, 0);
  572. }
  573. static char *event_read_name(void)
  574. {
  575. char *token;
  576. if (read_expected(EVENT_ITEM, (char *)"name") < 0)
  577. return NULL;
  578. if (read_expected(EVENT_OP, (char *)":") < 0)
  579. return NULL;
  580. if (read_expect_type(EVENT_ITEM, &token) < 0)
  581. goto fail;
  582. return token;
  583. fail:
  584. free_token(token);
  585. return NULL;
  586. }
  587. static int event_read_id(void)
  588. {
  589. char *token;
  590. int id;
  591. if (read_expected_item(EVENT_ITEM, (char *)"ID") < 0)
  592. return -1;
  593. if (read_expected(EVENT_OP, (char *)":") < 0)
  594. return -1;
  595. if (read_expect_type(EVENT_ITEM, &token) < 0)
  596. goto fail;
  597. id = strtoul(token, NULL, 0);
  598. free_token(token);
  599. return id;
  600. fail:
  601. free_token(token);
  602. return -1;
  603. }
  604. static int field_is_string(struct format_field *field)
  605. {
  606. if ((field->flags & FIELD_IS_ARRAY) &&
  607. (!strstr(field->type, "char") || !strstr(field->type, "u8") ||
  608. !strstr(field->type, "s8")))
  609. return 1;
  610. return 0;
  611. }
  612. static int field_is_dynamic(struct format_field *field)
  613. {
  614. if (!strcmp(field->type, "__data_loc"))
  615. return 1;
  616. return 0;
  617. }
  618. static int event_read_fields(struct event *event, struct format_field **fields)
  619. {
  620. struct format_field *field = NULL;
  621. enum event_type type;
  622. char *token;
  623. char *last_token;
  624. int count = 0;
  625. do {
  626. type = read_token(&token);
  627. if (type == EVENT_NEWLINE) {
  628. free_token(token);
  629. return count;
  630. }
  631. count++;
  632. if (test_type_token(type, token, EVENT_ITEM, (char *)"field"))
  633. goto fail;
  634. free_token(token);
  635. type = read_token(&token);
  636. /*
  637. * The ftrace fields may still use the "special" name.
  638. * Just ignore it.
  639. */
  640. if (event->flags & EVENT_FL_ISFTRACE &&
  641. type == EVENT_ITEM && strcmp(token, "special") == 0) {
  642. free_token(token);
  643. type = read_token(&token);
  644. }
  645. if (test_type_token(type, token, EVENT_OP, (char *)":") < 0)
  646. return -1;
  647. if (read_expect_type(EVENT_ITEM, &token) < 0)
  648. goto fail;
  649. last_token = token;
  650. field = malloc_or_die(sizeof(*field));
  651. memset(field, 0, sizeof(*field));
  652. /* read the rest of the type */
  653. for (;;) {
  654. type = read_token(&token);
  655. if (type == EVENT_ITEM ||
  656. (type == EVENT_OP && strcmp(token, "*") == 0) ||
  657. /*
  658. * Some of the ftrace fields are broken and have
  659. * an illegal "." in them.
  660. */
  661. (event->flags & EVENT_FL_ISFTRACE &&
  662. type == EVENT_OP && strcmp(token, ".") == 0)) {
  663. if (strcmp(token, "*") == 0)
  664. field->flags |= FIELD_IS_POINTER;
  665. if (field->type) {
  666. field->type = realloc(field->type,
  667. strlen(field->type) +
  668. strlen(last_token) + 2);
  669. strcat(field->type, " ");
  670. strcat(field->type, last_token);
  671. } else
  672. field->type = last_token;
  673. last_token = token;
  674. continue;
  675. }
  676. break;
  677. }
  678. if (!field->type) {
  679. die("no type found");
  680. goto fail;
  681. }
  682. field->name = last_token;
  683. if (test_type(type, EVENT_OP))
  684. goto fail;
  685. if (strcmp(token, "[") == 0) {
  686. enum event_type last_type = type;
  687. char *brackets = token;
  688. int len;
  689. field->flags |= FIELD_IS_ARRAY;
  690. type = read_token(&token);
  691. while (strcmp(token, "]") != 0) {
  692. if (last_type == EVENT_ITEM &&
  693. type == EVENT_ITEM)
  694. len = 2;
  695. else
  696. len = 1;
  697. last_type = type;
  698. brackets = realloc(brackets,
  699. strlen(brackets) +
  700. strlen(token) + len);
  701. if (len == 2)
  702. strcat(brackets, " ");
  703. strcat(brackets, token);
  704. free_token(token);
  705. type = read_token(&token);
  706. if (type == EVENT_NONE) {
  707. die("failed to find token");
  708. goto fail;
  709. }
  710. }
  711. free_token(token);
  712. brackets = realloc(brackets, strlen(brackets) + 2);
  713. strcat(brackets, "]");
  714. /* add brackets to type */
  715. type = read_token(&token);
  716. /*
  717. * If the next token is not an OP, then it is of
  718. * the format: type [] item;
  719. */
  720. if (type == EVENT_ITEM) {
  721. field->type = realloc(field->type,
  722. strlen(field->type) +
  723. strlen(field->name) +
  724. strlen(brackets) + 2);
  725. strcat(field->type, " ");
  726. strcat(field->type, field->name);
  727. free_token(field->name);
  728. strcat(field->type, brackets);
  729. field->name = token;
  730. type = read_token(&token);
  731. } else {
  732. field->type = realloc(field->type,
  733. strlen(field->type) +
  734. strlen(brackets) + 1);
  735. strcat(field->type, brackets);
  736. }
  737. free(brackets);
  738. }
  739. if (field_is_string(field)) {
  740. field->flags |= FIELD_IS_STRING;
  741. if (field_is_dynamic(field))
  742. field->flags |= FIELD_IS_DYNAMIC;
  743. }
  744. if (test_type_token(type, token, EVENT_OP, (char *)";"))
  745. goto fail;
  746. free_token(token);
  747. if (read_expected(EVENT_ITEM, (char *)"offset") < 0)
  748. goto fail_expect;
  749. if (read_expected(EVENT_OP, (char *)":") < 0)
  750. goto fail_expect;
  751. if (read_expect_type(EVENT_ITEM, &token))
  752. goto fail;
  753. field->offset = strtoul(token, NULL, 0);
  754. free_token(token);
  755. if (read_expected(EVENT_OP, (char *)";") < 0)
  756. goto fail_expect;
  757. if (read_expected(EVENT_ITEM, (char *)"size") < 0)
  758. goto fail_expect;
  759. if (read_expected(EVENT_OP, (char *)":") < 0)
  760. goto fail_expect;
  761. if (read_expect_type(EVENT_ITEM, &token))
  762. goto fail;
  763. field->size = strtoul(token, NULL, 0);
  764. free_token(token);
  765. if (read_expected(EVENT_OP, (char *)";") < 0)
  766. goto fail_expect;
  767. type = read_token(&token);
  768. if (type != EVENT_NEWLINE) {
  769. /* newer versions of the kernel have a "signed" type */
  770. if (test_type_token(type, token, EVENT_ITEM, (char *)"signed"))
  771. goto fail;
  772. free_token(token);
  773. if (read_expected(EVENT_OP, (char *)":") < 0)
  774. goto fail_expect;
  775. if (read_expect_type(EVENT_ITEM, &token))
  776. goto fail;
  777. /* add signed type */
  778. free_token(token);
  779. if (read_expected(EVENT_OP, (char *)";") < 0)
  780. goto fail_expect;
  781. if (read_expect_type(EVENT_NEWLINE, &token))
  782. goto fail;
  783. }
  784. free_token(token);
  785. *fields = field;
  786. fields = &field->next;
  787. } while (1);
  788. return 0;
  789. fail:
  790. free_token(token);
  791. fail_expect:
  792. if (field)
  793. free(field);
  794. return -1;
  795. }
  796. static int event_read_format(struct event *event)
  797. {
  798. char *token;
  799. int ret;
  800. if (read_expected_item(EVENT_ITEM, (char *)"format") < 0)
  801. return -1;
  802. if (read_expected(EVENT_OP, (char *)":") < 0)
  803. return -1;
  804. if (read_expect_type(EVENT_NEWLINE, &token))
  805. goto fail;
  806. free_token(token);
  807. ret = event_read_fields(event, &event->format.common_fields);
  808. if (ret < 0)
  809. return ret;
  810. event->format.nr_common = ret;
  811. ret = event_read_fields(event, &event->format.fields);
  812. if (ret < 0)
  813. return ret;
  814. event->format.nr_fields = ret;
  815. return 0;
  816. fail:
  817. free_token(token);
  818. return -1;
  819. }
  820. enum event_type
  821. process_arg_token(struct event *event, struct print_arg *arg,
  822. char **tok, enum event_type type);
  823. static enum event_type
  824. process_arg(struct event *event, struct print_arg *arg, char **tok)
  825. {
  826. enum event_type type;
  827. char *token;
  828. type = read_token(&token);
  829. *tok = token;
  830. return process_arg_token(event, arg, tok, type);
  831. }
  832. static enum event_type
  833. process_cond(struct event *event, struct print_arg *top, char **tok)
  834. {
  835. struct print_arg *arg, *left, *right;
  836. enum event_type type;
  837. char *token = NULL;
  838. arg = malloc_or_die(sizeof(*arg));
  839. memset(arg, 0, sizeof(*arg));
  840. left = malloc_or_die(sizeof(*left));
  841. right = malloc_or_die(sizeof(*right));
  842. arg->type = PRINT_OP;
  843. arg->op.left = left;
  844. arg->op.right = right;
  845. *tok = NULL;
  846. type = process_arg(event, left, &token);
  847. if (test_type_token(type, token, EVENT_OP, (char *)":"))
  848. goto out_free;
  849. arg->op.op = token;
  850. type = process_arg(event, right, &token);
  851. top->op.right = arg;
  852. *tok = token;
  853. return type;
  854. out_free:
  855. free_token(*tok);
  856. free(right);
  857. free(left);
  858. free_arg(arg);
  859. return EVENT_ERROR;
  860. }
  861. static enum event_type
  862. process_array(struct event *event, struct print_arg *top, char **tok)
  863. {
  864. struct print_arg *arg;
  865. enum event_type type;
  866. char *token = NULL;
  867. arg = malloc_or_die(sizeof(*arg));
  868. memset(arg, 0, sizeof(*arg));
  869. *tok = NULL;
  870. type = process_arg(event, arg, &token);
  871. if (test_type_token(type, token, EVENT_OP, (char *)"]"))
  872. goto out_free;
  873. top->op.right = arg;
  874. free_token(token);
  875. type = read_token_item(&token);
  876. *tok = token;
  877. return type;
  878. out_free:
  879. free_token(*tok);
  880. free_arg(arg);
  881. return EVENT_ERROR;
  882. }
  883. static int get_op_prio(char *op)
  884. {
  885. if (!op[1]) {
  886. switch (op[0]) {
  887. case '*':
  888. case '/':
  889. case '%':
  890. return 6;
  891. case '+':
  892. case '-':
  893. return 7;
  894. /* '>>' and '<<' are 8 */
  895. case '<':
  896. case '>':
  897. return 9;
  898. /* '==' and '!=' are 10 */
  899. case '&':
  900. return 11;
  901. case '^':
  902. return 12;
  903. case '|':
  904. return 13;
  905. case '?':
  906. return 16;
  907. default:
  908. die("unknown op '%c'", op[0]);
  909. return -1;
  910. }
  911. } else {
  912. if (strcmp(op, "++") == 0 ||
  913. strcmp(op, "--") == 0) {
  914. return 3;
  915. } else if (strcmp(op, ">>") == 0 ||
  916. strcmp(op, "<<") == 0) {
  917. return 8;
  918. } else if (strcmp(op, ">=") == 0 ||
  919. strcmp(op, "<=") == 0) {
  920. return 9;
  921. } else if (strcmp(op, "==") == 0 ||
  922. strcmp(op, "!=") == 0) {
  923. return 10;
  924. } else if (strcmp(op, "&&") == 0) {
  925. return 14;
  926. } else if (strcmp(op, "||") == 0) {
  927. return 15;
  928. } else {
  929. die("unknown op '%s'", op);
  930. return -1;
  931. }
  932. }
  933. }
  934. static void set_op_prio(struct print_arg *arg)
  935. {
  936. /* single ops are the greatest */
  937. if (!arg->op.left || arg->op.left->type == PRINT_NULL) {
  938. arg->op.prio = 0;
  939. return;
  940. }
  941. arg->op.prio = get_op_prio(arg->op.op);
  942. }
  943. static enum event_type
  944. process_op(struct event *event, struct print_arg *arg, char **tok)
  945. {
  946. struct print_arg *left, *right = NULL;
  947. enum event_type type;
  948. char *token;
  949. /* the op is passed in via tok */
  950. token = *tok;
  951. if (arg->type == PRINT_OP && !arg->op.left) {
  952. /* handle single op */
  953. if (token[1]) {
  954. die("bad op token %s", token);
  955. return EVENT_ERROR;
  956. }
  957. switch (token[0]) {
  958. case '!':
  959. case '+':
  960. case '-':
  961. break;
  962. default:
  963. die("bad op token %s", token);
  964. return EVENT_ERROR;
  965. }
  966. /* make an empty left */
  967. left = malloc_or_die(sizeof(*left));
  968. left->type = PRINT_NULL;
  969. arg->op.left = left;
  970. right = malloc_or_die(sizeof(*right));
  971. arg->op.right = right;
  972. type = process_arg(event, right, tok);
  973. } else if (strcmp(token, "?") == 0) {
  974. left = malloc_or_die(sizeof(*left));
  975. /* copy the top arg to the left */
  976. *left = *arg;
  977. arg->type = PRINT_OP;
  978. arg->op.op = token;
  979. arg->op.left = left;
  980. arg->op.prio = 0;
  981. type = process_cond(event, arg, tok);
  982. } else if (strcmp(token, ">>") == 0 ||
  983. strcmp(token, "<<") == 0 ||
  984. strcmp(token, "&") == 0 ||
  985. strcmp(token, "|") == 0 ||
  986. strcmp(token, "&&") == 0 ||
  987. strcmp(token, "||") == 0 ||
  988. strcmp(token, "-") == 0 ||
  989. strcmp(token, "+") == 0 ||
  990. strcmp(token, "*") == 0 ||
  991. strcmp(token, "^") == 0 ||
  992. strcmp(token, "/") == 0 ||
  993. strcmp(token, "<") == 0 ||
  994. strcmp(token, ">") == 0 ||
  995. strcmp(token, "==") == 0 ||
  996. strcmp(token, "!=") == 0) {
  997. left = malloc_or_die(sizeof(*left));
  998. /* copy the top arg to the left */
  999. *left = *arg;
  1000. arg->type = PRINT_OP;
  1001. arg->op.op = token;
  1002. arg->op.left = left;
  1003. set_op_prio(arg);
  1004. right = malloc_or_die(sizeof(*right));
  1005. type = read_token_item(&token);
  1006. *tok = token;
  1007. /* could just be a type pointer */
  1008. if ((strcmp(arg->op.op, "*") == 0) &&
  1009. type == EVENT_DELIM && (strcmp(token, ")") == 0)) {
  1010. if (left->type != PRINT_ATOM)
  1011. die("bad pointer type");
  1012. left->atom.atom = realloc(left->atom.atom,
  1013. sizeof(left->atom.atom) + 3);
  1014. strcat(left->atom.atom, " *");
  1015. *arg = *left;
  1016. free(arg);
  1017. return type;
  1018. }
  1019. type = process_arg_token(event, right, tok, type);
  1020. arg->op.right = right;
  1021. } else if (strcmp(token, "[") == 0) {
  1022. left = malloc_or_die(sizeof(*left));
  1023. *left = *arg;
  1024. arg->type = PRINT_OP;
  1025. arg->op.op = token;
  1026. arg->op.left = left;
  1027. arg->op.prio = 0;
  1028. type = process_array(event, arg, tok);
  1029. } else {
  1030. warning("unknown op '%s'", token);
  1031. event->flags |= EVENT_FL_FAILED;
  1032. /* the arg is now the left side */
  1033. return EVENT_NONE;
  1034. }
  1035. if (type == EVENT_OP) {
  1036. int prio;
  1037. /* higher prios need to be closer to the root */
  1038. prio = get_op_prio(*tok);
  1039. if (prio > arg->op.prio)
  1040. return process_op(event, arg, tok);
  1041. return process_op(event, right, tok);
  1042. }
  1043. return type;
  1044. }
  1045. static enum event_type
  1046. process_entry(struct event *event __unused, struct print_arg *arg,
  1047. char **tok)
  1048. {
  1049. enum event_type type;
  1050. char *field;
  1051. char *token;
  1052. if (read_expected(EVENT_OP, (char *)"->") < 0)
  1053. return EVENT_ERROR;
  1054. if (read_expect_type(EVENT_ITEM, &token) < 0)
  1055. goto fail;
  1056. field = token;
  1057. arg->type = PRINT_FIELD;
  1058. arg->field.name = field;
  1059. type = read_token(&token);
  1060. *tok = token;
  1061. return type;
  1062. fail:
  1063. free_token(token);
  1064. return EVENT_ERROR;
  1065. }
  1066. static char *arg_eval (struct print_arg *arg);
  1067. static long long arg_num_eval(struct print_arg *arg)
  1068. {
  1069. long long left, right;
  1070. long long val = 0;
  1071. switch (arg->type) {
  1072. case PRINT_ATOM:
  1073. val = strtoll(arg->atom.atom, NULL, 0);
  1074. break;
  1075. case PRINT_TYPE:
  1076. val = arg_num_eval(arg->typecast.item);
  1077. break;
  1078. case PRINT_OP:
  1079. switch (arg->op.op[0]) {
  1080. case '|':
  1081. left = arg_num_eval(arg->op.left);
  1082. right = arg_num_eval(arg->op.right);
  1083. if (arg->op.op[1])
  1084. val = left || right;
  1085. else
  1086. val = left | right;
  1087. break;
  1088. case '&':
  1089. left = arg_num_eval(arg->op.left);
  1090. right = arg_num_eval(arg->op.right);
  1091. if (arg->op.op[1])
  1092. val = left && right;
  1093. else
  1094. val = left & right;
  1095. break;
  1096. case '<':
  1097. left = arg_num_eval(arg->op.left);
  1098. right = arg_num_eval(arg->op.right);
  1099. switch (arg->op.op[1]) {
  1100. case 0:
  1101. val = left < right;
  1102. break;
  1103. case '<':
  1104. val = left << right;
  1105. break;
  1106. case '=':
  1107. val = left <= right;
  1108. break;
  1109. default:
  1110. die("unknown op '%s'", arg->op.op);
  1111. }
  1112. break;
  1113. case '>':
  1114. left = arg_num_eval(arg->op.left);
  1115. right = arg_num_eval(arg->op.right);
  1116. switch (arg->op.op[1]) {
  1117. case 0:
  1118. val = left > right;
  1119. break;
  1120. case '>':
  1121. val = left >> right;
  1122. break;
  1123. case '=':
  1124. val = left >= right;
  1125. break;
  1126. default:
  1127. die("unknown op '%s'", arg->op.op);
  1128. }
  1129. break;
  1130. case '=':
  1131. left = arg_num_eval(arg->op.left);
  1132. right = arg_num_eval(arg->op.right);
  1133. if (arg->op.op[1] != '=')
  1134. die("unknown op '%s'", arg->op.op);
  1135. val = left == right;
  1136. break;
  1137. case '!':
  1138. left = arg_num_eval(arg->op.left);
  1139. right = arg_num_eval(arg->op.right);
  1140. switch (arg->op.op[1]) {
  1141. case '=':
  1142. val = left != right;
  1143. break;
  1144. default:
  1145. die("unknown op '%s'", arg->op.op);
  1146. }
  1147. break;
  1148. default:
  1149. die("unknown op '%s'", arg->op.op);
  1150. }
  1151. break;
  1152. case PRINT_NULL:
  1153. case PRINT_FIELD ... PRINT_SYMBOL:
  1154. case PRINT_STRING:
  1155. default:
  1156. die("invalid eval type %d", arg->type);
  1157. }
  1158. return val;
  1159. }
  1160. static char *arg_eval (struct print_arg *arg)
  1161. {
  1162. long long val;
  1163. static char buf[20];
  1164. switch (arg->type) {
  1165. case PRINT_ATOM:
  1166. return arg->atom.atom;
  1167. case PRINT_TYPE:
  1168. return arg_eval(arg->typecast.item);
  1169. case PRINT_OP:
  1170. val = arg_num_eval(arg);
  1171. sprintf(buf, "%lld", val);
  1172. return buf;
  1173. case PRINT_NULL:
  1174. case PRINT_FIELD ... PRINT_SYMBOL:
  1175. case PRINT_STRING:
  1176. default:
  1177. die("invalid eval type %d", arg->type);
  1178. break;
  1179. }
  1180. return NULL;
  1181. }
  1182. static enum event_type
  1183. process_fields(struct event *event, struct print_flag_sym **list, char **tok)
  1184. {
  1185. enum event_type type;
  1186. struct print_arg *arg = NULL;
  1187. struct print_flag_sym *field;
  1188. char *token = NULL;
  1189. char *value;
  1190. do {
  1191. free_token(token);
  1192. type = read_token_item(&token);
  1193. if (test_type_token(type, token, EVENT_OP, (char *)"{"))
  1194. break;
  1195. arg = malloc_or_die(sizeof(*arg));
  1196. free_token(token);
  1197. type = process_arg(event, arg, &token);
  1198. if (test_type_token(type, token, EVENT_DELIM, (char *)","))
  1199. goto out_free;
  1200. field = malloc_or_die(sizeof(*field));
  1201. memset(field, 0, sizeof(field));
  1202. value = arg_eval(arg);
  1203. field->value = strdup(value);
  1204. free_token(token);
  1205. type = process_arg(event, arg, &token);
  1206. if (test_type_token(type, token, EVENT_OP, (char *)"}"))
  1207. goto out_free;
  1208. value = arg_eval(arg);
  1209. field->str = strdup(value);
  1210. free_arg(arg);
  1211. arg = NULL;
  1212. *list = field;
  1213. list = &field->next;
  1214. free_token(token);
  1215. type = read_token_item(&token);
  1216. } while (type == EVENT_DELIM && strcmp(token, ",") == 0);
  1217. *tok = token;
  1218. return type;
  1219. out_free:
  1220. free_arg(arg);
  1221. free_token(token);
  1222. return EVENT_ERROR;
  1223. }
  1224. static enum event_type
  1225. process_flags(struct event *event, struct print_arg *arg, char **tok)
  1226. {
  1227. struct print_arg *field;
  1228. enum event_type type;
  1229. char *token;
  1230. memset(arg, 0, sizeof(*arg));
  1231. arg->type = PRINT_FLAGS;
  1232. if (read_expected_item(EVENT_DELIM, (char *)"(") < 0)
  1233. return EVENT_ERROR;
  1234. field = malloc_or_die(sizeof(*field));
  1235. type = process_arg(event, field, &token);
  1236. if (test_type_token(type, token, EVENT_DELIM, (char *)","))
  1237. goto out_free;
  1238. arg->flags.field = field;
  1239. type = read_token_item(&token);
  1240. if (event_item_type(type)) {
  1241. arg->flags.delim = token;
  1242. type = read_token_item(&token);
  1243. }
  1244. if (test_type_token(type, token, EVENT_DELIM, (char *)","))
  1245. goto out_free;
  1246. type = process_fields(event, &arg->flags.flags, &token);
  1247. if (test_type_token(type, token, EVENT_DELIM, (char *)")"))
  1248. goto out_free;
  1249. free_token(token);
  1250. type = read_token_item(tok);
  1251. return type;
  1252. out_free:
  1253. free_token(token);
  1254. return EVENT_ERROR;
  1255. }
  1256. static enum event_type
  1257. process_symbols(struct event *event, struct print_arg *arg, char **tok)
  1258. {
  1259. struct print_arg *field;
  1260. enum event_type type;
  1261. char *token;
  1262. memset(arg, 0, sizeof(*arg));
  1263. arg->type = PRINT_SYMBOL;
  1264. if (read_expected_item(EVENT_DELIM, (char *)"(") < 0)
  1265. return EVENT_ERROR;
  1266. field = malloc_or_die(sizeof(*field));
  1267. type = process_arg(event, field, &token);
  1268. if (test_type_token(type, token, EVENT_DELIM, (char *)","))
  1269. goto out_free;
  1270. arg->symbol.field = field;
  1271. type = process_fields(event, &arg->symbol.symbols, &token);
  1272. if (test_type_token(type, token, EVENT_DELIM, (char *)")"))
  1273. goto out_free;
  1274. free_token(token);
  1275. type = read_token_item(tok);
  1276. return type;
  1277. out_free:
  1278. free_token(token);
  1279. return EVENT_ERROR;
  1280. }
  1281. static enum event_type
  1282. process_paren(struct event *event, struct print_arg *arg, char **tok)
  1283. {
  1284. struct print_arg *item_arg;
  1285. enum event_type type;
  1286. char *token;
  1287. type = process_arg(event, arg, &token);
  1288. if (type == EVENT_ERROR)
  1289. return EVENT_ERROR;
  1290. if (type == EVENT_OP)
  1291. type = process_op(event, arg, &token);
  1292. if (type == EVENT_ERROR)
  1293. return EVENT_ERROR;
  1294. if (test_type_token(type, token, EVENT_DELIM, (char *)")")) {
  1295. free_token(token);
  1296. return EVENT_ERROR;
  1297. }
  1298. free_token(token);
  1299. type = read_token_item(&token);
  1300. /*
  1301. * If the next token is an item or another open paren, then
  1302. * this was a typecast.
  1303. */
  1304. if (event_item_type(type) ||
  1305. (type == EVENT_DELIM && strcmp(token, "(") == 0)) {
  1306. /* make this a typecast and contine */
  1307. /* prevous must be an atom */
  1308. if (arg->type != PRINT_ATOM)
  1309. die("previous needed to be PRINT_ATOM");
  1310. item_arg = malloc_or_die(sizeof(*item_arg));
  1311. arg->type = PRINT_TYPE;
  1312. arg->typecast.type = arg->atom.atom;
  1313. arg->typecast.item = item_arg;
  1314. type = process_arg_token(event, item_arg, &token, type);
  1315. }
  1316. *tok = token;
  1317. return type;
  1318. }
  1319. static enum event_type
  1320. process_str(struct event *event __unused, struct print_arg *arg, char **tok)
  1321. {
  1322. enum event_type type;
  1323. char *token;
  1324. if (read_expected(EVENT_DELIM, (char *)"(") < 0)
  1325. return EVENT_ERROR;
  1326. if (read_expect_type(EVENT_ITEM, &token) < 0)
  1327. goto fail;
  1328. arg->type = PRINT_STRING;
  1329. arg->string.string = token;
  1330. arg->string.offset = -1;
  1331. if (read_expected(EVENT_DELIM, (char *)")") < 0)
  1332. return EVENT_ERROR;
  1333. type = read_token(&token);
  1334. *tok = token;
  1335. return type;
  1336. fail:
  1337. free_token(token);
  1338. return EVENT_ERROR;
  1339. }
  1340. enum event_type
  1341. process_arg_token(struct event *event, struct print_arg *arg,
  1342. char **tok, enum event_type type)
  1343. {
  1344. char *token;
  1345. char *atom;
  1346. token = *tok;
  1347. switch (type) {
  1348. case EVENT_ITEM:
  1349. if (strcmp(token, "REC") == 0) {
  1350. free_token(token);
  1351. type = process_entry(event, arg, &token);
  1352. } else if (strcmp(token, "__print_flags") == 0) {
  1353. free_token(token);
  1354. type = process_flags(event, arg, &token);
  1355. } else if (strcmp(token, "__print_symbolic") == 0) {
  1356. free_token(token);
  1357. type = process_symbols(event, arg, &token);
  1358. } else if (strcmp(token, "__get_str") == 0) {
  1359. free_token(token);
  1360. type = process_str(event, arg, &token);
  1361. } else {
  1362. atom = token;
  1363. /* test the next token */
  1364. type = read_token_item(&token);
  1365. /* atoms can be more than one token long */
  1366. while (type == EVENT_ITEM) {
  1367. atom = realloc(atom, strlen(atom) + strlen(token) + 2);
  1368. strcat(atom, " ");
  1369. strcat(atom, token);
  1370. free_token(token);
  1371. type = read_token_item(&token);
  1372. }
  1373. /* todo, test for function */
  1374. arg->type = PRINT_ATOM;
  1375. arg->atom.atom = atom;
  1376. }
  1377. break;
  1378. case EVENT_DQUOTE:
  1379. case EVENT_SQUOTE:
  1380. arg->type = PRINT_ATOM;
  1381. arg->atom.atom = token;
  1382. type = read_token_item(&token);
  1383. break;
  1384. case EVENT_DELIM:
  1385. if (strcmp(token, "(") == 0) {
  1386. free_token(token);
  1387. type = process_paren(event, arg, &token);
  1388. break;
  1389. }
  1390. case EVENT_OP:
  1391. /* handle single ops */
  1392. arg->type = PRINT_OP;
  1393. arg->op.op = token;
  1394. arg->op.left = NULL;
  1395. type = process_op(event, arg, &token);
  1396. break;
  1397. case EVENT_ERROR ... EVENT_NEWLINE:
  1398. default:
  1399. die("unexpected type %d", type);
  1400. }
  1401. *tok = token;
  1402. return type;
  1403. }
  1404. static int event_read_print_args(struct event *event, struct print_arg **list)
  1405. {
  1406. enum event_type type = EVENT_ERROR;
  1407. struct print_arg *arg;
  1408. char *token;
  1409. int args = 0;
  1410. do {
  1411. if (type == EVENT_NEWLINE) {
  1412. free_token(token);
  1413. type = read_token_item(&token);
  1414. continue;
  1415. }
  1416. arg = malloc_or_die(sizeof(*arg));
  1417. memset(arg, 0, sizeof(*arg));
  1418. type = process_arg(event, arg, &token);
  1419. if (type == EVENT_ERROR) {
  1420. free_arg(arg);
  1421. return -1;
  1422. }
  1423. *list = arg;
  1424. args++;
  1425. if (type == EVENT_OP) {
  1426. type = process_op(event, arg, &token);
  1427. list = &arg->next;
  1428. continue;
  1429. }
  1430. if (type == EVENT_DELIM && strcmp(token, ",") == 0) {
  1431. free_token(token);
  1432. *list = arg;
  1433. list = &arg->next;
  1434. continue;
  1435. }
  1436. break;
  1437. } while (type != EVENT_NONE);
  1438. if (type != EVENT_NONE)
  1439. free_token(token);
  1440. return args;
  1441. }
  1442. static int event_read_print(struct event *event)
  1443. {
  1444. enum event_type type;
  1445. char *token;
  1446. int ret;
  1447. if (read_expected_item(EVENT_ITEM, (char *)"print") < 0)
  1448. return -1;
  1449. if (read_expected(EVENT_ITEM, (char *)"fmt") < 0)
  1450. return -1;
  1451. if (read_expected(EVENT_OP, (char *)":") < 0)
  1452. return -1;
  1453. if (read_expect_type(EVENT_DQUOTE, &token) < 0)
  1454. goto fail;
  1455. concat:
  1456. event->print_fmt.format = token;
  1457. event->print_fmt.args = NULL;
  1458. /* ok to have no arg */
  1459. type = read_token_item(&token);
  1460. if (type == EVENT_NONE)
  1461. return 0;
  1462. /* Handle concatination of print lines */
  1463. if (type == EVENT_DQUOTE) {
  1464. char *cat;
  1465. cat = malloc_or_die(strlen(event->print_fmt.format) +
  1466. strlen(token) + 1);
  1467. strcpy(cat, event->print_fmt.format);
  1468. strcat(cat, token);
  1469. free_token(token);
  1470. free_token(event->print_fmt.format);
  1471. event->print_fmt.format = NULL;
  1472. token = cat;
  1473. goto concat;
  1474. }
  1475. if (test_type_token(type, token, EVENT_DELIM, (char *)","))
  1476. goto fail;
  1477. free_token(token);
  1478. ret = event_read_print_args(event, &event->print_fmt.args);
  1479. if (ret < 0)
  1480. return -1;
  1481. return 0;
  1482. fail:
  1483. free_token(token);
  1484. return -1;
  1485. }
  1486. static struct format_field *
  1487. find_common_field(struct event *event, const char *name)
  1488. {
  1489. struct format_field *format;
  1490. for (format = event->format.common_fields;
  1491. format; format = format->next) {
  1492. if (strcmp(format->name, name) == 0)
  1493. break;
  1494. }
  1495. return format;
  1496. }
  1497. static struct format_field *
  1498. find_field(struct event *event, const char *name)
  1499. {
  1500. struct format_field *format;
  1501. for (format = event->format.fields;
  1502. format; format = format->next) {
  1503. if (strcmp(format->name, name) == 0)
  1504. break;
  1505. }
  1506. return format;
  1507. }
  1508. static struct format_field *
  1509. find_any_field(struct event *event, const char *name)
  1510. {
  1511. struct format_field *format;
  1512. format = find_common_field(event, name);
  1513. if (format)
  1514. return format;
  1515. return find_field(event, name);
  1516. }
  1517. static unsigned long long read_size(void *ptr, int size)
  1518. {
  1519. switch (size) {
  1520. case 1:
  1521. return *(unsigned char *)ptr;
  1522. case 2:
  1523. return data2host2(ptr);
  1524. case 4:
  1525. return data2host4(ptr);
  1526. case 8:
  1527. return data2host8(ptr);
  1528. default:
  1529. /* BUG! */
  1530. return 0;
  1531. }
  1532. }
  1533. unsigned long long
  1534. raw_field_value(struct event *event, const char *name, void *data)
  1535. {
  1536. struct format_field *field;
  1537. field = find_any_field(event, name);
  1538. if (!field)
  1539. return 0ULL;
  1540. return read_size(data + field->offset, field->size);
  1541. }
  1542. void *raw_field_ptr(struct event *event, const char *name, void *data)
  1543. {
  1544. struct format_field *field;
  1545. field = find_any_field(event, name);
  1546. if (!field)
  1547. return NULL;
  1548. return data + field->offset;
  1549. }
  1550. static int get_common_info(const char *type, int *offset, int *size)
  1551. {
  1552. struct event *event;
  1553. struct format_field *field;
  1554. /*
  1555. * All events should have the same common elements.
  1556. * Pick any event to find where the type is;
  1557. */
  1558. if (!event_list)
  1559. die("no event_list!");
  1560. event = event_list;
  1561. field = find_common_field(event, type);
  1562. if (!field)
  1563. die("field '%s' not found", type);
  1564. *offset = field->offset;
  1565. *size = field->size;
  1566. return 0;
  1567. }
  1568. int trace_parse_common_type(void *data)
  1569. {
  1570. static int type_offset;
  1571. static int type_size;
  1572. int ret;
  1573. if (!type_size) {
  1574. ret = get_common_info("common_type",
  1575. &type_offset,
  1576. &type_size);
  1577. if (ret < 0)
  1578. return ret;
  1579. }
  1580. return read_size(data + type_offset, type_size);
  1581. }
  1582. static int parse_common_pid(void *data)
  1583. {
  1584. static int pid_offset;
  1585. static int pid_size;
  1586. int ret;
  1587. if (!pid_size) {
  1588. ret = get_common_info("common_pid",
  1589. &pid_offset,
  1590. &pid_size);
  1591. if (ret < 0)
  1592. return ret;
  1593. }
  1594. return read_size(data + pid_offset, pid_size);
  1595. }
  1596. struct event *trace_find_event(int id)
  1597. {
  1598. struct event *event;
  1599. for (event = event_list; event; event = event->next) {
  1600. if (event->id == id)
  1601. break;
  1602. }
  1603. return event;
  1604. }
  1605. static unsigned long long eval_num_arg(void *data, int size,
  1606. struct event *event, struct print_arg *arg)
  1607. {
  1608. unsigned long long val = 0;
  1609. unsigned long long left, right;
  1610. struct print_arg *larg;
  1611. switch (arg->type) {
  1612. case PRINT_NULL:
  1613. /* ?? */
  1614. return 0;
  1615. case PRINT_ATOM:
  1616. return strtoull(arg->atom.atom, NULL, 0);
  1617. case PRINT_FIELD:
  1618. if (!arg->field.field) {
  1619. arg->field.field = find_any_field(event, arg->field.name);
  1620. if (!arg->field.field)
  1621. die("field %s not found", arg->field.name);
  1622. }
  1623. /* must be a number */
  1624. val = read_size(data + arg->field.field->offset,
  1625. arg->field.field->size);
  1626. break;
  1627. case PRINT_FLAGS:
  1628. case PRINT_SYMBOL:
  1629. break;
  1630. case PRINT_TYPE:
  1631. return eval_num_arg(data, size, event, arg->typecast.item);
  1632. case PRINT_STRING:
  1633. return 0;
  1634. break;
  1635. case PRINT_OP:
  1636. if (strcmp(arg->op.op, "[") == 0) {
  1637. /*
  1638. * Arrays are special, since we don't want
  1639. * to read the arg as is.
  1640. */
  1641. if (arg->op.left->type != PRINT_FIELD)
  1642. goto default_op; /* oops, all bets off */
  1643. larg = arg->op.left;
  1644. if (!larg->field.field) {
  1645. larg->field.field =
  1646. find_any_field(event, larg->field.name);
  1647. if (!larg->field.field)
  1648. die("field %s not found", larg->field.name);
  1649. }
  1650. right = eval_num_arg(data, size, event, arg->op.right);
  1651. val = read_size(data + larg->field.field->offset +
  1652. right * long_size, long_size);
  1653. break;
  1654. }
  1655. default_op:
  1656. left = eval_num_arg(data, size, event, arg->op.left);
  1657. right = eval_num_arg(data, size, event, arg->op.right);
  1658. switch (arg->op.op[0]) {
  1659. case '|':
  1660. if (arg->op.op[1])
  1661. val = left || right;
  1662. else
  1663. val = left | right;
  1664. break;
  1665. case '&':
  1666. if (arg->op.op[1])
  1667. val = left && right;
  1668. else
  1669. val = left & right;
  1670. break;
  1671. case '<':
  1672. switch (arg->op.op[1]) {
  1673. case 0:
  1674. val = left < right;
  1675. break;
  1676. case '<':
  1677. val = left << right;
  1678. break;
  1679. case '=':
  1680. val = left <= right;
  1681. break;
  1682. default:
  1683. die("unknown op '%s'", arg->op.op);
  1684. }
  1685. break;
  1686. case '>':
  1687. switch (arg->op.op[1]) {
  1688. case 0:
  1689. val = left > right;
  1690. break;
  1691. case '>':
  1692. val = left >> right;
  1693. break;
  1694. case '=':
  1695. val = left >= right;
  1696. break;
  1697. default:
  1698. die("unknown op '%s'", arg->op.op);
  1699. }
  1700. break;
  1701. case '=':
  1702. if (arg->op.op[1] != '=')
  1703. die("unknown op '%s'", arg->op.op);
  1704. val = left == right;
  1705. break;
  1706. default:
  1707. die("unknown op '%s'", arg->op.op);
  1708. }
  1709. break;
  1710. default: /* not sure what to do there */
  1711. return 0;
  1712. }
  1713. return val;
  1714. }
  1715. struct flag {
  1716. const char *name;
  1717. unsigned long long value;
  1718. };
  1719. static const struct flag flags[] = {
  1720. { "HI_SOFTIRQ", 0 },
  1721. { "TIMER_SOFTIRQ", 1 },
  1722. { "NET_TX_SOFTIRQ", 2 },
  1723. { "NET_RX_SOFTIRQ", 3 },
  1724. { "BLOCK_SOFTIRQ", 4 },
  1725. { "BLOCK_IOPOLL_SOFTIRQ", 5 },
  1726. { "TASKLET_SOFTIRQ", 6 },
  1727. { "SCHED_SOFTIRQ", 7 },
  1728. { "HRTIMER_SOFTIRQ", 8 },
  1729. { "RCU_SOFTIRQ", 9 },
  1730. { "HRTIMER_NORESTART", 0 },
  1731. { "HRTIMER_RESTART", 1 },
  1732. };
  1733. static unsigned long long eval_flag(const char *flag)
  1734. {
  1735. int i;
  1736. /*
  1737. * Some flags in the format files do not get converted.
  1738. * If the flag is not numeric, see if it is something that
  1739. * we already know about.
  1740. */
  1741. if (isdigit(flag[0]))
  1742. return strtoull(flag, NULL, 0);
  1743. for (i = 0; i < (int)(sizeof(flags)/sizeof(flags[0])); i++)
  1744. if (strcmp(flags[i].name, flag) == 0)
  1745. return flags[i].value;
  1746. return 0;
  1747. }
  1748. static void print_str_arg(void *data, int size,
  1749. struct event *event, struct print_arg *arg)
  1750. {
  1751. struct print_flag_sym *flag;
  1752. unsigned long long val, fval;
  1753. char *str;
  1754. int print;
  1755. switch (arg->type) {
  1756. case PRINT_NULL:
  1757. /* ?? */
  1758. return;
  1759. case PRINT_ATOM:
  1760. printf("%s", arg->atom.atom);
  1761. return;
  1762. case PRINT_FIELD:
  1763. if (!arg->field.field) {
  1764. arg->field.field = find_any_field(event, arg->field.name);
  1765. if (!arg->field.field)
  1766. die("field %s not found", arg->field.name);
  1767. }
  1768. str = malloc_or_die(arg->field.field->size + 1);
  1769. memcpy(str, data + arg->field.field->offset,
  1770. arg->field.field->size);
  1771. str[arg->field.field->size] = 0;
  1772. printf("%s", str);
  1773. free(str);
  1774. break;
  1775. case PRINT_FLAGS:
  1776. val = eval_num_arg(data, size, event, arg->flags.field);
  1777. print = 0;
  1778. for (flag = arg->flags.flags; flag; flag = flag->next) {
  1779. fval = eval_flag(flag->value);
  1780. if (!val && !fval) {
  1781. printf("%s", flag->str);
  1782. break;
  1783. }
  1784. if (fval && (val & fval) == fval) {
  1785. if (print && arg->flags.delim)
  1786. printf("%s", arg->flags.delim);
  1787. printf("%s", flag->str);
  1788. print = 1;
  1789. val &= ~fval;
  1790. }
  1791. }
  1792. break;
  1793. case PRINT_SYMBOL:
  1794. val = eval_num_arg(data, size, event, arg->symbol.field);
  1795. for (flag = arg->symbol.symbols; flag; flag = flag->next) {
  1796. fval = eval_flag(flag->value);
  1797. if (val == fval) {
  1798. printf("%s", flag->str);
  1799. break;
  1800. }
  1801. }
  1802. break;
  1803. case PRINT_TYPE:
  1804. break;
  1805. case PRINT_STRING: {
  1806. int str_offset;
  1807. if (arg->string.offset == -1) {
  1808. struct format_field *f;
  1809. f = find_any_field(event, arg->string.string);
  1810. arg->string.offset = f->offset;
  1811. }
  1812. str_offset = *(int *)(data + arg->string.offset);
  1813. str_offset &= 0xffff;
  1814. printf("%s", ((char *)data) + str_offset);
  1815. break;
  1816. }
  1817. case PRINT_OP:
  1818. /*
  1819. * The only op for string should be ? :
  1820. */
  1821. if (arg->op.op[0] != '?')
  1822. return;
  1823. val = eval_num_arg(data, size, event, arg->op.left);
  1824. if (val)
  1825. print_str_arg(data, size, event, arg->op.right->op.left);
  1826. else
  1827. print_str_arg(data, size, event, arg->op.right->op.right);
  1828. break;
  1829. default:
  1830. /* well... */
  1831. break;
  1832. }
  1833. }
  1834. static struct print_arg *make_bprint_args(char *fmt, void *data, int size, struct event *event)
  1835. {
  1836. static struct format_field *field, *ip_field;
  1837. struct print_arg *args, *arg, **next;
  1838. unsigned long long ip, val;
  1839. char *ptr;
  1840. void *bptr;
  1841. if (!field) {
  1842. field = find_field(event, "buf");
  1843. if (!field)
  1844. die("can't find buffer field for binary printk");
  1845. ip_field = find_field(event, "ip");
  1846. if (!ip_field)
  1847. die("can't find ip field for binary printk");
  1848. }
  1849. ip = read_size(data + ip_field->offset, ip_field->size);
  1850. /*
  1851. * The first arg is the IP pointer.
  1852. */
  1853. args = malloc_or_die(sizeof(*args));
  1854. arg = args;
  1855. arg->next = NULL;
  1856. next = &arg->next;
  1857. arg->type = PRINT_ATOM;
  1858. arg->atom.atom = malloc_or_die(32);
  1859. sprintf(arg->atom.atom, "%lld", ip);
  1860. /* skip the first "%pf : " */
  1861. for (ptr = fmt + 6, bptr = data + field->offset;
  1862. bptr < data + size && *ptr; ptr++) {
  1863. int ls = 0;
  1864. if (*ptr == '%') {
  1865. process_again:
  1866. ptr++;
  1867. switch (*ptr) {
  1868. case '%':
  1869. break;
  1870. case 'l':
  1871. ls++;
  1872. goto process_again;
  1873. case 'L':
  1874. ls = 2;
  1875. goto process_again;
  1876. case '0' ... '9':
  1877. goto process_again;
  1878. case 'p':
  1879. ls = 1;
  1880. /* fall through */
  1881. case 'd':
  1882. case 'u':
  1883. case 'x':
  1884. case 'i':
  1885. /* the pointers are always 4 bytes aligned */
  1886. bptr = (void *)(((unsigned long)bptr + 3) &
  1887. ~3);
  1888. switch (ls) {
  1889. case 0:
  1890. case 1:
  1891. ls = long_size;
  1892. break;
  1893. case 2:
  1894. ls = 8;
  1895. default:
  1896. break;
  1897. }
  1898. val = read_size(bptr, ls);
  1899. bptr += ls;
  1900. arg = malloc_or_die(sizeof(*arg));
  1901. arg->next = NULL;
  1902. arg->type = PRINT_ATOM;
  1903. arg->atom.atom = malloc_or_die(32);
  1904. sprintf(arg->atom.atom, "%lld", val);
  1905. *next = arg;
  1906. next = &arg->next;
  1907. break;
  1908. case 's':
  1909. arg = malloc_or_die(sizeof(*arg));
  1910. arg->next = NULL;
  1911. arg->type = PRINT_STRING;
  1912. arg->string.string = strdup(bptr);
  1913. bptr += strlen(bptr) + 1;
  1914. *next = arg;
  1915. next = &arg->next;
  1916. default:
  1917. break;
  1918. }
  1919. }
  1920. }
  1921. return args;
  1922. }
  1923. static void free_args(struct print_arg *args)
  1924. {
  1925. struct print_arg *next;
  1926. while (args) {
  1927. next = args->next;
  1928. if (args->type == PRINT_ATOM)
  1929. free(args->atom.atom);
  1930. else
  1931. free(args->string.string);
  1932. free(args);
  1933. args = next;
  1934. }
  1935. }
  1936. static char *get_bprint_format(void *data, int size __unused, struct event *event)
  1937. {
  1938. unsigned long long addr;
  1939. static struct format_field *field;
  1940. struct printk_map *printk;
  1941. char *format;
  1942. char *p;
  1943. if (!field) {
  1944. field = find_field(event, "fmt");
  1945. if (!field)
  1946. die("can't find format field for binary printk");
  1947. printf("field->offset = %d size=%d\n", field->offset, field->size);
  1948. }
  1949. addr = read_size(data + field->offset, field->size);
  1950. printk = find_printk(addr);
  1951. if (!printk) {
  1952. format = malloc_or_die(45);
  1953. sprintf(format, "%%pf : (NO FORMAT FOUND at %llx)\n",
  1954. addr);
  1955. return format;
  1956. }
  1957. p = printk->printk;
  1958. /* Remove any quotes. */
  1959. if (*p == '"')
  1960. p++;
  1961. format = malloc_or_die(strlen(p) + 10);
  1962. sprintf(format, "%s : %s", "%pf", p);
  1963. /* remove ending quotes and new line since we will add one too */
  1964. p = format + strlen(format) - 1;
  1965. if (*p == '"')
  1966. *p = 0;
  1967. p -= 2;
  1968. if (strcmp(p, "\\n") == 0)
  1969. *p = 0;
  1970. return format;
  1971. }
  1972. static void pretty_print(void *data, int size, struct event *event)
  1973. {
  1974. struct print_fmt *print_fmt = &event->print_fmt;
  1975. struct print_arg *arg = print_fmt->args;
  1976. struct print_arg *args = NULL;
  1977. const char *ptr = print_fmt->format;
  1978. unsigned long long val;
  1979. struct func_map *func;
  1980. const char *saveptr;
  1981. char *bprint_fmt = NULL;
  1982. char format[32];
  1983. int show_func;
  1984. int len;
  1985. int ls;
  1986. if (event->flags & EVENT_FL_ISFUNC)
  1987. ptr = " %pF <-- %pF";
  1988. if (event->flags & EVENT_FL_ISBPRINT) {
  1989. bprint_fmt = get_bprint_format(data, size, event);
  1990. args = make_bprint_args(bprint_fmt, data, size, event);
  1991. arg = args;
  1992. ptr = bprint_fmt;
  1993. }
  1994. for (; *ptr; ptr++) {
  1995. ls = 0;
  1996. if (*ptr == '\\') {
  1997. ptr++;
  1998. switch (*ptr) {
  1999. case 'n':
  2000. printf("\n");
  2001. break;
  2002. case 't':
  2003. printf("\t");
  2004. break;
  2005. case 'r':
  2006. printf("\r");
  2007. break;
  2008. case '\\':
  2009. printf("\\");
  2010. break;
  2011. default:
  2012. printf("%c", *ptr);
  2013. break;
  2014. }
  2015. } else if (*ptr == '%') {
  2016. saveptr = ptr;
  2017. show_func = 0;
  2018. cont_process:
  2019. ptr++;
  2020. switch (*ptr) {
  2021. case '%':
  2022. printf("%%");
  2023. break;
  2024. case 'l':
  2025. ls++;
  2026. goto cont_process;
  2027. case 'L':
  2028. ls = 2;
  2029. goto cont_process;
  2030. case 'z':
  2031. case 'Z':
  2032. case '0' ... '9':
  2033. goto cont_process;
  2034. case 'p':
  2035. if (long_size == 4)
  2036. ls = 1;
  2037. else
  2038. ls = 2;
  2039. if (*(ptr+1) == 'F' ||
  2040. *(ptr+1) == 'f') {
  2041. ptr++;
  2042. show_func = *ptr;
  2043. }
  2044. /* fall through */
  2045. case 'd':
  2046. case 'i':
  2047. case 'x':
  2048. case 'X':
  2049. case 'u':
  2050. if (!arg)
  2051. die("no argument match");
  2052. len = ((unsigned long)ptr + 1) -
  2053. (unsigned long)saveptr;
  2054. /* should never happen */
  2055. if (len > 32)
  2056. die("bad format!");
  2057. memcpy(format, saveptr, len);
  2058. format[len] = 0;
  2059. val = eval_num_arg(data, size, event, arg);
  2060. arg = arg->next;
  2061. if (show_func) {
  2062. func = find_func(val);
  2063. if (func) {
  2064. printf("%s", func->func);
  2065. if (show_func == 'F')
  2066. printf("+0x%llx",
  2067. val - func->addr);
  2068. break;
  2069. }
  2070. }
  2071. switch (ls) {
  2072. case 0:
  2073. printf(format, (int)val);
  2074. break;
  2075. case 1:
  2076. printf(format, (long)val);
  2077. break;
  2078. case 2:
  2079. printf(format, (long long)val);
  2080. break;
  2081. default:
  2082. die("bad count (%d)", ls);
  2083. }
  2084. break;
  2085. case 's':
  2086. if (!arg)
  2087. die("no matching argument");
  2088. print_str_arg(data, size, event, arg);
  2089. arg = arg->next;
  2090. break;
  2091. default:
  2092. printf(">%c<", *ptr);
  2093. }
  2094. } else
  2095. printf("%c", *ptr);
  2096. }
  2097. if (args) {
  2098. free_args(args);
  2099. free(bprint_fmt);
  2100. }
  2101. }
  2102. static inline int log10_cpu(int nb)
  2103. {
  2104. if (nb / 100)
  2105. return 3;
  2106. if (nb / 10)
  2107. return 2;
  2108. return 1;
  2109. }
  2110. /* taken from Linux, written by Frederic Weisbecker */
  2111. static void print_graph_cpu(int cpu)
  2112. {
  2113. int i;
  2114. int log10_this = log10_cpu(cpu);
  2115. int log10_all = log10_cpu(cpus);
  2116. /*
  2117. * Start with a space character - to make it stand out
  2118. * to the right a bit when trace output is pasted into
  2119. * email:
  2120. */
  2121. printf(" ");
  2122. /*
  2123. * Tricky - we space the CPU field according to the max
  2124. * number of online CPUs. On a 2-cpu system it would take
  2125. * a maximum of 1 digit - on a 128 cpu system it would
  2126. * take up to 3 digits:
  2127. */
  2128. for (i = 0; i < log10_all - log10_this; i++)
  2129. printf(" ");
  2130. printf("%d) ", cpu);
  2131. }
  2132. #define TRACE_GRAPH_PROCINFO_LENGTH 14
  2133. #define TRACE_GRAPH_INDENT 2
  2134. static void print_graph_proc(int pid, const char *comm)
  2135. {
  2136. /* sign + log10(MAX_INT) + '\0' */
  2137. char pid_str[11];
  2138. int spaces = 0;
  2139. int len;
  2140. int i;
  2141. sprintf(pid_str, "%d", pid);
  2142. /* 1 stands for the "-" character */
  2143. len = strlen(comm) + strlen(pid_str) + 1;
  2144. if (len < TRACE_GRAPH_PROCINFO_LENGTH)
  2145. spaces = TRACE_GRAPH_PROCINFO_LENGTH - len;
  2146. /* First spaces to align center */
  2147. for (i = 0; i < spaces / 2; i++)
  2148. printf(" ");
  2149. printf("%s-%s", comm, pid_str);
  2150. /* Last spaces to align center */
  2151. for (i = 0; i < spaces - (spaces / 2); i++)
  2152. printf(" ");
  2153. }
  2154. static struct record *
  2155. get_return_for_leaf(int cpu, int cur_pid, unsigned long long cur_func,
  2156. struct record *next)
  2157. {
  2158. struct format_field *field;
  2159. struct event *event;
  2160. unsigned long val;
  2161. int type;
  2162. int pid;
  2163. type = trace_parse_common_type(next->data);
  2164. event = trace_find_event(type);
  2165. if (!event)
  2166. return NULL;
  2167. if (!(event->flags & EVENT_FL_ISFUNCRET))
  2168. return NULL;
  2169. pid = parse_common_pid(next->data);
  2170. field = find_field(event, "func");
  2171. if (!field)
  2172. die("function return does not have field func");
  2173. val = read_size(next->data + field->offset, field->size);
  2174. if (cur_pid != pid || cur_func != val)
  2175. return NULL;
  2176. /* this is a leaf, now advance the iterator */
  2177. return trace_read_data(cpu);
  2178. }
  2179. /* Signal a overhead of time execution to the output */
  2180. static void print_graph_overhead(unsigned long long duration)
  2181. {
  2182. /* Non nested entry or return */
  2183. if (duration == ~0ULL)
  2184. return (void)printf(" ");
  2185. /* Duration exceeded 100 msecs */
  2186. if (duration > 100000ULL)
  2187. return (void)printf("! ");
  2188. /* Duration exceeded 10 msecs */
  2189. if (duration > 10000ULL)
  2190. return (void)printf("+ ");
  2191. printf(" ");
  2192. }
  2193. static void print_graph_duration(unsigned long long duration)
  2194. {
  2195. unsigned long usecs = duration / 1000;
  2196. unsigned long nsecs_rem = duration % 1000;
  2197. /* log10(ULONG_MAX) + '\0' */
  2198. char msecs_str[21];
  2199. char nsecs_str[5];
  2200. int len;
  2201. int i;
  2202. sprintf(msecs_str, "%lu", usecs);
  2203. /* Print msecs */
  2204. len = printf("%lu", usecs);
  2205. /* Print nsecs (we don't want to exceed 7 numbers) */
  2206. if (len < 7) {
  2207. snprintf(nsecs_str, 8 - len, "%03lu", nsecs_rem);
  2208. len += printf(".%s", nsecs_str);
  2209. }
  2210. printf(" us ");
  2211. /* Print remaining spaces to fit the row's width */
  2212. for (i = len; i < 7; i++)
  2213. printf(" ");
  2214. printf("| ");
  2215. }
  2216. static void
  2217. print_graph_entry_leaf(struct event *event, void *data, struct record *ret_rec)
  2218. {
  2219. unsigned long long rettime, calltime;
  2220. unsigned long long duration, depth;
  2221. unsigned long long val;
  2222. struct format_field *field;
  2223. struct func_map *func;
  2224. struct event *ret_event;
  2225. int type;
  2226. int i;
  2227. type = trace_parse_common_type(ret_rec->data);
  2228. ret_event = trace_find_event(type);
  2229. field = find_field(ret_event, "rettime");
  2230. if (!field)
  2231. die("can't find rettime in return graph");
  2232. rettime = read_size(ret_rec->data + field->offset, field->size);
  2233. field = find_field(ret_event, "calltime");
  2234. if (!field)
  2235. die("can't find rettime in return graph");
  2236. calltime = read_size(ret_rec->data + field->offset, field->size);
  2237. duration = rettime - calltime;
  2238. /* Overhead */
  2239. print_graph_overhead(duration);
  2240. /* Duration */
  2241. print_graph_duration(duration);
  2242. field = find_field(event, "depth");
  2243. if (!field)
  2244. die("can't find depth in entry graph");
  2245. depth = read_size(data + field->offset, field->size);
  2246. /* Function */
  2247. for (i = 0; i < (int)(depth * TRACE_GRAPH_INDENT); i++)
  2248. printf(" ");
  2249. field = find_field(event, "func");
  2250. if (!field)
  2251. die("can't find func in entry graph");
  2252. val = read_size(data + field->offset, field->size);
  2253. func = find_func(val);
  2254. if (func)
  2255. printf("%s();", func->func);
  2256. else
  2257. printf("%llx();", val);
  2258. }
  2259. static void print_graph_nested(struct event *event, void *data)
  2260. {
  2261. struct format_field *field;
  2262. unsigned long long depth;
  2263. unsigned long long val;
  2264. struct func_map *func;
  2265. int i;
  2266. /* No overhead */
  2267. print_graph_overhead(-1);
  2268. /* No time */
  2269. printf(" | ");
  2270. field = find_field(event, "depth");
  2271. if (!field)
  2272. die("can't find depth in entry graph");
  2273. depth = read_size(data + field->offset, field->size);
  2274. /* Function */
  2275. for (i = 0; i < (int)(depth * TRACE_GRAPH_INDENT); i++)
  2276. printf(" ");
  2277. field = find_field(event, "func");
  2278. if (!field)
  2279. die("can't find func in entry graph");
  2280. val = read_size(data + field->offset, field->size);
  2281. func = find_func(val);
  2282. if (func)
  2283. printf("%s() {", func->func);
  2284. else
  2285. printf("%llx() {", val);
  2286. }
  2287. static void
  2288. pretty_print_func_ent(void *data, int size, struct event *event,
  2289. int cpu, int pid, const char *comm,
  2290. unsigned long secs, unsigned long usecs)
  2291. {
  2292. struct format_field *field;
  2293. struct record *rec;
  2294. void *copy_data;
  2295. unsigned long val;
  2296. printf("%5lu.%06lu | ", secs, usecs);
  2297. print_graph_cpu(cpu);
  2298. print_graph_proc(pid, comm);
  2299. printf(" | ");
  2300. field = find_field(event, "func");
  2301. if (!field)
  2302. die("function entry does not have func field");
  2303. val = read_size(data + field->offset, field->size);
  2304. /*
  2305. * peek_data may unmap the data pointer. Copy it first.
  2306. */
  2307. copy_data = malloc_or_die(size);
  2308. memcpy(copy_data, data, size);
  2309. data = copy_data;
  2310. rec = trace_peek_data(cpu);
  2311. if (rec) {
  2312. rec = get_return_for_leaf(cpu, pid, val, rec);
  2313. if (rec) {
  2314. print_graph_entry_leaf(event, data, rec);
  2315. goto out_free;
  2316. }
  2317. }
  2318. print_graph_nested(event, data);
  2319. out_free:
  2320. free(data);
  2321. }
  2322. static void
  2323. pretty_print_func_ret(void *data, int size __unused, struct event *event,
  2324. int cpu, int pid, const char *comm,
  2325. unsigned long secs, unsigned long usecs)
  2326. {
  2327. unsigned long long rettime, calltime;
  2328. unsigned long long duration, depth;
  2329. struct format_field *field;
  2330. int i;
  2331. printf("%5lu.%06lu | ", secs, usecs);
  2332. print_graph_cpu(cpu);
  2333. print_graph_proc(pid, comm);
  2334. printf(" | ");
  2335. field = find_field(event, "rettime");
  2336. if (!field)
  2337. die("can't find rettime in return graph");
  2338. rettime = read_size(data + field->offset, field->size);
  2339. field = find_field(event, "calltime");
  2340. if (!field)
  2341. die("can't find calltime in return graph");
  2342. calltime = read_size(data + field->offset, field->size);
  2343. duration = rettime - calltime;
  2344. /* Overhead */
  2345. print_graph_overhead(duration);
  2346. /* Duration */
  2347. print_graph_duration(duration);
  2348. field = find_field(event, "depth");
  2349. if (!field)
  2350. die("can't find depth in entry graph");
  2351. depth = read_size(data + field->offset, field->size);
  2352. /* Function */
  2353. for (i = 0; i < (int)(depth * TRACE_GRAPH_INDENT); i++)
  2354. printf(" ");
  2355. printf("}");
  2356. }
  2357. static void
  2358. pretty_print_func_graph(void *data, int size, struct event *event,
  2359. int cpu, int pid, const char *comm,
  2360. unsigned long secs, unsigned long usecs)
  2361. {
  2362. if (event->flags & EVENT_FL_ISFUNCENT)
  2363. pretty_print_func_ent(data, size, event,
  2364. cpu, pid, comm, secs, usecs);
  2365. else if (event->flags & EVENT_FL_ISFUNCRET)
  2366. pretty_print_func_ret(data, size, event,
  2367. cpu, pid, comm, secs, usecs);
  2368. printf("\n");
  2369. }
  2370. void print_event(int cpu, void *data, int size, unsigned long long nsecs,
  2371. char *comm)
  2372. {
  2373. struct event *event;
  2374. unsigned long secs;
  2375. unsigned long usecs;
  2376. int type;
  2377. int pid;
  2378. secs = nsecs / NSECS_PER_SEC;
  2379. nsecs -= secs * NSECS_PER_SEC;
  2380. usecs = nsecs / NSECS_PER_USEC;
  2381. type = trace_parse_common_type(data);
  2382. event = trace_find_event(type);
  2383. if (!event) {
  2384. warning("ug! no event found for type %d", type);
  2385. return;
  2386. }
  2387. pid = parse_common_pid(data);
  2388. if (event->flags & (EVENT_FL_ISFUNCENT | EVENT_FL_ISFUNCRET))
  2389. return pretty_print_func_graph(data, size, event, cpu,
  2390. pid, comm, secs, usecs);
  2391. printf("%16s-%-5d [%03d] %5lu.%09Lu: %s: ",
  2392. comm, pid, cpu,
  2393. secs, nsecs, event->name);
  2394. if (event->flags & EVENT_FL_FAILED) {
  2395. printf("EVENT '%s' FAILED TO PARSE\n",
  2396. event->name);
  2397. return;
  2398. }
  2399. pretty_print(data, size, event);
  2400. printf("\n");
  2401. }
  2402. static void print_fields(struct print_flag_sym *field)
  2403. {
  2404. printf("{ %s, %s }", field->value, field->str);
  2405. if (field->next) {
  2406. printf(", ");
  2407. print_fields(field->next);
  2408. }
  2409. }
  2410. static void print_args(struct print_arg *args)
  2411. {
  2412. int print_paren = 1;
  2413. switch (args->type) {
  2414. case PRINT_NULL:
  2415. printf("null");
  2416. break;
  2417. case PRINT_ATOM:
  2418. printf("%s", args->atom.atom);
  2419. break;
  2420. case PRINT_FIELD:
  2421. printf("REC->%s", args->field.name);
  2422. break;
  2423. case PRINT_FLAGS:
  2424. printf("__print_flags(");
  2425. print_args(args->flags.field);
  2426. printf(", %s, ", args->flags.delim);
  2427. print_fields(args->flags.flags);
  2428. printf(")");
  2429. break;
  2430. case PRINT_SYMBOL:
  2431. printf("__print_symbolic(");
  2432. print_args(args->symbol.field);
  2433. printf(", ");
  2434. print_fields(args->symbol.symbols);
  2435. printf(")");
  2436. break;
  2437. case PRINT_STRING:
  2438. printf("__get_str(%s)", args->string.string);
  2439. break;
  2440. case PRINT_TYPE:
  2441. printf("(%s)", args->typecast.type);
  2442. print_args(args->typecast.item);
  2443. break;
  2444. case PRINT_OP:
  2445. if (strcmp(args->op.op, ":") == 0)
  2446. print_paren = 0;
  2447. if (print_paren)
  2448. printf("(");
  2449. print_args(args->op.left);
  2450. printf(" %s ", args->op.op);
  2451. print_args(args->op.right);
  2452. if (print_paren)
  2453. printf(")");
  2454. break;
  2455. default:
  2456. /* we should warn... */
  2457. return;
  2458. }
  2459. if (args->next) {
  2460. printf("\n");
  2461. print_args(args->next);
  2462. }
  2463. }
  2464. static void parse_header_field(char *field,
  2465. int *offset, int *size)
  2466. {
  2467. char *token;
  2468. int type;
  2469. if (read_expected(EVENT_ITEM, (char *)"field") < 0)
  2470. return;
  2471. if (read_expected(EVENT_OP, (char *)":") < 0)
  2472. return;
  2473. /* type */
  2474. if (read_expect_type(EVENT_ITEM, &token) < 0)
  2475. goto fail;
  2476. free_token(token);
  2477. if (read_expected(EVENT_ITEM, field) < 0)
  2478. return;
  2479. if (read_expected(EVENT_OP, (char *)";") < 0)
  2480. return;
  2481. if (read_expected(EVENT_ITEM, (char *)"offset") < 0)
  2482. return;
  2483. if (read_expected(EVENT_OP, (char *)":") < 0)
  2484. return;
  2485. if (read_expect_type(EVENT_ITEM, &token) < 0)
  2486. goto fail;
  2487. *offset = atoi(token);
  2488. free_token(token);
  2489. if (read_expected(EVENT_OP, (char *)";") < 0)
  2490. return;
  2491. if (read_expected(EVENT_ITEM, (char *)"size") < 0)
  2492. return;
  2493. if (read_expected(EVENT_OP, (char *)":") < 0)
  2494. return;
  2495. if (read_expect_type(EVENT_ITEM, &token) < 0)
  2496. goto fail;
  2497. *size = atoi(token);
  2498. free_token(token);
  2499. if (read_expected(EVENT_OP, (char *)";") < 0)
  2500. return;
  2501. type = read_token(&token);
  2502. if (type != EVENT_NEWLINE) {
  2503. /* newer versions of the kernel have a "signed" type */
  2504. if (type != EVENT_ITEM)
  2505. goto fail;
  2506. if (strcmp(token, (char *)"signed") != 0)
  2507. goto fail;
  2508. free_token(token);
  2509. if (read_expected(EVENT_OP, (char *)":") < 0)
  2510. return;
  2511. if (read_expect_type(EVENT_ITEM, &token))
  2512. goto fail;
  2513. free_token(token);
  2514. if (read_expected(EVENT_OP, (char *)";") < 0)
  2515. return;
  2516. if (read_expect_type(EVENT_NEWLINE, &token))
  2517. goto fail;
  2518. }
  2519. fail:
  2520. free_token(token);
  2521. }
  2522. int parse_header_page(char *buf, unsigned long size)
  2523. {
  2524. init_input_buf(buf, size);
  2525. parse_header_field((char *)"timestamp", &header_page_ts_offset,
  2526. &header_page_ts_size);
  2527. parse_header_field((char *)"commit", &header_page_size_offset,
  2528. &header_page_size_size);
  2529. parse_header_field((char *)"data", &header_page_data_offset,
  2530. &header_page_data_size);
  2531. return 0;
  2532. }
  2533. int parse_ftrace_file(char *buf, unsigned long size)
  2534. {
  2535. struct format_field *field;
  2536. struct print_arg *arg, **list;
  2537. struct event *event;
  2538. int ret;
  2539. init_input_buf(buf, size);
  2540. event = alloc_event();
  2541. if (!event)
  2542. return -ENOMEM;
  2543. event->flags |= EVENT_FL_ISFTRACE;
  2544. event->name = event_read_name();
  2545. if (!event->name)
  2546. die("failed to read ftrace event name");
  2547. if (strcmp(event->name, "function") == 0)
  2548. event->flags |= EVENT_FL_ISFUNC;
  2549. else if (strcmp(event->name, "funcgraph_entry") == 0)
  2550. event->flags |= EVENT_FL_ISFUNCENT;
  2551. else if (strcmp(event->name, "funcgraph_exit") == 0)
  2552. event->flags |= EVENT_FL_ISFUNCRET;
  2553. else if (strcmp(event->name, "bprint") == 0)
  2554. event->flags |= EVENT_FL_ISBPRINT;
  2555. event->id = event_read_id();
  2556. if (event->id < 0)
  2557. die("failed to read ftrace event id");
  2558. add_event(event);
  2559. ret = event_read_format(event);
  2560. if (ret < 0)
  2561. die("failed to read ftrace event format");
  2562. ret = event_read_print(event);
  2563. if (ret < 0)
  2564. die("failed to read ftrace event print fmt");
  2565. /*
  2566. * The arguments for ftrace files are parsed by the fields.
  2567. * Set up the fields as their arguments.
  2568. */
  2569. list = &event->print_fmt.args;
  2570. for (field = event->format.fields; field; field = field->next) {
  2571. arg = malloc_or_die(sizeof(*arg));
  2572. memset(arg, 0, sizeof(*arg));
  2573. *list = arg;
  2574. list = &arg->next;
  2575. arg->type = PRINT_FIELD;
  2576. arg->field.name = field->name;
  2577. arg->field.field = field;
  2578. }
  2579. return 0;
  2580. }
  2581. int parse_event_file(char *buf, unsigned long size, char *sys)
  2582. {
  2583. struct event *event;
  2584. int ret;
  2585. init_input_buf(buf, size);
  2586. event = alloc_event();
  2587. if (!event)
  2588. return -ENOMEM;
  2589. event->name = event_read_name();
  2590. if (!event->name)
  2591. die("failed to read event name");
  2592. event->id = event_read_id();
  2593. if (event->id < 0)
  2594. die("failed to read event id");
  2595. ret = event_read_format(event);
  2596. if (ret < 0) {
  2597. warning("failed to read event format for %s", event->name);
  2598. goto event_failed;
  2599. }
  2600. ret = event_read_print(event);
  2601. if (ret < 0) {
  2602. warning("failed to read event print fmt for %s", event->name);
  2603. goto event_failed;
  2604. }
  2605. event->system = strdup(sys);
  2606. #define PRINT_ARGS 0
  2607. if (PRINT_ARGS && event->print_fmt.args)
  2608. print_args(event->print_fmt.args);
  2609. add_event(event);
  2610. return 0;
  2611. event_failed:
  2612. event->flags |= EVENT_FL_FAILED;
  2613. /* still add it even if it failed */
  2614. add_event(event);
  2615. return -1;
  2616. }
  2617. void parse_set_info(int nr_cpus, int long_sz)
  2618. {
  2619. cpus = nr_cpus;
  2620. long_size = long_sz;
  2621. }