vernier 0.1.1 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9d826cc1605b081bf6784ff46e1e49b09958f3c2626637d3d994b967bc52b391
4
- data.tar.gz: 743a02e32629c961795ab0a4b62f839e5bf905e3a4f339f6534157cd257f2e7a
3
+ metadata.gz: dcfae18cfffd67e1e8a52c0c9de2654e7523b674d492964dfa3447c967d981e3
4
+ data.tar.gz: 4ff2a81a37d19f974914a0ff3fa28937302a636721b8732f7e7b282f895db9f3
5
5
  SHA512:
6
- metadata.gz: ac4dc6ea1e3f9c32ba223e96aa7eae35c62f4a4e3d503efdee643b44984f5d03638b42a4d2e25fe991e8bc49240f75541da0c0791b525782f827969f1926d50c
7
- data.tar.gz: 4321e93946c0c2155f79326f9bf29f00bf0fab24785c1c7238b8fdf46570706d8906bf70e80241a7dadd1d1531f8c44e12b4b47584b6024cf7d47fa9fa0a432d
6
+ metadata.gz: bd4e4f001047bb3f20c9c0670339747b9e29abf6e44bcd77dbb38fcf7c16f42d33eef893045ab7a899b155d9b98765950e91af79864234a2d66243490d367d49
7
+ data.tar.gz: 14cecc8aa1058b4e38f130bed6ec1d43e8a59a636c125862ef6c61df13f885e1d76b1a142d0fa8fab16ea6bfee2642b7cd606bb562020f800ce3518b2c7fac2c
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Vernier
2
2
 
3
- Experimental Ruby profiling tool
3
+ Experimental next-generation Ruby profiler.
4
4
 
5
5
  ## Installation
6
6
 
@@ -10,16 +10,23 @@ gem 'vernier'
10
10
 
11
11
  ## Usage
12
12
 
13
- Record a flamegraph of all **retained** allocations from requiring `irb`.
13
+ ### Retained memory
14
+
15
+ Record a flamegraph of all **retained** allocations from loading `irb`.
14
16
 
15
17
  ```
16
- ruby -r vernier -e 'Vernier.trace_retained(out: "irb.stackcollapse") { require "irb" }'
18
+ ruby -r vernier -e 'Vernier.trace_retained(out: "irb_profile.json") { require "irb" }'
17
19
  ```
18
20
 
19
- The output can then be viewed in speedscope or other flamegraph tools
21
+ The output can then be viewed in the [Firefox Profiler (demo)](https://share.firefox.dev/3DhLsFa)
22
+
23
+ ![Screenshot 2023-07-16 at 21-06-19 Ruby_Vernier – 1970-01-01 12 00 00 a m UTC – Firefox Profiler](https://github.com/jhawthorn/vernier/assets/131752/9ca0b593-70fb-4c8b-aed9-cb33e0e0bc06)
20
24
 
21
- <img width="1082" alt="Screen Shot 2022-04-26 at 8 11 19 PM" src="https://user-images.githubusercontent.com/131752/165440422-3a11f5cc-3018-4455-8918-887c2afa6d6e.png">
25
+ ### Time
22
26
 
27
+ ```
28
+ Vernier.trace(out: "time_profile.json") { some_slow_method }
29
+ ```
23
30
 
24
31
  ## Development
25
32
 
@@ -31,6 +38,13 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
31
38
 
32
39
  Bug reports and pull requests are welcome on GitHub at https://github.com/jhawthorn/vernier. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/jhawthorn/vernier/blob/main/CODE_OF_CONDUCT.md).
33
40
 
41
+ ### Resources
42
+
43
+ * https://profiler.firefox.com/docs/#/
44
+ * https://github.com/firefox-devtools/profiler/tree/main/docs-developer
45
+ * https://github.com/tmm1/stackprof
46
+ * https://github.com/ruby/ruby/pull/5500
47
+
34
48
  ## License
35
49
 
36
50
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile CHANGED
@@ -9,6 +9,10 @@ Rake::TestTask.new(:test) do |t|
9
9
  t.test_files = FileList["test/**/test_*.rb"]
10
10
  end
11
11
 
12
+ task :console => :compile do
13
+ sh "irb -r vernier"
14
+ end
15
+
12
16
  require "rake/extensiontask"
13
17
 
14
18
  task build: :compile
@@ -0,0 +1,38 @@
1
+ require "vernier"
2
+
3
+ Vernier.trace(out: "http_requests.json") do
4
+
5
+ require "net/http"
6
+ require "uri"
7
+ require "openssl"
8
+
9
+ urls = Queue.new
10
+ received = Queue.new
11
+
12
+ threads = 2.times.map do
13
+ Thread.new do
14
+ while url = urls.pop
15
+ uri = URI.parse(url)
16
+ response = Net::HTTP.get_response(uri)
17
+
18
+ received << [url, response.code]
19
+ end
20
+ end
21
+ end
22
+
23
+ Thread.new do
24
+ threads.each(&:join)
25
+ received.close
26
+ end
27
+
28
+ urls << "http://example.com"
29
+ urls << "https://www.johnhawthorn.com"
30
+ urls << "https://tenderlovemaking.com/"
31
+ urls.close
32
+
33
+ while x = received.pop
34
+ url, code = *x
35
+ puts "#{url} #{code}"
36
+ end
37
+
38
+ end
@@ -0,0 +1,44 @@
1
+ #pragma once
2
+
3
+ inline const char *
4
+ ruby_object_type_name(VALUE obj) {
5
+ enum ruby_value_type type = rb_type(obj);
6
+
7
+ #define TYPE_CASE(x) case (x): return (#x)
8
+
9
+ // Many of these are impossible, but it's easier to just include them
10
+ switch (type) {
11
+ TYPE_CASE(T_OBJECT);
12
+ TYPE_CASE(T_CLASS);
13
+ TYPE_CASE(T_MODULE);
14
+ TYPE_CASE(T_FLOAT);
15
+ TYPE_CASE(T_STRING);
16
+ TYPE_CASE(T_REGEXP);
17
+ TYPE_CASE(T_ARRAY);
18
+ TYPE_CASE(T_HASH);
19
+ TYPE_CASE(T_STRUCT);
20
+ TYPE_CASE(T_BIGNUM);
21
+ TYPE_CASE(T_FILE);
22
+ TYPE_CASE(T_DATA);
23
+ TYPE_CASE(T_MATCH);
24
+ TYPE_CASE(T_COMPLEX);
25
+ TYPE_CASE(T_RATIONAL);
26
+
27
+ TYPE_CASE(T_NIL);
28
+ TYPE_CASE(T_TRUE);
29
+ TYPE_CASE(T_FALSE);
30
+ TYPE_CASE(T_SYMBOL);
31
+ TYPE_CASE(T_FIXNUM);
32
+ TYPE_CASE(T_UNDEF);
33
+
34
+ TYPE_CASE(T_IMEMO);
35
+ TYPE_CASE(T_NODE);
36
+ TYPE_CASE(T_ICLASS);
37
+ TYPE_CASE(T_ZOMBIE);
38
+ TYPE_CASE(T_MOVED);
39
+
40
+ default:
41
+ return "unknown type";
42
+ }
43
+ #undef TYPE_CASE
44
+ }