sperf 0.2.0 → 0.2.1

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: a2d6adf217328a161001097ef85fd62f9716a70089c254f6a831f2d8135d7a52
4
- data.tar.gz: 92b0aefb1cd263fb86c84553b76cbf1f3124eff5c24e2ceb7d8e15e36f7d5012
3
+ metadata.gz: 125090cb17cacbc9157402fcb9db54117011ccde812da775ea00b6c1f6bee535
4
+ data.tar.gz: 1430d997988a6538059a0c63be28d4f05f43681d1f2efbd84020490308a5c279
5
5
  SHA512:
6
- metadata.gz: ee0ba192454f4794b1f9c064ea743978dde3f8eb5588c2ed590b0cb90604e26aa373223e4d7eaf3b8f3ed56b7a8564a79aef7cc40b9fd806b528ac8482a22dc2
7
- data.tar.gz: e3519944bab031f83418893bdbf122ab0e308f1d72246dfca5315128365749c085fa3e1aa99f1fb75edd6d2fd2e7c3014fc86c996348420f69b32c80fb1a4b22
6
+ metadata.gz: 17a52cfc856ae47f254bf0df3450ff76cd471703c97e029907abbf639aa9dd8d6971ef8b18acf6a9784b87b295981533776c147b0fc31993e33dcf528cf15a3d
7
+ data.tar.gz: 6bbad7152c998859f4ec1f07d42eeca8824918ad635b0454fbe13635d9b913ad309b09f8e7c760f5cdd4cc1d32d1316ba50a5fb7c1863e7718cb1df01a2761ad
data/README.md CHANGED
@@ -9,6 +9,7 @@ A safepoint-based sampling performance profiler for Ruby. Uses actual time delta
9
9
  - Requires Ruby >= 3.4.0
10
10
  - Output: pprof protobuf, collapsed stacks, or text report
11
11
  - Modes: CPU time (per-thread) and wall time (with GVL/GC tracking)
12
+ - [Online manual](https://ko1.github.io/sperf/docs/manual/) | [GitHub](https://github.com/ko1/sperf)
12
13
 
13
14
  ## Quick Start
14
15
 
@@ -56,7 +57,7 @@ Profile without code changes (e.g., Rails):
56
57
  SPERF_ENABLED=1 SPERF_MODE=wall SPERF_OUTPUT=profile.pb.gz ruby app.rb
57
58
  ```
58
59
 
59
- Run `sperf help` for full documentation (all options, output interpretation, diagnostics guide).
60
+ Run `sperf help` for full documentation, or see the [online manual](https://ko1.github.io/sperf/).
60
61
 
61
62
  ## Subcommands
62
63
 
data/exe/sperf CHANGED
@@ -1,5 +1,13 @@
1
1
  #!/usr/bin/env ruby
2
2
  require "optparse"
3
+ require "socket"
4
+
5
+ def find_available_port
6
+ server = TCPServer.new("localhost", 0)
7
+ port = server.addr[1]
8
+ server.close
9
+ port
10
+ end
3
11
 
4
12
  HELP_TEXT = <<'HELP'
5
13
  sperf - safepoint-based sampling performance profiler for Ruby
@@ -22,12 +30,16 @@ CLI USAGE
22
30
  -f, --frequency HZ Sampling frequency in Hz (default: 1000)
23
31
  -m, --mode MODE cpu or wall (default: cpu)
24
32
  --format FORMAT pprof, collapsed, or text (default: auto from extension)
33
+ --signal VALUE Timer signal (Linux only): signal number, or 'false'
34
+ for nanosleep thread (default: auto)
25
35
  -v, --verbose Print sampling statistics to stderr
26
36
 
27
37
  stat: Run command and print performance summary to stderr.
28
38
  Always uses wall mode. No file output by default.
29
39
  -o, --output PATH Also save profile to file (default: none)
30
40
  -f, --frequency HZ Sampling frequency in Hz (default: 1000)
41
+ --signal VALUE Timer signal (Linux only): signal number, or 'false'
42
+ for nanosleep thread (default: auto)
31
43
  -v, --verbose Print additional sampling statistics
32
44
 
33
45
  Shows: user/sys/real time, time breakdown (CPU execution, GVL blocked,
@@ -230,6 +242,7 @@ ENVIRONMENT VARIABLES
230
242
  SPERF_MODE=cpu|wall Profiling mode
231
243
  SPERF_FORMAT=fmt pprof, collapsed, or text
232
244
  SPERF_VERBOSE=1 Print statistics
245
+ SPERF_SIGNAL=N|false Timer signal number or 'false' for nanosleep (Linux only)
233
246
 
234
247
  TIPS
235
248
 
@@ -316,7 +329,7 @@ when "report"
316
329
  when :text
317
330
  exec("go", "tool", "pprof", "-text", report_file)
318
331
  else
319
- exec("go", "tool", "pprof", "-http=:0", report_file)
332
+ exec("go", "tool", "pprof", "-http=localhost:#{find_available_port}", report_file)
320
333
  end
321
334
  when "diff"
322
335
  # sperf diff: compare two pprof profiles via go tool pprof -diff_base
@@ -374,7 +387,7 @@ when "diff"
374
387
  when :text
375
388
  exec("go", "tool", "pprof", "-text", "-diff_base=#{base_file}", target_file)
376
389
  else
377
- exec("go", "tool", "pprof", "-http=:0", "-diff_base=#{base_file}", target_file)
390
+ exec("go", "tool", "pprof", "-http=localhost:#{find_available_port}", "-diff_base=#{base_file}", target_file)
378
391
  end
379
392
  when "record", "stat"
380
393
  # continue below
@@ -388,6 +401,7 @@ output = (subcommand == "stat") ? nil : "sperf.data"
388
401
  frequency = 1000
389
402
  mode = (subcommand == "stat") ? "wall" : "cpu"
390
403
  format = nil
404
+ signal = nil
391
405
  verbose = false
392
406
 
393
407
  parser = OptionParser.new do |opts|
@@ -412,6 +426,10 @@ parser = OptionParser.new do |opts|
412
426
  end
413
427
  end
414
428
 
429
+ opts.on("--signal VALUE", "Timer signal (Linux only): signal number, or 'false' for nanosleep thread") do |v|
430
+ signal = (v == "false") ? "false" : v
431
+ end
432
+
415
433
  opts.on("-v", "--verbose", "Print sampling statistics to stderr") do
416
434
  verbose = true
417
435
  end
@@ -448,6 +466,7 @@ ENV["SPERF_FREQUENCY"] = frequency.to_s
448
466
  ENV["SPERF_MODE"] = mode
449
467
  ENV["SPERF_FORMAT"] = format if format
450
468
  ENV["SPERF_VERBOSE"] = "1" if verbose
469
+ ENV["SPERF_SIGNAL"] = signal if signal
451
470
 
452
471
  if subcommand == "stat"
453
472
  ENV["SPERF_STAT"] = "1"
data/lib/sperf/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Sperf
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
data/lib/sperf.rb CHANGED
@@ -359,11 +359,18 @@ module Sperf
359
359
  _sperf_mode = _sperf_mode_str == "wall" ? :wall : :cpu
360
360
  _sperf_format = ENV["SPERF_FORMAT"] ? ENV["SPERF_FORMAT"].to_sym : nil
361
361
  _sperf_stat = ENV["SPERF_STAT"] == "1"
362
- start(frequency: (ENV["SPERF_FREQUENCY"] || 1000).to_i, mode: _sperf_mode,
363
- output: _sperf_stat ? ENV["SPERF_OUTPUT"] : (ENV["SPERF_OUTPUT"] || "sperf.data"),
364
- verbose: ENV["SPERF_VERBOSE"] == "1",
365
- format: _sperf_format,
366
- stat: _sperf_stat)
362
+ _sperf_signal = case ENV["SPERF_SIGNAL"]
363
+ when nil then nil
364
+ when "false" then false
365
+ else ENV["SPERF_SIGNAL"].to_i
366
+ end
367
+ _sperf_start_opts = { frequency: (ENV["SPERF_FREQUENCY"] || 1000).to_i, mode: _sperf_mode,
368
+ output: _sperf_stat ? ENV["SPERF_OUTPUT"] : (ENV["SPERF_OUTPUT"] || "sperf.data"),
369
+ verbose: ENV["SPERF_VERBOSE"] == "1",
370
+ format: _sperf_format,
371
+ stat: _sperf_stat }
372
+ _sperf_start_opts[:signal] = _sperf_signal unless _sperf_signal.nil?
373
+ start(**_sperf_start_opts)
367
374
  at_exit { stop }
368
375
  end
369
376
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sperf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Koichi Sasada