Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
s7nfo committed Jul 6, 2024
1 parent f46b9f0 commit 9bf8e22
Show file tree
Hide file tree
Showing 5 changed files with 384 additions and 35 deletions.
45 changes: 35 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,61 @@
# Cirron

Cirron measures a piece of Python code and report back several performance counters: CPU instruction count, branch misses, page faults and time spent measuring. It uses the Linux perf events interface or @ibireme's [KPC demo](https://gist.github.com/ibireme/173517c208c7dc333ba962c1f0d67d12) on OSX.
Cirron measures a piece of Python or Ruby code and report back several performance counters: CPU instruction count, branch misses, page faults and time spent measuring. It uses the Linux perf events interface or @ibireme's [KPC demo](https://gist.github.com/ibireme/173517c208c7dc333ba962c1f0d67d12) on OSX.

It can also trace syscalls using `strace`, Linux only!

## Prerequisites

- Linux with perf events support / Apple ARM OSX
- C++
- Python 3.x
- Python 3.x / Ruby 3.x

## Installation

### Python
```bash
pip install cirron
```

The Python wrapper automatically compiles the C++ library (cirronlib.cpp) on first use.
### Ruby
```bash
gem install cirron
```

The wrapper automatically compiles the C++ library (cirronlib.cpp) on first use.

## Usage

### Performance Counters

#### Python

```
$ sudo python
>>> from cirron import Collector
>>>
>>> # Start collecting performance metrics
>>> with Collector() as collector:
>>> # Your code here
>>> # ...
>>>
>>> # Retrieve the metrics
>>> print(collector.counters)
```
from cirron import Collector

# Start collecting performance metrics
with Collector() as collector:
# Your code here
# ...
#### Ruby

# Retrieve the metrics
print(collector.counters)
```
$ sudo irb
irb(main):001> require 'cirron'
=> true
irb(main):002* c = Cirron::collector do
irb(main):003* puts 1
irb(main):004> end
1
=> #<Counter:0x0000000128a53498>
irb(main):005> c[:instruction_count]
=> 0.0
```

### Syscalls
Expand Down
23 changes: 14 additions & 9 deletions ruby/cirron.gemspec
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@

# frozen_string_literal: true

require_relative "lib/cirron/version"
require 'fileutils'
require 'pathname'

Gem::Specification.new do |spec|
spec.name = "cirron"
spec.version = Cirron::VERSION
spec.version = "0.2.1"
spec.authors = ["Matt Stuchlik"]
spec.email = ["[email protected]"]

Expand All @@ -18,13 +19,17 @@ Gem::Specification.new do |spec|
spec.metadata["homepage_uri"] = spec.homepage
spec.metadata["source_code_uri"] = "https://github.com/s7nfo/Cirron"

# Specify which files should be added to the gem when it is released.
# The git ls-files -z loads the files in the RubyGem that have been added into git.
spec.files = Dir.chdir(__dir__) do
git ls-files -z.split("\x0").reject do |f|
(f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
end
end
spec.files = [
"lib/apple_arm_events.h",
"lib/cirron.rb",
"lib/cirronlib.cpp",
"lib/collector.rb",
"lib/tracer.rb",
"README.md",
"LICENSE",
"cirron.gemspec"
]

spec.bindir = "exe"
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]
Expand Down
1 change: 0 additions & 1 deletion ruby/lib/apple_arm_events.h

This file was deleted.

1 change: 0 additions & 1 deletion ruby/lib/cirronlib.cpp

This file was deleted.

Loading

0 comments on commit 9bf8e22

Please sign in to comment.