corosync-fplay.c 12 KB

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