pf2 0.5.2 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +20 -0
  3. data/Cargo.lock +7 -27
  4. data/README.md +1 -1
  5. data/crates/backtrace-sys2/build.rs +1 -4
  6. data/crates/backtrace-sys2/src/libbacktrace/Makefile.am +116 -31
  7. data/crates/backtrace-sys2/src/libbacktrace/Makefile.in +295 -141
  8. data/crates/backtrace-sys2/src/libbacktrace/README.md +11 -1
  9. data/crates/backtrace-sys2/src/libbacktrace/alloc.c +1 -1
  10. data/crates/backtrace-sys2/src/libbacktrace/allocfail.c +1 -1
  11. data/crates/backtrace-sys2/src/libbacktrace/allocfail.sh +1 -1
  12. data/crates/backtrace-sys2/src/libbacktrace/atomic.c +1 -1
  13. data/crates/backtrace-sys2/src/libbacktrace/backtrace-supported.h.in +1 -1
  14. data/crates/backtrace-sys2/src/libbacktrace/backtrace.c +1 -1
  15. data/crates/backtrace-sys2/src/libbacktrace/backtrace.h +12 -12
  16. data/crates/backtrace-sys2/src/libbacktrace/btest.c +24 -8
  17. data/crates/backtrace-sys2/src/libbacktrace/config/libtool.m4 +162 -53
  18. data/crates/backtrace-sys2/src/libbacktrace/config.h.in +3 -0
  19. data/crates/backtrace-sys2/src/libbacktrace/configure +255 -66
  20. data/crates/backtrace-sys2/src/libbacktrace/configure.ac +27 -8
  21. data/crates/backtrace-sys2/src/libbacktrace/dwarf.c +37 -30
  22. data/crates/backtrace-sys2/src/libbacktrace/edtest.c +2 -2
  23. data/crates/backtrace-sys2/src/libbacktrace/edtest2.c +1 -1
  24. data/crates/backtrace-sys2/src/libbacktrace/elf.c +98 -76
  25. data/crates/backtrace-sys2/src/libbacktrace/fileline.c +1 -1
  26. data/crates/backtrace-sys2/src/libbacktrace/install-debuginfo-for-buildid.sh.in +2 -2
  27. data/crates/backtrace-sys2/src/libbacktrace/instrumented_alloc.c +1 -1
  28. data/crates/backtrace-sys2/src/libbacktrace/internal.h +41 -2
  29. data/crates/backtrace-sys2/src/libbacktrace/macho.c +25 -19
  30. data/crates/backtrace-sys2/src/libbacktrace/mmap.c +1 -1
  31. data/crates/backtrace-sys2/src/libbacktrace/mmapio.c +1 -1
  32. data/crates/backtrace-sys2/src/libbacktrace/mtest.c +4 -4
  33. data/crates/backtrace-sys2/src/libbacktrace/nounwind.c +1 -1
  34. data/crates/backtrace-sys2/src/libbacktrace/pecoff.c +192 -26
  35. data/crates/backtrace-sys2/src/libbacktrace/posix.c +1 -1
  36. data/crates/backtrace-sys2/src/libbacktrace/print.c +41 -16
  37. data/crates/backtrace-sys2/src/libbacktrace/read.c +1 -1
  38. data/crates/backtrace-sys2/src/libbacktrace/simple.c +1 -1
  39. data/crates/backtrace-sys2/src/libbacktrace/sort.c +1 -1
  40. data/crates/backtrace-sys2/src/libbacktrace/state.c +1 -1
  41. data/crates/backtrace-sys2/src/libbacktrace/stest.c +1 -1
  42. data/crates/backtrace-sys2/src/libbacktrace/test_format.c +1 -1
  43. data/crates/backtrace-sys2/src/libbacktrace/testlib.c +1 -1
  44. data/crates/backtrace-sys2/src/libbacktrace/testlib.h +1 -1
  45. data/crates/backtrace-sys2/src/libbacktrace/ttest.c +1 -1
  46. data/crates/backtrace-sys2/src/libbacktrace/unittest.c +1 -1
  47. data/crates/backtrace-sys2/src/libbacktrace/unknown.c +1 -1
  48. data/crates/backtrace-sys2/src/libbacktrace/xcoff.c +43 -32
  49. data/crates/backtrace-sys2/src/libbacktrace/xztest.c +2 -2
  50. data/crates/backtrace-sys2/src/libbacktrace/zstdtest.c +1 -1
  51. data/crates/backtrace-sys2/src/libbacktrace/ztest.c +1 -1
  52. data/ext/pf2/Cargo.toml +1 -1
  53. data/ext/pf2/src/lib.rs +1 -0
  54. data/ext/pf2/src/profile.rs +7 -3
  55. data/ext/pf2/src/profile_serializer.rs +6 -13
  56. data/ext/pf2/src/ringbuffer.rs +1 -3
  57. data/ext/pf2/src/ruby_init.rs +1 -4
  58. data/ext/pf2/src/sample.rs +1 -0
  59. data/ext/pf2/src/serialization/profile.rs +47 -0
  60. data/ext/pf2/src/serialization/serializer.rs +325 -0
  61. data/ext/pf2/src/serialization.rs +2 -0
  62. data/ext/pf2/src/session/configuration.rs +2 -1
  63. data/ext/pf2/src/session/new_thread_watcher.rs +1 -1
  64. data/ext/pf2/src/session/ruby_object.rs +1 -5
  65. data/ext/pf2/src/session.rs +20 -19
  66. data/ext/pf2/src/signal_scheduler.rs +12 -7
  67. data/ext/pf2/src/timer_thread_scheduler.rs +11 -3
  68. data/lib/pf2/cli.rb +3 -1
  69. data/lib/pf2/reporter/firefox_profiler.rb +397 -0
  70. data/lib/pf2/reporter/stack_weaver.rb +81 -0
  71. data/lib/pf2/reporter.rb +3 -392
  72. data/lib/pf2/serve.rb +3 -1
  73. data/lib/pf2/session.rb +2 -0
  74. data/lib/pf2/version.rb +3 -1
  75. data/lib/pf2.rb +4 -1
  76. data/rustfmt.toml +1 -0
  77. metadata +13 -12
  78. data/crates/backtrace-sys2/src/libbacktrace/libtool.m4 +0 -7436
  79. data/crates/backtrace-sys2/src/libbacktrace/ltoptions.m4 +0 -369
  80. data/crates/backtrace-sys2/src/libbacktrace/ltsugar.m4 +0 -123
  81. data/crates/backtrace-sys2/src/libbacktrace/ltversion.m4 +0 -23
  82. data/crates/backtrace-sys2/src/libbacktrace/lt~obsolete.m4 +0 -98
@@ -1,5 +1,5 @@
1
1
  /* sort.c -- Sort without allocating memory
2
- Copyright (C) 2012-2021 Free Software Foundation, Inc.
2
+ Copyright (C) 2012-2024 Free Software Foundation, Inc.
3
3
  Written by Ian Lance Taylor, Google.
4
4
 
5
5
  Redistribution and use in source and binary forms, with or without
@@ -1,5 +1,5 @@
1
1
  /* state.c -- Create the backtrace state.
2
- Copyright (C) 2012-2021 Free Software Foundation, Inc.
2
+ Copyright (C) 2012-2024 Free Software Foundation, Inc.
3
3
  Written by Ian Lance Taylor, Google.
4
4
 
5
5
  Redistribution and use in source and binary forms, with or without
@@ -1,5 +1,5 @@
1
1
  /* stest.c -- Test for libbacktrace internal sort function
2
- Copyright (C) 2012-2021 Free Software Foundation, Inc.
2
+ Copyright (C) 2012-2024 Free Software Foundation, Inc.
3
3
  Written by Ian Lance Taylor, Google.
4
4
 
5
5
  Redistribution and use in source and binary forms, with or without
@@ -1,5 +1,5 @@
1
1
  /* test_format.c -- Test for libbacktrace library
2
- Copyright (C) 2018-2021 Free Software Foundation, Inc.
2
+ Copyright (C) 2018-2024 Free Software Foundation, Inc.
3
3
 
4
4
  Redistribution and use in source and binary forms, with or without
5
5
  modification, are permitted provided that the following conditions are
@@ -1,5 +1,5 @@
1
1
  /* testlib.c -- test functions for libbacktrace library
2
- Copyright (C) 2012-2021 Free Software Foundation, Inc.
2
+ Copyright (C) 2012-2024 Free Software Foundation, Inc.
3
3
  Written by Ian Lance Taylor, Google.
4
4
 
5
5
  Redistribution and use in source and binary forms, with or without
@@ -1,5 +1,5 @@
1
1
  /* testlib.h -- Header for test functions for libbacktrace library
2
- Copyright (C) 2012-2021 Free Software Foundation, Inc.
2
+ Copyright (C) 2012-2024 Free Software Foundation, Inc.
3
3
  Written by Ian Lance Taylor, Google.
4
4
 
5
5
  Redistribution and use in source and binary forms, with or without
@@ -1,5 +1,5 @@
1
1
  /* ttest.c -- Test for libbacktrace library
2
- Copyright (C) 2017-2021 Free Software Foundation, Inc.
2
+ Copyright (C) 2017-2024 Free Software Foundation, Inc.
3
3
  Written by Ian Lance Taylor, Google.
4
4
 
5
5
  Redistribution and use in source and binary forms, with or without
@@ -1,5 +1,5 @@
1
1
  /* unittest.c -- Test for libbacktrace library
2
- Copyright (C) 2018-2021 Free Software Foundation, Inc.
2
+ Copyright (C) 2018-2024 Free Software Foundation, Inc.
3
3
 
4
4
  Redistribution and use in source and binary forms, with or without
5
5
  modification, are permitted provided that the following conditions are
@@ -1,5 +1,5 @@
1
1
  /* unknown.c -- used when backtrace configury does not know file format.
2
- Copyright (C) 2012-2021 Free Software Foundation, Inc.
2
+ Copyright (C) 2012-2024 Free Software Foundation, Inc.
3
3
  Written by Ian Lance Taylor, Google.
4
4
 
5
5
  Redistribution and use in source and binary forms, with or without
@@ -1,5 +1,5 @@
1
1
  /* xcoff.c -- Get debug data from an XCOFF file for backtraces.
2
- Copyright (C) 2012-2021 Free Software Foundation, Inc.
2
+ Copyright (C) 2012-2024 Free Software Foundation, Inc.
3
3
  Adapted from elf.c.
4
4
 
5
5
  Redistribution and use in source and binary forms, with or without
@@ -133,6 +133,7 @@ typedef struct {
133
133
  #define SSUBTYP_DWARNGE 0x50000 /* DWARF aranges section. */
134
134
  #define SSUBTYP_DWABREV 0x60000 /* DWARF abbreviation section. */
135
135
  #define SSUBTYP_DWSTR 0x70000 /* DWARF strings section. */
136
+ #define SSUBTYP_DWRNGES 0x80000 /* DWARF ranges section. */
136
137
 
137
138
  /* XCOFF symbol. */
138
139
 
@@ -384,7 +385,7 @@ struct xcoff_fileline_data
384
385
  size_t linenos_size;
385
386
  uint64_t lnnoptr0;
386
387
  /* Loader address. */
387
- uintptr_t base_address;
388
+ struct libbacktrace_base_address base_address;
388
389
  };
389
390
 
390
391
  /* Information we gather for the DWARF sections we care about. */
@@ -585,8 +586,7 @@ xcoff_symname (const b_xcoff_syment *asym,
585
586
 
586
587
  static int
587
588
  xcoff_initialize_syminfo (struct backtrace_state *state,
588
- uintptr_t base_address,
589
- const b_xcoff_scnhdr *sects,
589
+ struct libbacktrace_base_address base_address,
590
590
  const b_xcoff_syment *syms, size_t nsyms,
591
591
  const unsigned char *strtab, size_t strtab_size,
592
592
  backtrace_error_callback error_callback, void *data,
@@ -628,8 +628,8 @@ xcoff_initialize_syminfo (struct backtrace_state *state,
628
628
  {
629
629
  const b_xcoff_auxent *aux = (const b_xcoff_auxent *) (asym + 1);
630
630
  xcoff_symbols[j].name = xcoff_symname (asym, strtab, strtab_size);
631
- xcoff_symbols[j].address = base_address + asym->n_value
632
- - sects[asym->n_scnum - 1].s_paddr;
631
+ xcoff_symbols[j].address =
632
+ libbacktrace_add_base (asym->n_value, base_address);
633
633
  /* x_fsize will be 0 if there is no debug information. */
634
634
  xcoff_symbols[j].size = aux->x_fcn.x_fsize;
635
635
  ++j;
@@ -767,7 +767,8 @@ xcoff_lookup_pc (struct backtrace_state *state ATTRIBUTE_UNUSED,
767
767
  lineno = (const b_xcoff_lineno *) lineptr;
768
768
  if (lineno->l_lnno == 0)
769
769
  break;
770
- if (pc <= fdata->base_address + lineno->l_addr.l_paddr - fn->sect_base)
770
+ if (pc <= libbacktrace_add_base (lineno->l_addr.l_paddr,
771
+ fdata->base_address))
771
772
  break;
772
773
  match = lnnoptr;
773
774
  lnno = lineno->l_lnno;
@@ -861,7 +862,7 @@ xcoff_fileline (struct backtrace_state *state, uintptr_t pc,
861
862
 
862
863
  static int
863
864
  xcoff_initialize_fileline (struct backtrace_state *state,
864
- uintptr_t base_address,
865
+ struct libbacktrace_base_address base_address,
865
866
  const b_xcoff_scnhdr *sects,
866
867
  const b_xcoff_syment *syms, size_t nsyms,
867
868
  const unsigned char *strtab, size_t strtab_size,
@@ -1002,7 +1003,7 @@ xcoff_initialize_fileline (struct backtrace_state *state,
1002
1003
  fn->name = xcoff_symname (fsym, strtab, strtab_size);
1003
1004
  fn->filename = filename;
1004
1005
  fn->sect_base = sects[fsym->n_scnum - 1].s_paddr;
1005
- fn->pc = base_address + fsym->n_value - fn->sect_base;
1006
+ fn->pc = libbacktrace_add_base (fsym->n_value, base_address);
1006
1007
  fn->size = fsize;
1007
1008
  fn->lnno = lnno;
1008
1009
  fn->lnnoptr = lnnoptr;
@@ -1071,7 +1072,8 @@ fail:
1071
1072
 
1072
1073
  static int
1073
1074
  xcoff_add (struct backtrace_state *state, int descriptor, off_t offset,
1074
- uintptr_t base_address, backtrace_error_callback error_callback,
1075
+ struct libbacktrace_base_address base_address,
1076
+ backtrace_error_callback error_callback,
1075
1077
  void *data, fileline *fileline_fn, int *found_sym, int exe)
1076
1078
  {
1077
1079
  struct backtrace_view fhdr_view;
@@ -1153,8 +1155,16 @@ xcoff_add (struct backtrace_state *state, int descriptor, off_t offset,
1153
1155
 
1154
1156
  stext = &sects[i];
1155
1157
 
1156
- /* AIX ldinfo_textorg includes the XCOFF headers. */
1157
- base_address = (exe ? XCOFF_AIX_TEXTBASE : base_address) + stext->s_scnptr;
1158
+ /* base_address represents the difference between the
1159
+ virtual memory address of the shared object or a loaded
1160
+ executable and the offset of that object in the file
1161
+ from which it was loaded.
1162
+ On AIX, virtual address is either fixed for executable
1163
+ or given by ldinfo. This address will include the XCOFF
1164
+ headers. */
1165
+ base_address.m = ((exe ? XCOFF_AIX_TEXTBASE : base_address.m)
1166
+ + stext->s_scnptr
1167
+ - stext->s_paddr);
1158
1168
 
1159
1169
  lnnoptr = stext->s_lnnoptr;
1160
1170
  nlnno = stext->s_nlnno;
@@ -1193,7 +1203,9 @@ xcoff_add (struct backtrace_state *state, int descriptor, off_t offset,
1193
1203
  goto fail;
1194
1204
  syms_view_valid = 1;
1195
1205
 
1196
- memcpy (&str_size, syms_view.data + syms_size, 4);
1206
+ memcpy (&str_size,
1207
+ (const unsigned char *) syms_view.data + syms_size,
1208
+ 4);
1197
1209
 
1198
1210
  str_off = fhdr.f_symptr + syms_size;
1199
1211
 
@@ -1212,7 +1224,7 @@ xcoff_add (struct backtrace_state *state, int descriptor, off_t offset,
1212
1224
  if (sdata == NULL)
1213
1225
  goto fail;
1214
1226
 
1215
- if (!xcoff_initialize_syminfo (state, base_address, sects,
1227
+ if (!xcoff_initialize_syminfo (state, base_address,
1216
1228
  syms_view.data, fhdr.f_nsyms,
1217
1229
  str_view.data, str_size,
1218
1230
  error_callback, data, sdata))
@@ -1252,7 +1264,7 @@ xcoff_add (struct backtrace_state *state, int descriptor, off_t offset,
1252
1264
  case SSUBTYP_DWABREV:
1253
1265
  idx = DEBUG_ABBREV;
1254
1266
  break;
1255
- case SSUBTYP_DWARNGE:
1267
+ case SSUBTYP_DWRNGES:
1256
1268
  idx = DEBUG_RANGES;
1257
1269
  break;
1258
1270
  case SSUBTYP_DWSTR:
@@ -1290,13 +1302,7 @@ xcoff_add (struct backtrace_state *state, int descriptor, off_t offset,
1290
1302
 
1291
1303
  dwarf_sections.data[DEBUG_INFO] = dwsect[DEBUG_INFO].data;
1292
1304
  dwarf_sections.size[DEBUG_INFO] = dwsect[DEBUG_INFO].size;
1293
- #if BACKTRACE_XCOFF_SIZE == 32
1294
- /* XXX workaround for broken lineoff */
1295
- dwarf_sections.data[DEBUG_LINE] = dwsect[DEBUG_LINE].data - 4;
1296
- #else
1297
- /* XXX workaround for broken lineoff */
1298
- dwarf_sections.data[DEBUG_LINE] = dwsect[DEBUG_LINE].data - 12;
1299
- #endif
1305
+ dwarf_sections.data[DEBUG_LINE] = dwsect[DEBUG_LINE].data;
1300
1306
  dwarf_sections.size[DEBUG_LINE] = dwsect[DEBUG_LINE].size;
1301
1307
  dwarf_sections.data[DEBUG_ABBREV] = dwsect[DEBUG_ABBREV].data;
1302
1308
  dwarf_sections.size[DEBUG_ABBREV] = dwsect[DEBUG_ABBREV].size;
@@ -1305,7 +1311,7 @@ xcoff_add (struct backtrace_state *state, int descriptor, off_t offset,
1305
1311
  dwarf_sections.data[DEBUG_STR] = dwsect[DEBUG_STR].data;
1306
1312
  dwarf_sections.size[DEBUG_STR] = dwsect[DEBUG_STR].size;
1307
1313
 
1308
- if (!backtrace_dwarf_add (state, 0, &dwarf_sections,
1314
+ if (!backtrace_dwarf_add (state, base_address, &dwarf_sections,
1309
1315
  1, /* big endian */
1310
1316
  NULL, /* altlink */
1311
1317
  error_callback, data, fileline_fn,
@@ -1390,9 +1396,9 @@ xcoff_parse_decimal (const char *buf, size_t size, off_t *off)
1390
1396
 
1391
1397
  static int
1392
1398
  xcoff_armem_add (struct backtrace_state *state, int descriptor,
1393
- uintptr_t base_address, const char *member,
1394
- backtrace_error_callback error_callback, void *data,
1395
- fileline *fileline_fn, int *found_sym)
1399
+ struct libbacktrace_base_address base_address,
1400
+ const char *member, backtrace_error_callback error_callback,
1401
+ void *data, fileline *fileline_fn, int *found_sym)
1396
1402
  {
1397
1403
  struct backtrace_view view;
1398
1404
  b_ar_fl_hdr fl_hdr;
@@ -1513,6 +1519,8 @@ xcoff_add_shared_libs (struct backtrace_state *state,
1513
1519
  ldinfo = (const struct ld_info *) buf;
1514
1520
  while ((const char *) ldinfo < (const char *) buf + buflen)
1515
1521
  {
1522
+ struct libbacktrace_base_address base_address;
1523
+
1516
1524
  if (*ldinfo->ldinfo_filename != '/')
1517
1525
  goto next;
1518
1526
 
@@ -1524,16 +1532,17 @@ xcoff_add_shared_libs (struct backtrace_state *state,
1524
1532
  /* Check if it is an archive (member name not empty). */
1525
1533
 
1526
1534
  member = ldinfo->ldinfo_filename + strlen (ldinfo->ldinfo_filename) + 1;
1535
+ memset (&base_address, 0, sizeof base_address);
1536
+ base_address.m = (uintptr_t) ldinfo->ldinfo_textorg;
1527
1537
  if (*member)
1528
1538
  {
1529
- xcoff_armem_add (state, descriptor,
1530
- (uintptr_t) ldinfo->ldinfo_textorg, member,
1539
+ xcoff_armem_add (state, descriptor, base_address, member,
1531
1540
  error_callback, data, fileline_fn, &lib_found_sym);
1532
1541
  }
1533
1542
  else
1534
1543
  {
1535
- xcoff_add (state, descriptor, 0, (uintptr_t) ldinfo->ldinfo_textorg,
1536
- error_callback, data, fileline_fn, &lib_found_sym, 0);
1544
+ xcoff_add (state, descriptor, 0, base_address, error_callback, data,
1545
+ fileline_fn, &lib_found_sym, 0);
1537
1546
  }
1538
1547
  if (lib_found_sym)
1539
1548
  *found_sym = 1;
@@ -1558,12 +1567,14 @@ backtrace_initialize (struct backtrace_state *state,
1558
1567
  backtrace_error_callback error_callback,
1559
1568
  void *data, fileline *fileline_fn)
1560
1569
  {
1570
+ struct libbacktrace_base_address zero_base_address;
1561
1571
  int ret;
1562
1572
  int found_sym;
1563
1573
  fileline xcoff_fileline_fn = xcoff_nodebug;
1564
1574
 
1565
- ret = xcoff_add (state, descriptor, 0, 0, error_callback, data,
1566
- &xcoff_fileline_fn, &found_sym, 1);
1575
+ memset (&zero_base_address, 0, sizeof zero_base_address);
1576
+ ret = xcoff_add (state, descriptor, 0, zero_base_address,
1577
+ error_callback, data, &xcoff_fileline_fn, &found_sym, 1);
1567
1578
  if (!ret)
1568
1579
  return 0;
1569
1580
 
@@ -1,5 +1,5 @@
1
1
  /* xztest.c -- Test for libbacktrace LZMA decoder.
2
- Copyright (C) 2020-2021 Free Software Foundation, Inc.
2
+ Copyright (C) 2020-2024 Free Software Foundation, Inc.
3
3
  Written by Ian Lance Taylor, Google.
4
4
 
5
5
  Redistribution and use in source and binary forms, with or without
@@ -172,7 +172,7 @@ test_samples (struct backtrace_state *state)
172
172
  tests[i].name, uncompressed_len, v);
173
173
  ++failures;
174
174
  }
175
- else if (memcmp (tests[i].uncompressed, uncompressed, v) != 0)
175
+ else if (v > 0 && memcmp (tests[i].uncompressed, uncompressed, v) != 0)
176
176
  {
177
177
  size_t j;
178
178
 
@@ -1,5 +1,5 @@
1
1
  /* ztest.c -- Test for libbacktrace zstd code.
2
- Copyright (C) 2022 Free Software Foundation, Inc.
2
+ Copyright (C) 2022-2024 Free Software Foundation, Inc.
3
3
  Written by Ian Lance Taylor, Google.
4
4
 
5
5
  Redistribution and use in source and binary forms, with or without
@@ -1,5 +1,5 @@
1
1
  /* ztest.c -- Test for libbacktrace inflate code.
2
- Copyright (C) 2017-2021 Free Software Foundation, Inc.
2
+ Copyright (C) 2017-2024 Free Software Foundation, Inc.
3
3
  Written by Ian Lance Taylor, Google.
4
4
 
5
5
  Redistribution and use in source and binary forms, with or without
data/ext/pf2/Cargo.toml CHANGED
@@ -13,7 +13,7 @@ backtrace-sys2 = { path = "../../crates/backtrace-sys2" }
13
13
  env_logger = { version = "0.11.0", optional = true }
14
14
  libc = "0.2.149"
15
15
  log = "0.4.20"
16
- rb-sys = { version = "0.9.82", features = ["stable-api", "stable-api-compiled-testing"] } # using stable-api-compiled-testing for generating bindings from Ruby source
16
+ rb-sys = { version = "0.9.105", features = ["stable-api"] }
17
17
  serde = "1.0.189"
18
18
  serde_derive = "1.0.189"
19
19
  serde_json = "1.0.107"
data/ext/pf2/src/lib.rs CHANGED
@@ -10,6 +10,7 @@ mod profile_serializer;
10
10
  mod ringbuffer;
11
11
  mod sample;
12
12
  mod scheduler;
13
+ mod serialization;
13
14
  mod session;
14
15
  #[cfg(target_os = "linux")]
15
16
  mod signal_scheduler;
@@ -1,4 +1,4 @@
1
- use std::time::Instant;
1
+ use std::time::{Instant, SystemTime};
2
2
  use std::{collections::HashSet, ptr::null_mut};
3
3
 
4
4
  use rb_sys::*;
@@ -15,7 +15,9 @@ const DEFAULT_RINGBUFFER_CAPACITY: usize = 320;
15
15
 
16
16
  #[derive(Debug)]
17
17
  pub struct Profile {
18
- pub start_timestamp: Instant,
18
+ pub start_timestamp: SystemTime,
19
+ pub start_instant: Instant,
20
+ pub end_instant: Option<Instant>,
19
21
  pub samples: Vec<Sample>,
20
22
  pub temporary_sample_buffer: Ringbuffer,
21
23
  pub backtrace_state: BacktraceState,
@@ -35,7 +37,9 @@ impl Profile {
35
37
  };
36
38
 
37
39
  Self {
38
- start_timestamp: Instant::now(),
40
+ start_timestamp: SystemTime::now(),
41
+ start_instant: Instant::now(),
42
+ end_instant: None,
39
43
  samples: vec![],
40
44
  temporary_sample_buffer: Ringbuffer::new(DEFAULT_RINGBUFFER_CAPACITY),
41
45
  backtrace_state,
@@ -29,11 +29,7 @@ impl ThreadProfile {
29
29
  ThreadProfile {
30
30
  thread_id,
31
31
  // The root node
32
- stack_tree: StackTreeNode {
33
- children: HashMap::new(),
34
- node_id: 0,
35
- frame_id: 0,
36
- },
32
+ stack_tree: StackTreeNode { children: HashMap::new(), node_id: 0, frame_id: 0 },
37
33
  frame_table: HashMap::new(),
38
34
  samples: vec![],
39
35
  }
@@ -91,9 +87,7 @@ impl ProfileSerializer {
91
87
  pub fn serialize(profile: &Profile) -> String {
92
88
  let mut sequence = 1;
93
89
 
94
- let mut serializer = ProfileSerializer {
95
- threads: HashMap::new(),
96
- };
90
+ let mut serializer = ProfileSerializer { threads: HashMap::new() };
97
91
 
98
92
  unsafe {
99
93
  // Process each sample
@@ -221,11 +215,10 @@ impl ProfileSerializer {
221
215
 
222
216
  if merged_stack.is_empty() {
223
217
  // This is the leaf node, record a Sample
224
- let elapsed_ns = (sample.timestamp - profile.start_timestamp).as_nanos();
225
- thread_serializer.samples.push(ProfileSample {
226
- elapsed_ns,
227
- stack_tree_id: stack_tree.node_id,
228
- });
218
+ let elapsed_ns = (sample.timestamp - profile.start_instant).as_nanos();
219
+ thread_serializer
220
+ .samples
221
+ .push(ProfileSample { elapsed_ns, stack_tree_id: stack_tree.node_id });
229
222
  }
230
223
 
231
224
  // Register frame metadata to frame table, if not registered yet
@@ -17,9 +17,7 @@ impl Ringbuffer {
17
17
  pub fn new(capacity: usize) -> Self {
18
18
  Self {
19
19
  capacity,
20
- buffer: std::iter::repeat_with(|| None)
21
- .take(capacity + 1)
22
- .collect::<Vec<_>>(),
20
+ buffer: std::iter::repeat_with(|| None).take(capacity + 1).collect::<Vec<_>>(),
23
21
  read_index: 0,
24
22
  write_index: 0,
25
23
  }
@@ -10,10 +10,7 @@ use crate::util::*;
10
10
  extern "C" fn Init_pf2() {
11
11
  #[cfg(feature = "debug")]
12
12
  {
13
- env_logger::builder()
14
- .format_timestamp(None)
15
- .format_module_path(false)
16
- .init();
13
+ env_logger::builder().format_timestamp(None).format_module_path(false).init();
17
14
  }
18
15
 
19
16
  unsafe {
@@ -14,6 +14,7 @@ pub struct Sample {
14
14
  pub line_count: i32,
15
15
  pub frames: [VALUE; MAX_STACK_DEPTH],
16
16
  pub linenos: [i32; MAX_STACK_DEPTH],
17
+ /// First element represents the backtrace depth.
17
18
  pub c_backtrace_pcs: [usize; MAX_C_STACK_DEPTH + 1],
18
19
  }
19
20
 
@@ -0,0 +1,47 @@
1
+ #[derive(Clone, Deserialize, Serialize)]
2
+ pub struct Profile {
3
+ pub samples: Vec<Sample>,
4
+ pub locations: Vec<Location>,
5
+ pub functions: Vec<Function>,
6
+ pub start_timestamp_ns: u128,
7
+ pub duration_ns: u128,
8
+ }
9
+
10
+ pub type LocationIndex = usize;
11
+ pub type FunctionIndex = usize;
12
+
13
+ /// Sample
14
+ #[derive(Clone, Serialize, Deserialize)]
15
+ pub struct Sample {
16
+ /// The stack leading to this sample.
17
+ /// The leaf node will be stored at `stack[0]`.
18
+ pub stack: Vec<LocationIndex>,
19
+ pub native_stack: Vec<LocationIndex>,
20
+ pub ruby_thread_id: Option<u64>,
21
+ }
22
+
23
+ /// Location represents a location (line) in the source code when a sample was captured.
24
+ #[derive(Clone, PartialEq, Serialize, Deserialize)]
25
+ pub struct Location {
26
+ pub function_index: FunctionIndex,
27
+ pub lineno: i32,
28
+ pub address: Option<usize>,
29
+ }
30
+
31
+ /// Function represents a Ruby method or a C function in the profile.
32
+ #[derive(Clone, PartialEq, Serialize, Deserialize)]
33
+ pub struct Function {
34
+ pub implementation: FunctionImplementation,
35
+ pub name: Option<String>, // unique key
36
+ pub filename: Option<String>,
37
+ /// The first line number in the method/function definition.
38
+ /// For the actual location (line) which was hit during sample capture, refer to `Location.lineno`.
39
+ pub start_lineno: Option<i32>,
40
+ pub start_address: Option<usize>,
41
+ }
42
+
43
+ #[derive(Clone, PartialEq, Serialize, Deserialize)]
44
+ pub enum FunctionImplementation {
45
+ Ruby,
46
+ Native,
47
+ }