cirron 0.2.9 → 0.3.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: 6e8d1c23ccd7fd4048aeb66e99872feece2af74b94efb711459cc8eab1b9b97f
4
- data.tar.gz: 78cfa7c9ffcb276bd17360e30796b1158ad015ae09c39d8cef01ca10fca87273
3
+ metadata.gz: 9c007b251356de7d4d30dc444f70ce6440b1df51aca80292e1d4f1f6be1f282f
4
+ data.tar.gz: 168cf0a7b01bf1bf59bcbeba407be5580dfe3f6634f676527284e912eb1e3f8b
5
5
  SHA512:
6
- metadata.gz: 285ba864a24717610ba6e0322a55c491a62d22dc6f0c098ec17853a36eb5e6d4b26f33f05c162b8511e1ec7bad8feb229d49f96400f32462b9bbbdabc5897d6c
7
- data.tar.gz: 38de94ae0f78f8751fbfb24f62f2eb9ffeb321345c9ae8eb78c187499af07f2b11b5dd06bfcc6e22b552ceb9bb9a6662a7579bff2b39ecd061f2b8dfbecb442d
6
+ metadata.gz: 10db47d299a3200ccf6f7e4b7d76825fd1d5433b865b5bdc73f3d0ac1a99198b0b1f2ea340545de3519d087aa42adf4d7dc87cb14bf2e580cdf05e8d3151fc48
7
+ data.tar.gz: 4b4cbf8ffeb1c032cbd329eb7717d5caa878c2919010e227dac5bd06b78e9c81613052e8276bc98569af8bafdc3ca658223e27ee46f825f92812e39684e737cf
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.1"
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/cirronlib.cpp CHANGED
@@ -123,7 +123,7 @@ int start()
123
123
  // load pmc db
124
124
  int ret = 0;
125
125
  kpep_db *db = NULL;
126
- if ((ret = kpep_db_create("a9", &db)))
126
+ if ((ret = kpep_db_create(NULL, &db)))
127
127
  {
128
128
  printf("Error: cannot load pmc database: %d.\n", ret);
129
129
  return 1;
data/lib/collector.rb CHANGED
@@ -46,6 +46,17 @@ class Counter < FFI::Struct
46
46
  end
47
47
 
48
48
  module Cirron
49
+ @overhead = {}
50
+
51
+ def self.calculate_overhead
52
+ 10.times do
53
+ counter = collector(measure_overhead: false) {}
54
+ Counter.members.each do |field|
55
+ @overhead[field] = [@overhead[field], counter[field]].compact.min
56
+ end
57
+ end
58
+ end
59
+
49
60
  def self.start
50
61
  ret_val = CirronInterOp.start
51
62
  if ret_val == -1
@@ -58,13 +69,22 @@ module Cirron
58
69
  CirronInterOp.end(fd, counter)
59
70
  end
60
71
 
61
- def self.collector(&blk)
72
+ def self.collector(measure_overhead: true, &blk)
73
+ calculate_overhead if measure_overhead && @overhead.empty?
74
+
62
75
  counter = Counter.new
63
76
  ret_val = self.start
64
77
 
65
78
  yield
66
79
 
67
80
  self.end(ret_val, counter)
81
+
82
+ if measure_overhead && !@overhead.empty?
83
+ Counter.members.each do |field|
84
+ counter[field] = [counter[field] - @overhead[field], 0].max
85
+ end
86
+ end
87
+
68
88
  counter
69
89
  end
70
90
  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.1
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-09 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: []