Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
142 additions
and
1 deletion.
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
PATH | ||
remote: . | ||
specs: | ||
rbbcc (0.1.1) | ||
rbbcc (0.2.0) | ||
|
||
GEM | ||
remote: https://rubygems.org/ | ||
|
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,10 @@ | ||
# frozen_string_literal: true | ||
|
||
source "https://rubygems.org" | ||
|
||
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } | ||
|
||
gem "rbbcc", path: '../../' | ||
gem "charty", path: '/usr/local/ghq/github.com/udzura/charty' | ||
gem "unicode_plot" | ||
gem "numo" |
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,44 @@ | ||
PATH | ||
remote: ../.. | ||
specs: | ||
rbbcc (0.2.0) | ||
|
||
PATH | ||
remote: /usr/local/ghq/github.com/udzura/charty | ||
specs: | ||
charty (0.2.2) | ||
red-colors | ||
|
||
GEM | ||
remote: https://rubygems.org/ | ||
specs: | ||
enumerable-statistics (2.0.1) | ||
numo (0.1.1) | ||
numo-fftw (~> 0.1.1) | ||
numo-gnuplot (~> 0.2.4) | ||
numo-gsl (~> 0.1.1) | ||
numo-linalg (~> 0.1.0) | ||
numo-narray (~> 0.9.1) | ||
numo-fftw (0.1.1) | ||
numo-narray (~> 0.9.0) | ||
numo-gnuplot (0.2.4) | ||
numo-gsl (0.1.2) | ||
numo-narray (>= 0.9.0.8) | ||
numo-linalg (0.1.5) | ||
numo-narray (>= 0.9.1.4) | ||
numo-narray (0.9.1.6) | ||
red-colors (0.1.1) | ||
unicode_plot (0.0.4) | ||
enumerable-statistics (>= 2.0.1) | ||
|
||
PLATFORMS | ||
ruby | ||
|
||
DEPENDENCIES | ||
charty! | ||
numo | ||
rbbcc! | ||
unicode_plot | ||
|
||
BUNDLED WITH | ||
2.0.2 |
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,87 @@ | ||
#!/usr/bin/env ruby | ||
# | ||
# bitehist.rb, ported from bitehist.py. See license on that file | ||
# | ||
# Written as a basic example of using histograms to show a distribution. | ||
# | ||
# A Ctrl-C will print the gathered histogram then exit. | ||
# | ||
|
||
require 'rbbcc' | ||
include RbBCC | ||
|
||
b = BCC.new(text: <<CLANG) | ||
#include <uapi/linux/ptrace.h> | ||
#include <linux/blkdev.h> | ||
BPF_HISTOGRAM(dist); | ||
BPF_HISTOGRAM(dist_linear); | ||
int kprobe__blk_account_io_completion(struct pt_regs *ctx, struct request *req) | ||
{ | ||
dist.increment(bpf_log2l(req->__data_len / 1024)); | ||
dist_linear.increment(req->__data_len / 1024); | ||
return 0; | ||
} | ||
CLANG | ||
|
||
puts "Tracing... Hit Ctrl-C to end." | ||
|
||
loop do | ||
begin | ||
sleep 0.1 | ||
rescue Interrupt | ||
puts | ||
break | ||
end | ||
end | ||
|
||
require 'unicode_plot' | ||
def log2hist_unicode(table) | ||
strip_leading_zero = true | ||
vals = Array.new($log2_index_max) { 0 } | ||
data = {} | ||
table.each_pair do |k, v| | ||
vals[k.to_bcc_value] = v.to_bcc_value | ||
end | ||
|
||
log2_dist_max = 64 | ||
idx_max = -1 | ||
val_max = 0 | ||
|
||
vals.each_with_index do |v, i| | ||
idx_max = i if v > 0 | ||
val_max = v if v > val_max | ||
end | ||
|
||
(1...(idx_max + 1)).each do |i| | ||
low = (1 << i) >> 1 | ||
high = (1 << i) | ||
if (low == high) | ||
low -= 1 | ||
end | ||
val = vals[i] | ||
|
||
if strip_leading_zero | ||
if val | ||
data["[#{low}, #{high})"] = val | ||
strip_leading_zero = false | ||
end | ||
else | ||
data["[#{low}, #{high})"] = val | ||
end | ||
end | ||
|
||
unless data.empty? | ||
puts UnicodePlot.barplot(data: data, title: "log2 histogram").render | ||
else | ||
puts "No sample found." | ||
end | ||
end | ||
|
||
log2hist_unicode b["dist"] | ||
|
||
# puts | ||
# puts "linear histogram" | ||
# puts "~~~~~~~~~~~~~~~~" | ||
# b["dist_linear"].print_linear_hist("kbytes") |