corosync-fplay.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487
  1. #include <config.h>
  2. #include <sys/types.h>
  3. #include <sys/stat.h>
  4. #include <fcntl.h>
  5. #include <stdio.h>
  6. #include <unistd.h>
  7. #include <string.h>
  8. #include <stdlib.h>
  9. #include <assert.h>
  10. #include <stdint.h>
  11. #include <sys/socket.h>
  12. #include <netinet/in.h>
  13. #include <sys/types.h>
  14. #include <sys/socket.h>
  15. #include <arpa/inet.h>
  16. #include <corosync/engine/logsys.h>
  17. unsigned int flt_data_size = 1000000;
  18. unsigned int *flt_data;
  19. #define FDHEAD_INDEX (flt_data_size)
  20. #define FDTAIL_INDEX (flt_data_size + 1)
  21. #define TOTEMIP_ADDRLEN (sizeof(struct in6_addr))
  22. struct totem_ip_address {
  23. unsigned int nodeid;
  24. unsigned short family;
  25. unsigned char addr[TOTEMIP_ADDRLEN];
  26. } __attribute__((packed));
  27. struct memb_ring_id {
  28. struct totem_ip_address rep;
  29. unsigned long long seq;
  30. } __attribute__((packed));
  31. const char *totemip_print(struct totem_ip_address *addr)
  32. {
  33. static char buf[INET6_ADDRSTRLEN];
  34. return inet_ntop(addr->family, addr->addr, buf, sizeof(buf));
  35. }
  36. char *print_string_len (unsigned char *str, unsigned int len)
  37. {
  38. unsigned int i;
  39. static char buf[1024];
  40. memset (buf, 0, sizeof (buf));
  41. for (i = 0; i < len; i++) {
  42. buf[i] = str[i];
  43. }
  44. return (buf);
  45. }
  46. void sync_printer_confchg_set_sync (void **record)
  47. {
  48. unsigned int *my_should_sync = record[0];
  49. printf ("Setting my_should_sync to %d\n", *my_should_sync);
  50. }
  51. void sync_printer_set_sync_state (void **record)
  52. {
  53. unsigned int *my_sync_state = record[0];
  54. printf ("Setting my_sync_state to %d\n", *my_sync_state);
  55. }
  56. void sync_printer_process_currentstate (void **record)
  57. {
  58. unsigned int *my_sync_state = record[0];
  59. printf ("Retrieving my_sync_state %d\n", *my_sync_state);
  60. }
  61. void sync_printer_process_get_shouldsync (void **record)
  62. {
  63. unsigned int *my_should_sync = record[0];
  64. printf ("Getting my_should_sync %d\n", *my_should_sync);
  65. }
  66. void sync_printer_checkpoint_release (void **record)
  67. {
  68. unsigned char *name = record[0];
  69. uint16_t *name_len = record[1];
  70. unsigned int *ckpt_id = record[2];
  71. unsigned int *from = record[3];
  72. printf ("Checkpoint release name=[%s] id=[%d] from=[%d] len=[%d]\n",
  73. print_string_len (name, *name_len),
  74. *ckpt_id,
  75. *from,
  76. *name_len);
  77. }
  78. void sync_printer_checkpoint_transmit (void **record)
  79. {
  80. unsigned char *name = record[0];
  81. uint16_t *name_len = record[1];
  82. unsigned int *ckpt_id = record[2];
  83. unsigned int *xmit_id = record[3];
  84. printf ("xmit_id=[%d] Checkpoint transmit name=[%s] id=[%d]\n",
  85. *xmit_id, print_string_len (name, *name_len),
  86. *ckpt_id);
  87. }
  88. void sync_printer_section_transmit (void **record)
  89. {
  90. unsigned char *ckpt_name = record[0];
  91. uint16_t *name_len = record[1];
  92. unsigned int *ckpt_id = record[2];
  93. unsigned int *xmit_id = record[3];
  94. unsigned char *section_name = record[4];
  95. uint16_t *section_name_len = record[5];
  96. printf ("xmit_id=[%d] Section transmit checkpoint name=[%s] id=[%d] ",
  97. *xmit_id, print_string_len (ckpt_name, *name_len),
  98. *ckpt_id);
  99. printf ("section=[%s]\n",
  100. print_string_len (section_name, *section_name_len));
  101. }
  102. void sync_printer_checkpoint_receive (void **record)
  103. {
  104. unsigned char *ckpt_name = record[0];
  105. uint16_t *name_len = record[1];
  106. unsigned int *ckpt_id = record[2];
  107. unsigned int *xmit_id = record[3];
  108. printf ("xmit_id=[%d] Checkpoint receive checkpoint name=[%s] id=[%d]\n",
  109. *xmit_id, print_string_len (ckpt_name, *name_len), *ckpt_id);
  110. }
  111. void sync_printer_section_receive (void **record)
  112. {
  113. unsigned char *ckpt_name = record[0];
  114. uint16_t *name_len = record[1];
  115. unsigned int *ckpt_id = record[2];
  116. unsigned int *xmit_id = record[3];
  117. unsigned char *section_name = record[4];
  118. unsigned int *section_name_len = record[5];
  119. printf ("xmit_id=[%d] Section receive checkpoint name=[%s] id=[%d] ",
  120. *xmit_id, print_string_len (ckpt_name, *name_len),
  121. *ckpt_id);
  122. printf ("section=[%s]\n",
  123. print_string_len (section_name, *section_name_len));
  124. }
  125. void sync_printer_nada (void **record)
  126. {
  127. printf ("nada\n");
  128. }
  129. void sync_printer_confchg_fn (void **record)
  130. {
  131. unsigned int i;
  132. unsigned int *members = record[0];
  133. unsigned int *member_count = record[1];
  134. struct memb_ring_id *ring_id = record[2];
  135. struct in_addr addr;
  136. printf ("sync confchg fn ringid [ip=%s seq=%lld]\n",
  137. totemip_print (&ring_id->rep),
  138. ring_id->seq);
  139. printf ("members [%d]:\n", *member_count);
  140. for (i = 0; i < *member_count; i++) {
  141. addr.s_addr = members[i];
  142. printf ("\tmember [%s]\n", inet_ntoa (addr));
  143. }
  144. }
  145. void printer_totemsrp_mcast (void **record)
  146. {
  147. unsigned int *msgid = record[0];
  148. printf ("totemsrp_mcast %d\n", *msgid);
  149. }
  150. void printer_totemsrp_delv (void **record)
  151. {
  152. unsigned int *msgid = record[0];
  153. printf ("totemsrp_delv %d\n", *msgid);
  154. }
  155. void printer_totempg_mcast_fits (void **record)
  156. {
  157. unsigned int *index = record[0];
  158. unsigned int *iov_len = record[1];
  159. unsigned int *copy_len = record[2];
  160. unsigned int *fragment_size = record[3];
  161. unsigned int *max_packet_size = record[4];
  162. unsigned int *copy_base = record[5];
  163. unsigned char *next_fragment = record[6];
  164. printf ("totempg_mcast index=[%d] iov_len=[%d] copy_len=[%d] fragment_size=[%d] max_packet_size=[%d] copy_base=[%d] next_fragment[%d]\n",
  165. *index, *iov_len, *copy_len, *fragment_size, *max_packet_size, *copy_base, *next_fragment);
  166. }
  167. void sync_printer_service_process (void **record)
  168. {
  169. struct memb_ring_id *ring_id = record[0];
  170. struct memb_ring_id *sync_ring_id = record[1];
  171. printf ("sync service process callback ringid [ip=%s seq=%lld] ",
  172. totemip_print (&ring_id->rep),
  173. ring_id->seq);
  174. printf ("sync ringid [ip=%s seq=%lld]\n",
  175. totemip_print (&sync_ring_id->rep),
  176. sync_ring_id->seq);
  177. }
  178. struct printer_subsys_record_print {
  179. int ident;
  180. void (*print_fn)(void **record);
  181. int record_length;
  182. };
  183. struct printer_subsys {
  184. char *subsys;
  185. struct printer_subsys_record_print *record_printers;
  186. int record_printers_count;
  187. };
  188. #define LOGREC_ID_SYNC_CONFCHG_FN 0
  189. #define LOGREC_ID_SYNC_SERVICE_PROCESS 1
  190. /*
  191. * CKPT subsystem
  192. */
  193. #define LOGREC_ID_CONFCHG_SETSYNC 0
  194. #define LOGREC_ID_SETSYNCSTATE 1
  195. #define LOGREC_ID_SYNC_PROCESS_CURRENTSTATE 2
  196. #define LOGREC_ID_SYNC_PROCESS_GETSHOULDSYNC 3
  197. #define LOGREC_ID_SYNC_CHECKPOINT_TRANSMIT 4
  198. #define LOGREC_ID_SYNC_SECTION_TRANSMIT 5
  199. #define LOGREC_ID_SYNC_CHECKPOINT_RECEIVE 6
  200. #define LOGREC_ID_SYNC_SECTION_RECEIVE 7
  201. #define LOGREC_ID_SYNC_CHECKPOINT_RELEASE 8
  202. #define LOGREC_ID_TOTEMSRP_MCAST 0
  203. #define LOGREC_ID_TOTEMSRP_DELV 1
  204. #define LOGREC_ID_TOTEMPG_MCAST_FITS 2
  205. struct printer_subsys_record_print record_print_sync[] = {
  206. {
  207. .ident = LOGREC_ID_SYNC_CONFCHG_FN,
  208. .print_fn = sync_printer_confchg_fn,
  209. .record_length = 28
  210. },
  211. {
  212. .ident = LOGREC_ID_SYNC_SERVICE_PROCESS,
  213. .print_fn = sync_printer_service_process,
  214. .record_length = 28
  215. }
  216. };
  217. struct printer_subsys_record_print record_print_ckpt[] = {
  218. {
  219. .ident = LOGREC_ID_CONFCHG_SETSYNC,
  220. .print_fn = sync_printer_confchg_set_sync,
  221. .record_length = 28
  222. },
  223. {
  224. .ident = LOGREC_ID_SETSYNCSTATE,
  225. .print_fn = sync_printer_set_sync_state,
  226. .record_length = 28
  227. },
  228. {
  229. .ident = LOGREC_ID_SYNC_PROCESS_CURRENTSTATE,
  230. .print_fn = sync_printer_process_currentstate,
  231. .record_length = 28
  232. },
  233. {
  234. .ident = LOGREC_ID_SYNC_PROCESS_GETSHOULDSYNC,
  235. .print_fn = sync_printer_process_get_shouldsync,
  236. .record_length = 28
  237. },
  238. {
  239. .ident = LOGREC_ID_SYNC_CHECKPOINT_TRANSMIT,
  240. .print_fn = sync_printer_checkpoint_transmit,
  241. .record_length = 28
  242. },
  243. {
  244. .ident = LOGREC_ID_SYNC_SECTION_TRANSMIT,
  245. .print_fn = sync_printer_section_transmit,
  246. .record_length = 28
  247. },
  248. {
  249. .ident = LOGREC_ID_SYNC_CHECKPOINT_RECEIVE,
  250. .print_fn = sync_printer_checkpoint_receive,
  251. .record_length = 28
  252. },
  253. {
  254. .ident = LOGREC_ID_SYNC_SECTION_RECEIVE,
  255. .print_fn = sync_printer_section_receive,
  256. .record_length = 28
  257. },
  258. {
  259. .ident = LOGREC_ID_SYNC_CHECKPOINT_RELEASE,
  260. .print_fn = sync_printer_checkpoint_release,
  261. .record_length = 28
  262. }
  263. };
  264. struct printer_subsys_record_print record_print_totem[] = {
  265. {
  266. .ident = LOGREC_ID_TOTEMSRP_MCAST,
  267. .print_fn = printer_totemsrp_mcast,
  268. .record_length = 28
  269. },
  270. {
  271. .ident = LOGREC_ID_TOTEMSRP_DELV,
  272. .print_fn = printer_totemsrp_delv,
  273. .record_length = 28
  274. },
  275. {
  276. .ident = LOGREC_ID_TOTEMPG_MCAST_FITS,
  277. .print_fn = printer_totempg_mcast_fits,
  278. .record_length = 28
  279. }
  280. };
  281. struct printer_subsys printer_subsystems[] = {
  282. {
  283. .subsys = "SYNC",
  284. .record_printers = record_print_sync,
  285. .record_printers_count = sizeof (record_print_sync) / sizeof (struct printer_subsys_record_print)
  286. },
  287. {
  288. .subsys = "CKPT",
  289. .record_printers = record_print_ckpt,
  290. .record_printers_count = sizeof (record_print_ckpt) / sizeof (struct printer_subsys_record_print)
  291. },
  292. {
  293. .subsys = "TOTEM",
  294. .record_printers = record_print_totem,
  295. .record_printers_count = sizeof (record_print_totem) / sizeof (struct printer_subsys_record_print)
  296. }
  297. };
  298. unsigned int printer_subsys_count = sizeof (printer_subsystems) / sizeof (struct printer_subsys);
  299. unsigned int records_printed = 1;
  300. unsigned int record[10000];
  301. /*
  302. * Copy record, dealing with wrapping
  303. */
  304. int logsys_rec_get (int rec_idx) {
  305. unsigned int rec_size;
  306. int firstcopy, secondcopy;
  307. rec_size = flt_data[rec_idx];
  308. firstcopy = rec_size;
  309. secondcopy = 0;
  310. if (firstcopy + rec_idx > flt_data_size) {
  311. firstcopy = flt_data_size - rec_idx;
  312. secondcopy -= firstcopy - rec_size;
  313. }
  314. memcpy (&record[0], &flt_data[rec_idx], firstcopy<<2);
  315. if (secondcopy) {
  316. memcpy (&record[firstcopy], &flt_data[0], secondcopy<<2);
  317. }
  318. return ((rec_idx + rec_size) % flt_data_size);
  319. }
  320. void logsys_rec_print (void *record)
  321. {
  322. unsigned int *buf_uint32t = (unsigned int *)record;
  323. unsigned int rec_size;
  324. unsigned int rec_ident;
  325. unsigned int line;
  326. unsigned int arg_size_idx;
  327. unsigned int i;
  328. unsigned int j;
  329. unsigned int rec_idx = 0;
  330. unsigned int record_number;
  331. unsigned int words_processed;
  332. unsigned int found;
  333. void *arguments[64];
  334. int arg_count = 0;
  335. rec_size = buf_uint32t[rec_idx];
  336. rec_ident = buf_uint32t[rec_idx+1];
  337. line = buf_uint32t[rec_idx+2];
  338. record_number = buf_uint32t[rec_idx+3];
  339. printf ("rec=[%d] ", record_number);
  340. arg_size_idx = rec_idx + 4;
  341. words_processed = 4;
  342. for (i = 0; words_processed < rec_size; i++) {
  343. arguments[arg_count++] = &buf_uint32t[arg_size_idx + 1];
  344. words_processed += buf_uint32t[arg_size_idx] + 1;
  345. arg_size_idx += buf_uint32t[arg_size_idx] + 1;
  346. }
  347. found = 0;
  348. for (i = 0; i < printer_subsys_count; i++) {
  349. if (strcmp ((char *)arguments[0], printer_subsystems[i].subsys) == 0) {
  350. for (j = 0; j < printer_subsystems[i].record_printers_count; j++) {
  351. if (rec_ident == printer_subsystems[i].record_printers[j].ident) {
  352. printer_subsystems[i].record_printers[j].print_fn (&arguments[3]);
  353. found = 1;
  354. }
  355. }
  356. }
  357. }
  358. if (rec_ident & LOGSYS_TAG_LOG) {
  359. printf ("Log Message=%s\n", (char *)arguments[3]);
  360. found = 1;
  361. }
  362. if (rec_ident & LOGSYS_TAG_ENTER) {
  363. printf ("ENTERING function [%s] line [%d]\n", (char *)arguments[2], line);
  364. found = 1;
  365. }
  366. if (rec_ident & LOGSYS_TAG_LEAVE) {
  367. printf ("LEAVING function [%s] line [%d]\n", (char *)arguments[2], line);
  368. found = 1;
  369. }
  370. if (found == 0) {
  371. printf ("Unknown record type found subsys=[%s] ident=[%d]\n",
  372. (char *)arguments[0], rec_ident);
  373. }
  374. if (rec_ident == 999) {
  375. printf ("ENTERING function [%s] line [%d]\n", (char *)arguments[2], line);
  376. found = 1;
  377. }
  378. if (rec_ident == 1000) {
  379. printf ("LEAVING function [%s] line [%d]\n", (char *)arguments[2], line);
  380. found = 1;
  381. }
  382. if (found == 0) {
  383. printf ("Unknown record type found subsys=[%s] ident=[%d]\n",
  384. (char *)arguments[0], rec_ident);
  385. }
  386. #ifdef COMPILE_OUT
  387. printf ("\n");
  388. #endif
  389. }
  390. int main (void)
  391. {
  392. unsigned int fd;
  393. int rec_idx;
  394. int end_rec;
  395. int record_count = 1;
  396. int size_read;
  397. flt_data = malloc ((flt_data_size + 2) * sizeof (unsigned int));
  398. fd = open (LOCALSTATEDIR "/lib/corosync/fdata", O_RDONLY);
  399. size_read = (int)read (fd, flt_data, (flt_data_size + 2) * sizeof (unsigned int));
  400. if (size_read != (flt_data_size + 2) * sizeof (unsigned int)) {
  401. printf ("Warning: read %d bytes, but expected %d\n",
  402. size_read, (flt_data_size + 2) * sizeof (unsigned int));
  403. }
  404. rec_idx = flt_data[FDTAIL_INDEX];
  405. end_rec = flt_data[FDHEAD_INDEX];
  406. printf ("Starting replay: head [%d] tail [%d]\n",
  407. flt_data[FDHEAD_INDEX],
  408. flt_data[FDTAIL_INDEX]);
  409. for (;;) {
  410. rec_idx = logsys_rec_get (rec_idx);
  411. logsys_rec_print (record);
  412. if (rec_idx == end_rec) {
  413. break;
  414. }
  415. record_count += 1;
  416. }
  417. printf ("Finishing replay: records found [%d]\n", record_count);
  418. return (0);
  419. }