-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Donald Lee <[email protected]>
- Loading branch information
Showing
18 changed files
with
667 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
name: CI | ||
|
||
on: | ||
pull_request: | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: '3.11' | ||
|
||
- name: Set up Ruby | ||
uses: ruby/setup-ruby@v1 | ||
with: | ||
ruby-version: '3.3' | ||
|
||
- name: Run tests | ||
run: make test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
*.so | ||
|
||
*.egg | ||
*.egg-info/ | ||
dist/ | ||
build/ | ||
*.pyd | ||
|
||
.DS_Store | ||
Gemfile.lock | ||
|
||
python/cirron/cirronlib.cpp | ||
python/cirron/apple_arm_events.h | ||
ruby/lib/cirronlib.cpp | ||
ruby/lib/apple_arm_events.h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
SOURCES = src/cirronlib.cpp src/apple_arm_events.h | ||
PYTHON_DIR = python/cirron | ||
RUBY_DIR = ruby/lib | ||
|
||
.PHONY: test build build-python build-ruby copy-sources | ||
|
||
test: test-python test-ruby | ||
|
||
copy-sources: | ||
cp $(SOURCES) $(PYTHON_DIR)/ | ||
cp $(SOURCES) $(RUBY_DIR)/ | ||
|
||
.PHONY: test-python | ||
test-python: copy-sources | ||
rm -f $(PYTHON_DIR)/cirronlib.so | ||
@echo "Running Python tests..." | ||
sudo PYTHONPATH=./python python -m unittest discover -s python/tests | ||
|
||
.PHONY: test-ruby | ||
test-ruby: copy-sources | ||
rm -f $(RUBY_DIR)/cirronlib.so | ||
@echo "Running Ruby tests..." | ||
cd ruby && \ | ||
sudo gem install bundler && \ | ||
sudo bundle install && \ | ||
sudo bundle exec ruby -Ilib:test tests/tests.rb | ||
|
||
build: build-python build-ruby | ||
|
||
.PHONY: build-python | ||
build-python: copy-sources | ||
@echo "Building Python package..." | ||
cd python && python setup.py sdist bdist_wheel | ||
|
||
.PHONY: build-ruby | ||
build-ruby: copy-sources | ||
@echo "Building Ruby package..." | ||
cd ruby && gem build cirron.gemspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,95 @@ | ||
# 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 | ||
>>> print("Hello") | ||
>>> | ||
>>> # Retrieve the metrics | ||
>>> print(collector.counters) | ||
Counter(time_enabled_ns=144185, instruction_count=19434, branch_misses=440, page_faults=0) | ||
``` | ||
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 "Hello" | ||
irb(main):004> end | ||
Hello | ||
=> Counter(time_enabled_ns: 110260, instruction_count: 15406, branch_misses: 525, page_faults: 0) | ||
``` | ||
|
||
### Syscalls | ||
``` | ||
from cirron import Tracer, to_tef | ||
|
||
with Tracer() as tracer: | ||
# Your code here | ||
# ... | ||
#### Python | ||
|
||
# Stop collecting and retrieve the trace | ||
print(tracer.trace) | ||
``` | ||
$ sudo python | ||
>>> from cirron import Tracer, to_tef | ||
# Save the trace for ingesting to Perfetto | ||
open("/tmp/trace", "w").write(to_tef(trace)) | ||
>>> with Tracer() as tracer: | ||
>>> # Your code here | ||
>>> print("Hello") | ||
>>> | ||
>>> # Retrieve the trace | ||
>>> print(tracer.trace) | ||
>>> [Syscall(name='write', args='1, "Hello\\n", 6', retval='6', duration='0.000043', timestamp='1720333364.368337', pid='2270837')] | ||
>>> | ||
>>> # Save the trace for ingesting to Perfetto | ||
>>> open("/tmp/trace", "w").write(to_tef(tracer.trace)) | ||
``` | ||
#### Ruby | ||
|
||
``` | ||
$ sudo irb | ||
irb> require 'cirron' | ||
=> true | ||
irb> trace = Cirron::tracer do | ||
irb> # Your code here | ||
irb> puts "Hello" | ||
irb> end | ||
=> [#<Syscall:0x00007c6c1a4b3608 @args="1, [{iov_base=\"Hello\", iov_len=5}, {iov_base=\"\\n\", iov_len=1}], 2", @duration="0.000201", @name="writev", @pid="2261962", @retval="6", @timestamp="1720285300.334976">] | ||
# Save the trace for ingesting to Perfetto | ||
irb> File.write("/tmp/trace", Cirron::to_tef(trace)) | ||
=> 267 | ||
``` |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.