cirron 0.2.8 → 0.3

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 (6) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +11 -12
  3. data/cirron.gemspec +1 -7
  4. data/lib/collector.rb +23 -1
  5. data/lib/tracer.rb +2 -2
  6. metadata +10 -10
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '031948c5f88eb541e318a992ec6c99d534f703a2e372082c6b07ed2b4e7783f2'
4
- data.tar.gz: 79ad0542a7e65819008b65e053250d073b5c87a8f4923c1ae8a64fdd2f15cf10
3
+ metadata.gz: a77b46874cc80bc5596a3855ed42263ede1fca9a37c1577ea4f3345bb1790e93
4
+ data.tar.gz: 7448021b56a6fb278c3ed7a098e6a30c09d5347b6d926810c129247b31efdb7c
5
5
  SHA512:
6
- metadata.gz: d0a263836ee39db7e6723aeb78a71da0d4bdc6536d9a79463a2dd312c3fa0ff3737f233d7c4e8b9a2c26957678565e4eebc400e827f206088c5c87d28e7ba1f4
7
- data.tar.gz: d081b2b307ed89ddf06735be9c547383ea42de2129a365d910f72b19b298373a4cb94ad011cee20e7d5db793436067d0a9e1cdc42947c00e380455f598444e69
6
+ metadata.gz: 4f1a875af0e1d1f29087a8066ed78ac645c33087a3d8ff4cd30bc4c3b9f5edbb20b00f0a7cb0605d2a76fb54851c58dbacc6287ca9b5fa9e1c6c1250937ed5f8
7
+ data.tar.gz: 1c0ad6fd55b08dec530b4ffc4d8e807ebe2499eec5138110a9e0b117efa6db3c209eb106318669e4e9d9abfd3f63ba951963bc2fc0cd44c2a8031ed5ce0e35a6
data/README.md CHANGED
@@ -8,28 +8,27 @@ It can also trace syscalls using +strace+, Linux only!
8
8
 
9
9
  == Prerequisites
10
10
 
11
- - Linux with perf events support / Apple ARM OSX
12
- - C++
13
- - Ruby 3.x
11
+ - Linux with perf events support / Apple ARM OSX
12
+ - C++
13
+ - Ruby 3.x
14
14
 
15
15
  == Usage
16
16
 
17
17
  === Performance Counters
18
18
  $ sudo irb
19
- irb> require 'cirron'
20
-
21
- # Start collecting performance metrics
22
- irb> counters = Cirron::collector do
23
- irb> # Your code here
24
- irb> puts "Hello"
25
- irb> end
26
- => Counter(time_enabled_ns: 0, instruction_count: 39066, branch_misses: 546, page_faults: 0)
19
+ irb(main):001> require 'cirron'
20
+ => true
21
+ irb(main):002* c = Cirron::collector do
22
+ irb(main):003* puts "Hello"
23
+ irb(main):004> end
24
+ Hello
25
+ => Counter(time_enabled_ns: 110260, instruction_count: 15406, branch_misses: 525, page_faults: 0)
27
26
 
28
27
  === Syscalls
29
28
 
30
29
  $ sudo irb
31
30
  irb> require 'cirron'
32
-
31
+ => true
33
32
  irb> trace = Cirron::tracer do
34
33
  irb> # Your code here
35
34
  irb> puts "Hello"
data/cirron.gemspec CHANGED
@@ -6,7 +6,7 @@ require 'pathname'
6
6
 
7
7
  Gem::Specification.new do |spec|
8
8
  spec.name = "cirron"
9
- spec.version = "0.2.8"
9
+ spec.version = "0.3"
10
10
  spec.authors = ["Matt Stuchlik"]
11
11
  spec.email = ["matej.stuchlik@gmail.com"]
12
12
 
@@ -33,10 +33,4 @@ Gem::Specification.new do |spec|
33
33
  spec.bindir = "exe"
34
34
  spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
35
35
  spec.require_paths = ["lib"]
36
-
37
- # Uncomment to register a new dependency of your gem
38
- # spec.add_dependency "example-gem", "~> 1.0"
39
-
40
- # For more information and examples about making a new gem, check out our
41
- # guide at: https://bundler.io/guides/creating_gem.html
42
36
  end
data/lib/collector.rb CHANGED
@@ -46,6 +46,19 @@ class Counter < FFI::Struct
46
46
  end
47
47
 
48
48
  module Cirron
49
+ @overhead = {}
50
+
51
+ def self.calculate_overhead
52
+ puts "Measuring overhead..."
53
+ 10.times do
54
+ counter = collector(measure_overhead: false) {}
55
+ Counter.members.each do |field|
56
+ @overhead[field] = [@overhead[field], counter[field]].compact.min
57
+ end
58
+ end
59
+ puts @overhead
60
+ end
61
+
49
62
  def self.start
50
63
  ret_val = CirronInterOp.start
51
64
  if ret_val == -1
@@ -58,13 +71,22 @@ module Cirron
58
71
  CirronInterOp.end(fd, counter)
59
72
  end
60
73
 
61
- def self.collector(&blk)
74
+ def self.collector(measure_overhead: true, &blk)
75
+ calculate_overhead if measure_overhead && @overhead.empty?
76
+
62
77
  counter = Counter.new
63
78
  ret_val = self.start
64
79
 
65
80
  yield
66
81
 
67
82
  self.end(ret_val, counter)
83
+
84
+ if measure_overhead && !@overhead.empty?
85
+ Counter.members.each do |field|
86
+ counter[field] = [counter[field] - @overhead[field], 0].max
87
+ end
88
+ end
89
+
68
90
  counter
69
91
  end
70
92
  end
data/lib/tracer.rb CHANGED
@@ -73,8 +73,8 @@ def parse_strace(file)
73
73
  end
74
74
 
75
75
  def filter_trace(trace, marker_path)
76
- start_index = trace.index { |event| event.args.include?(marker_path) }
77
- end_index = trace.rindex { |event| event.args.include?(marker_path) }
76
+ start_index = trace.index { |event| event.is_a?(Syscall) && event.args.include?(marker_path) }
77
+ end_index = trace.rindex { |event| event.is_a?(Syscall) && event.args.include?(marker_path) }
78
78
 
79
79
  if start_index && end_index
80
80
  trace[start_index + 1...end_index]
metadata CHANGED
@@ -1,26 +1,26 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cirron
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.8
4
+ version: '0.3'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Stuchlik
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-07-06 00:00:00.000000000 Z
11
+ date: 2024-07-07 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: "= Cirron\n\nCirron measures a piece of Ruby code and reports back several
14
14
  performance counters: \nCPU instruction count, branch misses, page faults and time
15
15
  spent measuring. \nIt uses the Linux perf events interface or @ibireme's KPC demo[https://gist.github.com/ibireme/173517c208c7dc333ba962c1f0d67d12]
16
- on OSX.\n\nIt can also trace syscalls using +strace+, Linux only!\n\n== Prerequisites\n\n-
17
- Linux with perf events support / Apple ARM OSX\n- C++\n- Ruby 3.x\n\n== Usage\n\n===
18
- Performance Counters\n $ sudo irb\n irb> require 'cirron'\n\n # Start collecting
19
- performance metrics\n irb> counters = Cirron::collector do\n irb> # Your code
20
- here\n irb> puts \"Hello\"\n irb> end\n => Counter(time_enabled_ns: 0, instruction_count:
21
- 39066, branch_misses: 546, page_faults: 0)\n\n=== Syscalls\n\n $ sudo irb\n irb>
22
- require 'cirron'\n\n irb> trace = Cirron::tracer do\n irb> # Your code here\n
23
- \ irb> puts \"Hello\"\n irb> end\n => [#<Syscall:0x00007c6c1a4b3608 @args=\"1,
16
+ on OSX.\n\nIt can also trace syscalls using +strace+, Linux only!\n\n== Prerequisites\n\n
17
+ \ - Linux with perf events support / Apple ARM OSX\n - C++\n - Ruby 3.x\n\n==
18
+ Usage\n\n=== Performance Counters\n $ sudo irb\n irb(main):001> require 'cirron'\n
19
+ \ => true\n irb(main):002* c = Cirron::collector do\n irb(main):003* puts \"Hello\"\n
20
+ \ irb(main):004> end\n Hello\n => Counter(time_enabled_ns: 110260, instruction_count:
21
+ 15406, branch_misses: 525, page_faults: 0)\n\n=== Syscalls\n\n $ sudo irb\n irb>
22
+ require 'cirron'\n => true\n irb> trace = Cirron::tracer do\n irb> # Your code
23
+ here\n irb> puts \"Hello\"\n irb> end\n => [#<Syscall:0x00007c6c1a4b3608 @args=\"1,
24
24
  [{iov_base=\\\"Hello\\\", iov_len=5}, {iov_base=\\\"\\\\n\\\", iov_len=1}], 2\",
25
25
  @duration=\"0.000201\", @name=\"writev\", @pid=\"2261962\", @retval=\"6\", @timestamp=\"1720285300.334976\">]\n
26
26
  \ # Save the trace for ingesting to Perfetto\n irb> File.write(\"/tmp/trace\",