straces 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 7622196d114cb354c8c936e5970a5fb5cc712f9266707a2933441176a0bcb13a
4
+ data.tar.gz: e871e0c71d7efb4554fe085370280a64a0eda59403fbf813d0d934bd48828f56
5
+ SHA512:
6
+ metadata.gz: 0ec86d4745ac99a80eb466c5f90a5c14a082319c0d5f7deeb137be980739b814b5e1fff66e6b5142656e341597ad77d24c60cb344c3266ae75b3934eff211abf
7
+ data.tar.gz: d097a7457d6758c4b11adaf2be77a52b6d436d9f323569f0357be2ec4f03f65389f22b941391de7e4f5a4c02d69d0e07c195bea75e3033153c3753cfdd55ddeb
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ straces
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.6.4
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.3
7
+ before_install: gem install bundler -v 1.17.3
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in straces.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,35 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ straces (0.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.3)
10
+ rake (10.5.0)
11
+ rspec (3.8.0)
12
+ rspec-core (~> 3.8.0)
13
+ rspec-expectations (~> 3.8.0)
14
+ rspec-mocks (~> 3.8.0)
15
+ rspec-core (3.8.2)
16
+ rspec-support (~> 3.8.0)
17
+ rspec-expectations (3.8.4)
18
+ diff-lcs (>= 1.2.0, < 2.0)
19
+ rspec-support (~> 3.8.0)
20
+ rspec-mocks (3.8.1)
21
+ diff-lcs (>= 1.2.0, < 2.0)
22
+ rspec-support (~> 3.8.0)
23
+ rspec-support (3.8.2)
24
+
25
+ PLATFORMS
26
+ ruby
27
+
28
+ DEPENDENCIES
29
+ bundler (~> 1.17)
30
+ rake (~> 10.0)
31
+ rspec (~> 3.0)
32
+ straces!
33
+
34
+ BUNDLED WITH
35
+ 1.17.3
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Matti Paksula
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # Straces
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/straces`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'straces'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install straces
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/straces.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "straces"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/exe/straces ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ # add lib to libpath (only needed when running from the sources)
5
+ require 'pathname'
6
+ lib_path = File.expand_path('../../lib', Pathname.new(__FILE__).realpath)
7
+ $LOAD_PATH.unshift lib_path unless $LOAD_PATH.include?(lib_path)
8
+
9
+ STDOUT.sync = true
10
+
11
+ require 'straces'
data/lib/straces.rb ADDED
@@ -0,0 +1,142 @@
1
+ unless ARGV[0]
2
+ puts "USAGE: [STRACES_IGNORE=accept4,gettimeofday] [STRACES_FOCUS=sendto,recvfrom] straces dump [gt|ge|lt|le|eq=value] [lines_before] [lines_after]"
3
+ exit 1
4
+ end
5
+
6
+ contents = File.read ARGV[0]
7
+ filter = ARGV[1]
8
+ lines_before = Float ARGV[2] rescue 1
9
+ lines_after = Float ARGV[3] rescue 1
10
+ syscalls_ignored = ENV['STRACES_IGNORE']&.split(",") || []
11
+ syscalls_focused = ENV['STRACES_FOCUS']&.split(",") || []
12
+
13
+ class String
14
+ def black; "\e[30m#{self}\e[0m" end
15
+ def red; "\e[31m#{self}\e[0m" end
16
+ def green; "\e[32m#{self}\e[0m" end
17
+ def brown; "\e[33m#{self}\e[0m" end
18
+ def blue; "\e[34m#{self}\e[0m" end
19
+ def magenta; "\e[35m#{self}\e[0m" end
20
+ def cyan; "\e[36m#{self}\e[0m" end
21
+ def gray; "\e[37m#{self}\e[0m" end
22
+
23
+ def bg_black; "\e[40m#{self}\e[0m" end
24
+ def bg_red; "\e[41m#{self}\e[0m" end
25
+ def bg_green; "\e[42m#{self}\e[0m" end
26
+ def bg_brown; "\e[43m#{self}\e[0m" end
27
+ def bg_blue; "\e[44m#{self}\e[0m" end
28
+ def bg_magenta; "\e[45m#{self}\e[0m" end
29
+ def bg_cyan; "\e[46m#{self}\e[0m" end
30
+ def bg_gray; "\e[47m#{self}\e[0m" end
31
+
32
+ def bold; "\e[1m#{self}\e[22m" end
33
+ def italic; "\e[3m#{self}\e[23m" end
34
+ def underline; "\e[4m#{self}\e[24m" end
35
+ def blink; "\e[5m#{self}\e[25m" end
36
+ def reverse_color; "\e[7m#{self}\e[27m" end
37
+ end
38
+
39
+
40
+ def strace_parse(line)
41
+ matcher = line.match /^(?<time>\d\d:\d\d:\d\d\.?\d*)?\s?(?<pid>\d*)\s?(?<call>[^\(]+)(?<middle>.*)\<(?<timing>\d+\.\d+)\>$/
42
+
43
+ # <detached ..>
44
+ timing = Float matcher[:timing] rescue 0.0
45
+
46
+ if matcher
47
+ {
48
+ pid: matcher[:pid],
49
+ call: matcher[:call],
50
+ middle: matcher[:middle],
51
+ timing: timing
52
+ }
53
+ else
54
+ nil
55
+ end
56
+ end
57
+
58
+ def process(lines, syscalls_ignored, syscalls_focused)
59
+ last_obj = {
60
+ time: 0.0
61
+ }
62
+
63
+ objs = lines.map do |line|
64
+ obj = strace_parse(line)
65
+ next unless obj
66
+
67
+ if syscalls_focused.length > 0
68
+ next unless syscalls_focused.include? obj[:call]
69
+ end
70
+ next if syscalls_ignored.include? obj[:call]
71
+
72
+ obj[:time] = obj[:timing] + last_obj[:time]
73
+ last_obj = obj
74
+ obj
75
+ end
76
+ objs.compact
77
+ end
78
+
79
+ def format(obj)
80
+ [
81
+ obj[:time].round(4).to_s.ljust(6, "0"),
82
+ obj[:timing].round(6).to_s.ljust(8, "0"),
83
+ obj[:call].ljust(16),
84
+ obj[:middle],
85
+ ].join(" ")
86
+ end
87
+
88
+ objs = process(contents.split("\n"), syscalls_ignored, syscalls_focused)
89
+ min = (objs.min_by {|e| e[:timing] })[:timing]
90
+ max = (objs.max_by {|e| e[:timing] })[:timing]
91
+ range = max - min
92
+
93
+ objs.each do |obj|
94
+ obj[:normalized] = (
95
+ (obj[:timing] - min) * 100 / range
96
+ ).round(0)
97
+ end
98
+
99
+ objs.each_with_index do |obj, i|
100
+ #p [obj[:time], obj[:timing], obj[:normalized]]
101
+
102
+ unless filter
103
+ puts [
104
+
105
+ obj[:time].round(4).to_s.ljust(6, "0"),
106
+ obj[:timing].round(6).to_s.ljust(8, "0"),
107
+ obj[:call].ljust(16),
108
+ "#"*(obj[:normalized] == 0 ? 1 : obj[:normalized])
109
+ ].join " "
110
+ else
111
+ matches = filter.match /^(?<comparator>gt|lt|ge|le|eq)=(?<value>\d+\.?\d*)$/
112
+ comparator = matches && matches[:comparator]
113
+ value = Float matches[:value] rescue nil
114
+ if comparator.nil? || value.nil?
115
+ puts "invalid filter #{filter}"
116
+ exit 1
117
+ end
118
+
119
+ ruby_comparator = case comparator
120
+ when "gt"
121
+ :>
122
+ when "ge"
123
+ :>=
124
+ when "lt"
125
+ :<
126
+ when "lte"
127
+ :<=
128
+ when "eq"
129
+ :==
130
+ end
131
+
132
+ if obj[:timing].send(ruby_comparator, value)
133
+ terminal_width=Integer `tput cols`
134
+ puts "-"*terminal_width
135
+ puts objs[i-lines_before..i-1].map {|o| format(o)}
136
+ puts format(objs[i]).red
137
+ puts objs[i+1..i+lines_after].map {|o| format(o)}
138
+
139
+ puts ""
140
+ end
141
+ end
142
+ end
data/straces.gemspec ADDED
@@ -0,0 +1,28 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "straces"
7
+ spec.version = "0.0.1"
8
+ spec.authors = ["Matti Paksula"]
9
+ spec.email = ["matti.paksula@iki.fi"]
10
+
11
+ spec.summary = "straces"
12
+ spec.description = "straces"
13
+ spec.homepage = "https://github.com/matti/straces"
14
+ spec.license = "MIT"
15
+
16
+ # Specify which files should be added to the gem when it is released.
17
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
18
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
19
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ end
21
+ spec.bindir = "exe"
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.17"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "rspec", "~> 3.0"
28
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: straces
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Matti Paksula
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-09-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.17'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.17'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: straces
56
+ email:
57
+ - matti.paksula@iki.fi
58
+ executables:
59
+ - straces
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - ".rspec"
65
+ - ".ruby-gemset"
66
+ - ".ruby-version"
67
+ - ".travis.yml"
68
+ - Gemfile
69
+ - Gemfile.lock
70
+ - LICENSE.txt
71
+ - README.md
72
+ - Rakefile
73
+ - bin/console
74
+ - bin/setup
75
+ - exe/straces
76
+ - lib/straces.rb
77
+ - straces.gemspec
78
+ homepage: https://github.com/matti/straces
79
+ licenses:
80
+ - MIT
81
+ metadata: {}
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubygems_version: 3.0.6
98
+ signing_key:
99
+ specification_version: 4
100
+ summary: straces
101
+ test_files: []