cirron 0.2.9 → 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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6e8d1c23ccd7fd4048aeb66e99872feece2af74b94efb711459cc8eab1b9b97f
4
- data.tar.gz: 78cfa7c9ffcb276bd17360e30796b1158ad015ae09c39d8cef01ca10fca87273
3
+ metadata.gz: a77b46874cc80bc5596a3855ed42263ede1fca9a37c1577ea4f3345bb1790e93
4
+ data.tar.gz: 7448021b56a6fb278c3ed7a098e6a30c09d5347b6d926810c129247b31efdb7c
5
5
  SHA512:
6
- metadata.gz: 285ba864a24717610ba6e0322a55c491a62d22dc6f0c098ec17853a36eb5e6d4b26f33f05c162b8511e1ec7bad8feb229d49f96400f32462b9bbbdabc5897d6c
7
- data.tar.gz: 38de94ae0f78f8751fbfb24f62f2eb9ffeb321345c9ae8eb78c187499af07f2b11b5dd06bfcc6e22b552ceb9bb9a6662a7579bff2b39ecd061f2b8dfbecb442d
6
+ metadata.gz: 4f1a875af0e1d1f29087a8066ed78ac645c33087a3d8ff4cd30bc4c3b9f5edbb20b00f0a7cb0605d2a76fb54851c58dbacc6287ca9b5fa9e1c6c1250937ed5f8
7
+ data.tar.gz: 1c0ad6fd55b08dec530b4ffc4d8e807ebe2499eec5138110a9e0b117efa6db3c209eb106318669e4e9d9abfd3f63ba951963bc2fc0cd44c2a8031ed5ce0e35a6
data/README.md CHANGED
@@ -16,20 +16,19 @@ It can also trace syscalls using +strace+, Linux only!
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.9"
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,32 +1,31 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cirron
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.9
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
16
  on OSX.\n\nIt can also trace syscalls using +strace+, Linux only!\n\n== Prerequisites\n\n
17
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> require 'cirron'\n\n #
19
- Start collecting performance metrics\n irb> counters = Cirron::collector do\n irb>
20
- \ # Your code here\n irb> puts \"Hello\"\n irb> end\n => Counter(time_enabled_ns:
21
- 0, instruction_count: 39066, branch_misses: 546, page_faults: 0)\n\n=== Syscalls\n\n
22
- \ $ sudo irb\n irb> require 'cirron'\n\n irb> trace = Cirron::tracer do\n irb>
23
- \ # Your code here\n irb> puts \"Hello\"\n irb> end\n => [#<Syscall:0x00007c6c1a4b3608
24
- @args=\"1, [{iov_base=\\\"Hello\\\", iov_len=5}, {iov_base=\\\"\\\\n\\\", iov_len=1}],
25
- 2\", @duration=\"0.000201\", @name=\"writev\", @pid=\"2261962\", @retval=\"6\",
26
- @timestamp=\"1720285300.334976\">]\n # Save the trace for ingesting to Perfetto\n
27
- \ irb> File.write(\"/tmp/trace\", Cirron::to_tef(trace))\n => 267\n\n== Additional
28
- Information\n\nFor more detailed information, please visit the project's GitHub
29
- page: https://github.com/s7nfo/Cirron"
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
+ [{iov_base=\\\"Hello\\\", iov_len=5}, {iov_base=\\\"\\\\n\\\", iov_len=1}], 2\",
25
+ @duration=\"0.000201\", @name=\"writev\", @pid=\"2261962\", @retval=\"6\", @timestamp=\"1720285300.334976\">]\n
26
+ \ # Save the trace for ingesting to Perfetto\n irb> File.write(\"/tmp/trace\",
27
+ Cirron::to_tef(trace))\n => 267\n\n== Additional Information\n\nFor more detailed
28
+ information, please visit the project's GitHub page: https://github.com/s7nfo/Cirron"
30
29
  email:
31
30
  - matej.stuchlik@gmail.com
32
31
  executables: []