pf2 0.1.0 → 0.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8e386916b39ce131297e3e29ec4eca107fe9b2ebe98e69db68f1c84091fac724
4
- data.tar.gz: 84a658c4f5f336a39a52b2ed58ccb600e7b4f541cd58b4aeea041863db4edfc9
3
+ metadata.gz: 1062b7dd7fbbc96396e59dcd189bc63f20a98f81f68f871e8f2b36fb7be82f42
4
+ data.tar.gz: 8c809750b5e2bca91b0d51a81f583ee31d8a2c63fd9162bc5d4bdbd946915f06
5
5
  SHA512:
6
- metadata.gz: 16d6addbe2abbf348158dca6f2c7e2d048048a22d8a93b194556195e0c9d7c00c51c50f8b82bd462b263d7db6bc8211da1112d5d436fcfdafba08591b618e901
7
- data.tar.gz: 0603d44895aeea77484c6862cbd2660dffa131c4ad5761aaa94e5c67c44bce04491b7ab29078897b095b44d07fc31dbb7351056cbbc005d3f097c2cb83744fc0
6
+ metadata.gz: d1e1ac1962437b0f2d0fb89cc6d0ef5fa4dca4dec0a47a67500fb30d99ec4f17433f600288a32686d003e3771907273e3c1606a1345db1c658a12e7c1b11b51b
7
+ data.tar.gz: 90a8c791f2e5a26a68b9bf90c70d302d63ce4ec77058dbfa8dd86e7aed1f13cafb61521ce12cddb42bb43019217a58a4b451edb858417748f32b140313610eef
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## [0.2.0] - 2024-01-21
2
+
3
+ - New Ruby interface: Pf2.start, Pf2.stop, Pf2.profile
4
+ - Introduce the concepts of Schedulers
5
+ - Implement SignalScheduler and TimerThreadScheduler
6
+ - Rewritten many components
7
+
1
8
  ## [0.1.0] - 2023-10-04
2
9
 
3
10
  - Initial release
data/Cargo.lock ADDED
@@ -0,0 +1,481 @@
1
+ # This file is automatically @generated by Cargo.
2
+ # It is not intended for manual editing.
3
+ version = 3
4
+
5
+ [[package]]
6
+ name = "aho-corasick"
7
+ version = "1.1.2"
8
+ source = "registry+https://github.com/rust-lang/crates.io-index"
9
+ checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0"
10
+ dependencies = [
11
+ "memchr",
12
+ ]
13
+
14
+ [[package]]
15
+ name = "anstream"
16
+ version = "0.6.11"
17
+ source = "registry+https://github.com/rust-lang/crates.io-index"
18
+ checksum = "6e2e1ebcb11de5c03c67de28a7df593d32191b44939c482e97702baaaa6ab6a5"
19
+ dependencies = [
20
+ "anstyle",
21
+ "anstyle-parse",
22
+ "anstyle-query",
23
+ "anstyle-wincon",
24
+ "colorchoice",
25
+ "utf8parse",
26
+ ]
27
+
28
+ [[package]]
29
+ name = "anstyle"
30
+ version = "1.0.4"
31
+ source = "registry+https://github.com/rust-lang/crates.io-index"
32
+ checksum = "7079075b41f533b8c61d2a4d073c4676e1f8b249ff94a393b0595db304e0dd87"
33
+
34
+ [[package]]
35
+ name = "anstyle-parse"
36
+ version = "0.2.3"
37
+ source = "registry+https://github.com/rust-lang/crates.io-index"
38
+ checksum = "c75ac65da39e5fe5ab759307499ddad880d724eed2f6ce5b5e8a26f4f387928c"
39
+ dependencies = [
40
+ "utf8parse",
41
+ ]
42
+
43
+ [[package]]
44
+ name = "anstyle-query"
45
+ version = "1.0.2"
46
+ source = "registry+https://github.com/rust-lang/crates.io-index"
47
+ checksum = "e28923312444cdd728e4738b3f9c9cac739500909bb3d3c94b43551b16517648"
48
+ dependencies = [
49
+ "windows-sys",
50
+ ]
51
+
52
+ [[package]]
53
+ name = "anstyle-wincon"
54
+ version = "3.0.2"
55
+ source = "registry+https://github.com/rust-lang/crates.io-index"
56
+ checksum = "1cd54b81ec8d6180e24654d0b371ad22fc3dd083b6ff8ba325b72e00c87660a7"
57
+ dependencies = [
58
+ "anstyle",
59
+ "windows-sys",
60
+ ]
61
+
62
+ [[package]]
63
+ name = "bindgen"
64
+ version = "0.66.1"
65
+ source = "registry+https://github.com/rust-lang/crates.io-index"
66
+ checksum = "f2b84e06fc203107bfbad243f4aba2af864eb7db3b1cf46ea0a023b0b433d2a7"
67
+ dependencies = [
68
+ "bitflags",
69
+ "cexpr",
70
+ "clang-sys",
71
+ "lazy_static",
72
+ "lazycell",
73
+ "peeking_take_while",
74
+ "proc-macro2",
75
+ "quote",
76
+ "regex",
77
+ "rustc-hash",
78
+ "shlex",
79
+ "syn",
80
+ ]
81
+
82
+ [[package]]
83
+ name = "bitflags"
84
+ version = "2.4.1"
85
+ source = "registry+https://github.com/rust-lang/crates.io-index"
86
+ checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07"
87
+
88
+ [[package]]
89
+ name = "cc"
90
+ version = "1.0.83"
91
+ source = "registry+https://github.com/rust-lang/crates.io-index"
92
+ checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0"
93
+ dependencies = [
94
+ "libc",
95
+ ]
96
+
97
+ [[package]]
98
+ name = "cexpr"
99
+ version = "0.6.0"
100
+ source = "registry+https://github.com/rust-lang/crates.io-index"
101
+ checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766"
102
+ dependencies = [
103
+ "nom",
104
+ ]
105
+
106
+ [[package]]
107
+ name = "cfg-if"
108
+ version = "1.0.0"
109
+ source = "registry+https://github.com/rust-lang/crates.io-index"
110
+ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
111
+
112
+ [[package]]
113
+ name = "clang-sys"
114
+ version = "1.6.1"
115
+ source = "registry+https://github.com/rust-lang/crates.io-index"
116
+ checksum = "c688fc74432808e3eb684cae8830a86be1d66a2bd58e1f248ed0960a590baf6f"
117
+ dependencies = [
118
+ "glob",
119
+ "libc",
120
+ "libloading",
121
+ ]
122
+
123
+ [[package]]
124
+ name = "colorchoice"
125
+ version = "1.0.0"
126
+ source = "registry+https://github.com/rust-lang/crates.io-index"
127
+ checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7"
128
+
129
+ [[package]]
130
+ name = "env_filter"
131
+ version = "0.1.0"
132
+ source = "registry+https://github.com/rust-lang/crates.io-index"
133
+ checksum = "a009aa4810eb158359dda09d0c87378e4bbb89b5a801f016885a4707ba24f7ea"
134
+ dependencies = [
135
+ "log",
136
+ "regex",
137
+ ]
138
+
139
+ [[package]]
140
+ name = "env_logger"
141
+ version = "0.11.0"
142
+ source = "registry+https://github.com/rust-lang/crates.io-index"
143
+ checksum = "9eeb342678d785662fd2514be38c459bb925f02b68dd2a3e0f21d7ef82d979dd"
144
+ dependencies = [
145
+ "anstream",
146
+ "anstyle",
147
+ "env_filter",
148
+ "humantime",
149
+ "log",
150
+ ]
151
+
152
+ [[package]]
153
+ name = "glob"
154
+ version = "0.3.1"
155
+ source = "registry+https://github.com/rust-lang/crates.io-index"
156
+ checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b"
157
+
158
+ [[package]]
159
+ name = "humantime"
160
+ version = "2.1.0"
161
+ source = "registry+https://github.com/rust-lang/crates.io-index"
162
+ checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
163
+
164
+ [[package]]
165
+ name = "itoa"
166
+ version = "1.0.9"
167
+ source = "registry+https://github.com/rust-lang/crates.io-index"
168
+ checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38"
169
+
170
+ [[package]]
171
+ name = "lazy_static"
172
+ version = "1.4.0"
173
+ source = "registry+https://github.com/rust-lang/crates.io-index"
174
+ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
175
+
176
+ [[package]]
177
+ name = "lazycell"
178
+ version = "1.3.0"
179
+ source = "registry+https://github.com/rust-lang/crates.io-index"
180
+ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
181
+
182
+ [[package]]
183
+ name = "libc"
184
+ version = "0.2.149"
185
+ source = "registry+https://github.com/rust-lang/crates.io-index"
186
+ checksum = "a08173bc88b7955d1b3145aa561539096c421ac8debde8cbc3612ec635fee29b"
187
+
188
+ [[package]]
189
+ name = "libloading"
190
+ version = "0.7.4"
191
+ source = "registry+https://github.com/rust-lang/crates.io-index"
192
+ checksum = "b67380fd3b2fbe7527a606e18729d21c6f3951633d0500574c4dc22d2d638b9f"
193
+ dependencies = [
194
+ "cfg-if",
195
+ "winapi",
196
+ ]
197
+
198
+ [[package]]
199
+ name = "log"
200
+ version = "0.4.20"
201
+ source = "registry+https://github.com/rust-lang/crates.io-index"
202
+ checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f"
203
+
204
+ [[package]]
205
+ name = "memchr"
206
+ version = "2.6.4"
207
+ source = "registry+https://github.com/rust-lang/crates.io-index"
208
+ checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167"
209
+
210
+ [[package]]
211
+ name = "minimal-lexical"
212
+ version = "0.2.1"
213
+ source = "registry+https://github.com/rust-lang/crates.io-index"
214
+ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
215
+
216
+ [[package]]
217
+ name = "nom"
218
+ version = "7.1.3"
219
+ source = "registry+https://github.com/rust-lang/crates.io-index"
220
+ checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a"
221
+ dependencies = [
222
+ "memchr",
223
+ "minimal-lexical",
224
+ ]
225
+
226
+ [[package]]
227
+ name = "peeking_take_while"
228
+ version = "0.1.2"
229
+ source = "registry+https://github.com/rust-lang/crates.io-index"
230
+ checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099"
231
+
232
+ [[package]]
233
+ name = "pf2"
234
+ version = "0.1.0"
235
+ dependencies = [
236
+ "cc",
237
+ "env_logger",
238
+ "libc",
239
+ "log",
240
+ "rb-sys",
241
+ "serde",
242
+ "serde_derive",
243
+ "serde_json",
244
+ ]
245
+
246
+ [[package]]
247
+ name = "proc-macro2"
248
+ version = "1.0.69"
249
+ source = "registry+https://github.com/rust-lang/crates.io-index"
250
+ checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da"
251
+ dependencies = [
252
+ "unicode-ident",
253
+ ]
254
+
255
+ [[package]]
256
+ name = "quote"
257
+ version = "1.0.33"
258
+ source = "registry+https://github.com/rust-lang/crates.io-index"
259
+ checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae"
260
+ dependencies = [
261
+ "proc-macro2",
262
+ ]
263
+
264
+ [[package]]
265
+ name = "rb-sys"
266
+ version = "0.9.82"
267
+ source = "registry+https://github.com/rust-lang/crates.io-index"
268
+ checksum = "a3e6bf79bf4c711917cacfaf46dfab4314dbfdd89a8ee3ec4b98336cd23f1ebf"
269
+ dependencies = [
270
+ "rb-sys-build",
271
+ ]
272
+
273
+ [[package]]
274
+ name = "rb-sys-build"
275
+ version = "0.9.82"
276
+ source = "registry+https://github.com/rust-lang/crates.io-index"
277
+ checksum = "5482a1ed4cde58dddaf162b6aebcb5c25645822547832b8be101f2acd40bcdd6"
278
+ dependencies = [
279
+ "bindgen",
280
+ "lazy_static",
281
+ "proc-macro2",
282
+ "quote",
283
+ "regex",
284
+ "shell-words",
285
+ "syn",
286
+ ]
287
+
288
+ [[package]]
289
+ name = "regex"
290
+ version = "1.10.2"
291
+ source = "registry+https://github.com/rust-lang/crates.io-index"
292
+ checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343"
293
+ dependencies = [
294
+ "aho-corasick",
295
+ "memchr",
296
+ "regex-automata",
297
+ "regex-syntax",
298
+ ]
299
+
300
+ [[package]]
301
+ name = "regex-automata"
302
+ version = "0.4.3"
303
+ source = "registry+https://github.com/rust-lang/crates.io-index"
304
+ checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f"
305
+ dependencies = [
306
+ "aho-corasick",
307
+ "memchr",
308
+ "regex-syntax",
309
+ ]
310
+
311
+ [[package]]
312
+ name = "regex-syntax"
313
+ version = "0.8.2"
314
+ source = "registry+https://github.com/rust-lang/crates.io-index"
315
+ checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f"
316
+
317
+ [[package]]
318
+ name = "rustc-hash"
319
+ version = "1.1.0"
320
+ source = "registry+https://github.com/rust-lang/crates.io-index"
321
+ checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
322
+
323
+ [[package]]
324
+ name = "ryu"
325
+ version = "1.0.15"
326
+ source = "registry+https://github.com/rust-lang/crates.io-index"
327
+ checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741"
328
+
329
+ [[package]]
330
+ name = "serde"
331
+ version = "1.0.189"
332
+ source = "registry+https://github.com/rust-lang/crates.io-index"
333
+ checksum = "8e422a44e74ad4001bdc8eede9a4570ab52f71190e9c076d14369f38b9200537"
334
+ dependencies = [
335
+ "serde_derive",
336
+ ]
337
+
338
+ [[package]]
339
+ name = "serde_derive"
340
+ version = "1.0.189"
341
+ source = "registry+https://github.com/rust-lang/crates.io-index"
342
+ checksum = "1e48d1f918009ce3145511378cf68d613e3b3d9137d67272562080d68a2b32d5"
343
+ dependencies = [
344
+ "proc-macro2",
345
+ "quote",
346
+ "syn",
347
+ ]
348
+
349
+ [[package]]
350
+ name = "serde_json"
351
+ version = "1.0.107"
352
+ source = "registry+https://github.com/rust-lang/crates.io-index"
353
+ checksum = "6b420ce6e3d8bd882e9b243c6eed35dbc9a6110c9769e74b584e0d68d1f20c65"
354
+ dependencies = [
355
+ "itoa",
356
+ "ryu",
357
+ "serde",
358
+ ]
359
+
360
+ [[package]]
361
+ name = "shell-words"
362
+ version = "1.1.0"
363
+ source = "registry+https://github.com/rust-lang/crates.io-index"
364
+ checksum = "24188a676b6ae68c3b2cb3a01be17fbf7240ce009799bb56d5b1409051e78fde"
365
+
366
+ [[package]]
367
+ name = "shlex"
368
+ version = "1.2.0"
369
+ source = "registry+https://github.com/rust-lang/crates.io-index"
370
+ checksum = "a7cee0529a6d40f580e7a5e6c495c8fbfe21b7b52795ed4bb5e62cdf92bc6380"
371
+
372
+ [[package]]
373
+ name = "syn"
374
+ version = "2.0.38"
375
+ source = "registry+https://github.com/rust-lang/crates.io-index"
376
+ checksum = "e96b79aaa137db8f61e26363a0c9b47d8b4ec75da28b7d1d614c2303e232408b"
377
+ dependencies = [
378
+ "proc-macro2",
379
+ "quote",
380
+ "unicode-ident",
381
+ ]
382
+
383
+ [[package]]
384
+ name = "unicode-ident"
385
+ version = "1.0.12"
386
+ source = "registry+https://github.com/rust-lang/crates.io-index"
387
+ checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
388
+
389
+ [[package]]
390
+ name = "utf8parse"
391
+ version = "0.2.1"
392
+ source = "registry+https://github.com/rust-lang/crates.io-index"
393
+ checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a"
394
+
395
+ [[package]]
396
+ name = "winapi"
397
+ version = "0.3.9"
398
+ source = "registry+https://github.com/rust-lang/crates.io-index"
399
+ checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
400
+ dependencies = [
401
+ "winapi-i686-pc-windows-gnu",
402
+ "winapi-x86_64-pc-windows-gnu",
403
+ ]
404
+
405
+ [[package]]
406
+ name = "winapi-i686-pc-windows-gnu"
407
+ version = "0.4.0"
408
+ source = "registry+https://github.com/rust-lang/crates.io-index"
409
+ checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
410
+
411
+ [[package]]
412
+ name = "winapi-x86_64-pc-windows-gnu"
413
+ version = "0.4.0"
414
+ source = "registry+https://github.com/rust-lang/crates.io-index"
415
+ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
416
+
417
+ [[package]]
418
+ name = "windows-sys"
419
+ version = "0.52.0"
420
+ source = "registry+https://github.com/rust-lang/crates.io-index"
421
+ checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"
422
+ dependencies = [
423
+ "windows-targets",
424
+ ]
425
+
426
+ [[package]]
427
+ name = "windows-targets"
428
+ version = "0.52.0"
429
+ source = "registry+https://github.com/rust-lang/crates.io-index"
430
+ checksum = "8a18201040b24831fbb9e4eb208f8892e1f50a37feb53cc7ff887feb8f50e7cd"
431
+ dependencies = [
432
+ "windows_aarch64_gnullvm",
433
+ "windows_aarch64_msvc",
434
+ "windows_i686_gnu",
435
+ "windows_i686_msvc",
436
+ "windows_x86_64_gnu",
437
+ "windows_x86_64_gnullvm",
438
+ "windows_x86_64_msvc",
439
+ ]
440
+
441
+ [[package]]
442
+ name = "windows_aarch64_gnullvm"
443
+ version = "0.52.0"
444
+ source = "registry+https://github.com/rust-lang/crates.io-index"
445
+ checksum = "cb7764e35d4db8a7921e09562a0304bf2f93e0a51bfccee0bd0bb0b666b015ea"
446
+
447
+ [[package]]
448
+ name = "windows_aarch64_msvc"
449
+ version = "0.52.0"
450
+ source = "registry+https://github.com/rust-lang/crates.io-index"
451
+ checksum = "bbaa0368d4f1d2aaefc55b6fcfee13f41544ddf36801e793edbbfd7d7df075ef"
452
+
453
+ [[package]]
454
+ name = "windows_i686_gnu"
455
+ version = "0.52.0"
456
+ source = "registry+https://github.com/rust-lang/crates.io-index"
457
+ checksum = "a28637cb1fa3560a16915793afb20081aba2c92ee8af57b4d5f28e4b3e7df313"
458
+
459
+ [[package]]
460
+ name = "windows_i686_msvc"
461
+ version = "0.52.0"
462
+ source = "registry+https://github.com/rust-lang/crates.io-index"
463
+ checksum = "ffe5e8e31046ce6230cc7215707b816e339ff4d4d67c65dffa206fd0f7aa7b9a"
464
+
465
+ [[package]]
466
+ name = "windows_x86_64_gnu"
467
+ version = "0.52.0"
468
+ source = "registry+https://github.com/rust-lang/crates.io-index"
469
+ checksum = "3d6fa32db2bc4a2f5abeacf2b69f7992cd09dca97498da74a151a3132c26befd"
470
+
471
+ [[package]]
472
+ name = "windows_x86_64_gnullvm"
473
+ version = "0.52.0"
474
+ source = "registry+https://github.com/rust-lang/crates.io-index"
475
+ checksum = "1a657e1e9d3f514745a572a6846d3c7aa7dbe1658c056ed9c3344c4109a6949e"
476
+
477
+ [[package]]
478
+ name = "windows_x86_64_msvc"
479
+ version = "0.52.0"
480
+ source = "registry+https://github.com/rust-lang/crates.io-index"
481
+ checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04"
data/Cargo.toml ADDED
@@ -0,0 +1,3 @@
1
+ [workspace]
2
+ members = ["./ext/pf2"]
3
+ resolver = "2"
data/README.md CHANGED
@@ -1,26 +1,112 @@
1
- # Pf2
1
+ Pf2
2
+ ===========
2
3
 
3
- A sampling-based profiler for Ruby.
4
- Works only on a patched version of CRuby (MRI) at the moment.
4
+ A experimental sampling-based profiler for Ruby 3.3+.
5
5
 
6
- ## Installation
6
+ Notable Capabilites
7
+ --------
7
8
 
8
- TBD
9
+ - Can accurately track multiple Ruby Threads' activity
10
+ - Sampling interval can be set based on per-Thread CPU usage
9
11
 
10
- ## Usage
12
+ Usage
13
+ --------
11
14
 
12
- TBD
15
+ ### Profiling
13
16
 
14
- ## Development
17
+ Pf2 will collect samples every 10 ms of wall time by default.
15
18
 
16
- After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
19
+ ```ruby
20
+ # Specify Ruby Threads to track in the first argument.
21
+ # New Ruby Threads will be tracked if the second argument is true.
22
+ Pf2.start([Thread.current], false)
23
+ your_code_here() # will be profiled
24
+ Thread.new { threaded_code() } # will also be profiled if second argument is true
17
25
 
18
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
26
+ # Stop profiling and save the profile for visualization
27
+ profile = Pf2.stop
28
+ File.write("my_program.pf2profile", profile)
29
+ ```
19
30
 
20
- ## Contributing
31
+ Alternatively, you may provide a code block to profile.
21
32
 
22
- Bug reports and pull requests are welcome on GitHub at https://github.com/osyoyu/pf2.
33
+ ```ruby
34
+ profile = Pf2.profile do
35
+ your_code_here() # will be profiled
36
+ Thread.new { threaded_code() } # will also be profiled
37
+ end
23
38
 
24
- ## License
39
+ # Save the profile for visualization
40
+ File.write("my_program.pf2profile", profile)
41
+ ```
42
+
43
+ ### Reporting / Visualization
44
+
45
+ Profiles can be visualized using the [Firefox Profiler](https://profiler.firefox.com/).
46
+
47
+ ```console
48
+ $ pf2 -o report.json my_program.pf2profile
49
+ ```
50
+
51
+ ### Configuration
52
+
53
+ (TBD)
54
+
55
+ Overhead
56
+ --------
57
+
58
+ While Pf2 aims to be non-disturbulent as much as possible, a small overhead still is incured.
59
+
60
+ (TBD)
61
+
62
+ Limitations
63
+ --------
64
+
65
+ Pf2 cannot properly track program activity in some known cases. I'm working to remove these limtations, so stay tuned.
66
+
67
+ - Program execution in forked processes
68
+ - Workarounds available for Puma
69
+ - Program execution in Fibers
70
+ - Program execution when MaNy (`RUBY_MN_THREADS`) is enabled
71
+
72
+ Internals
73
+ --------
74
+
75
+ ### Sampling
76
+
77
+ Pf2 is a _sampling profiler_. This means that Pf2 collects _samples_ of program execution periodically, instead of tracing every action (e.g. method invocations and returns).
78
+
79
+ Pf2 uses the `rb_profile_thread_frames()` API for sampling. When to do so is controlled by _Schedulers_, described in the following section.
80
+
81
+ ### Schedulers
82
+
83
+ Schedulers determine when to execute sample collection, based on configuration (time mode and interval). Pf2 has two schedulers available.
84
+
85
+ #### SignalScheduler (Linux-only)
86
+
87
+ The first is the `SignalScheduler`, based on POSIX timers. Pf2 will use this scheduler when possible. SignalScheduler creates a POSIX timer for each Ruby Thread (the underlying pthread to be more accurate) using `timer_create(3)`. This leaves the actual time-keeping to the OS, which is capable of tracking accurate per-thread CPU time usage.
88
+
89
+ When the specified interval has arrived (the timer has _expired_), the OS delivers us a SIGALRM (note: Unlike `setitimer(2)`, `timer_create(3)` allows us to choose which signal to be delivered, and Pf2 uses SIGALRM regardless of time mode). This is why the scheduler is named SignalScheduler.
90
+
91
+ Signals are directed to Ruby Threads' underlying pthread, effectively "pausing" the Thread's activity. This routing is done using `SIGEV_THREAD_ID`, which is a Linux-only feature. Sample collection is done in the signal handler, which is expected to be more _accurate_, capturing the paused Thread's activity.
92
+
93
+ This scheduler heavily relies on Ruby's 1:N Thread model (1 Ruby Threads is strongly tied to a native pthread). It will not work properly in MaNy (`RUBY_MN_THREADS=1`).
94
+
95
+ #### TimerThreadScheduler
96
+
97
+ Another scheduler is the `TimerThreadScheduler`, which maintains a time-keeping thread by itself. A new native thread (pthread on Linux/macOS) will be created, and an infinite loop will be run inside. After `sleep(2)`-ing for the specified interval time, sampling will be queued using Ruby's Postponed Job API.
98
+
99
+ This scheduler is wall-time only, and does not support CPU-time based profiling.
100
+
101
+ Future Plans
102
+ --------
103
+
104
+ - Remove known limitations, if possible
105
+ - Implement a "tracing" scheduler, using the C TracePoint API
106
+ - more
107
+
108
+
109
+ License
110
+ --------
25
111
 
26
112
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,24 @@
1
+ [package]
2
+ name = "pf2"
3
+ version = "0.1.0"
4
+ edition = "2021"
5
+ authors = ["Daisuke Aritomo <osyoyu@osyoyu.com>"]
6
+ publish = false
7
+
8
+ [lib]
9
+ crate-type = ["cdylib"]
10
+
11
+ [dependencies]
12
+ env_logger = { version = "0.11.0", optional = true }
13
+ libc = "0.2.149"
14
+ log = "0.4.20"
15
+ 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
+ serde = "1.0.189"
17
+ serde_derive = "1.0.189"
18
+ serde_json = "1.0.107"
19
+
20
+ [build-dependencies]
21
+ cc = "1.0.83"
22
+
23
+ [features]
24
+ debug = ["env_logger"]
data/ext/pf2/build.rs ADDED
@@ -0,0 +1,3 @@
1
+ fn main() {
2
+ cc::Build::new().file("src/siginfo_t.c").compile("ccode");
3
+ }
data/ext/pf2/extconf.rb CHANGED
@@ -1,5 +1,10 @@
1
1
  require 'mkmf'
2
+ require 'rb_sys/mkmf'
2
3
 
3
4
  abort 'missing rb_profile_thread_frames()' unless have_func 'rb_profile_thread_frames'
4
5
 
5
- create_makefile 'pf2/pf2'
6
+ create_rust_makefile 'pf2/pf2' do |r|
7
+ if ENV['PF2_FEATURES']
8
+ r.features = ENV['PF2_FEATURES'].split(",")
9
+ end
10
+ end
@@ -0,0 +1,14 @@
1
+ extern crate serde;
2
+ #[macro_use]
3
+ extern crate serde_derive;
4
+
5
+ mod ruby_init;
6
+
7
+ mod profile;
8
+ mod profile_serializer;
9
+ mod ringbuffer;
10
+ mod sample;
11
+ #[cfg(target_os = "linux")]
12
+ mod signal_scheduler;
13
+ mod timer_thread_scheduler;
14
+ mod util;