vernier 1.3.1 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e471649c05955e4b4411e87aed57ce900eca0d9c01750feca9df4c35a5de1541
4
- data.tar.gz: e37b6d23c3178224d3de32d930bc27459dc49fb87172509222e03b1142ea524a
3
+ metadata.gz: faf587f758e0b9a68adc377bf27c0f35eb0605703b088e3e122f969f513c864d
4
+ data.tar.gz: 6cbefbfa78fb3ef1e92c7cfdd5ba0dd43f59b1f63cce6583fe18f4e667fd61db
5
5
  SHA512:
6
- metadata.gz: 8fb4c59fe60b6b905c2491f6dc02e557d55c61c4bc233105ca6a6eb99e2c4264c9dbe3442185fdf52ff7d8d8f7d20324c05aeb390cbbfecbf612d3ee84ca6146
7
- data.tar.gz: 9b57699f365e9f5460454da9dc45b36081baee0a1a94e51506c948cf9f76410c74a6c140ff01336117fc8337714217fb3a64f73ac6098f713283597894f0e070
6
+ metadata.gz: 402ce92fbe0f408906fe368e0e2edc637dd68f08476a690877166cb1628068fd6bbfd11878d625276e8f3f785c20adc49ef19494d9e81162d201930b4c64c81f
7
+ data.tar.gz: 8b7d6c687873ed991b23a508231471b445d6960b47bac2045f1f9eee9f5d82584490a0278f2344d0001e3f5367fffcdfc29fbc284bed448c4155e4381aa26292
data/README.md CHANGED
@@ -30,7 +30,7 @@ gem "vernier", "~> 1.0"
30
30
 
31
31
  ## Usage
32
32
 
33
- The output can be viewed in the web app at https://vernier.prof, locally using the [`profile-viewer` gem](https://github.com/tenderlove/profiler/tree/ruby) (both lightly customized versions of the firefox profiler frontend, which profiles are also compatible with) or by using the `verrnier view` command in the CLI.
33
+ The output can be viewed in the web app at https://vernier.prof, locally using the [`profile-viewer` gem](https://github.com/tenderlove/profiler/tree/ruby) (both lightly customized versions of the firefox profiler frontend, which profiles are also compatible with) or by using the `vernier view` command in the CLI.
34
34
 
35
35
  - **Flame Graph**: Shows proportionally how much time is spent within particular stack frames. Frames are grouped together, which means that x-axis / left-to-right order is not meaningful.
36
36
  - **Stack Chart**: Shows the stack at each sample with the x-axis representing time and can be read left-to-right.
@@ -30,6 +30,7 @@
30
30
  #include "vernier.hh"
31
31
 
32
32
  #include "ruby/ruby.h"
33
+ #include "ruby/encoding.h"
33
34
  #include "ruby/debug.h"
34
35
  #include "ruby/thread.h"
35
36
 
@@ -746,7 +747,20 @@ StackTable::stack_table_func_name(VALUE self, VALUE idxval) {
746
747
  } else {
747
748
  const auto &func_info = table[idx];
748
749
  const std::string &label = func_info.label;
749
- return rb_interned_str(label.c_str(), label.length());
750
+
751
+ // Ruby constants are in an arbitrary (ASCII compatible) encoding and
752
+ // method names are in an arbitrary (ASCII compatible) encoding. These
753
+ // can be mixed in the same program.
754
+ //
755
+ // However, by this point we've lost the chain of what the correct
756
+ // encoding should be. Oops!
757
+ //
758
+ // Instead we'll just guess at UTF-8 which should satisfy most. It won't
759
+ // necessarily be valid but that can be scrubbed on the Ruby side.
760
+ //
761
+ // In the future we might keep class and method name separate for
762
+ // longer, preserve encodings, and defer formatting to the Ruby side.
763
+ return rb_enc_interned_str(label.c_str(), label.length(), rb_utf8_encoding());
750
764
  }
751
765
  }
752
766
 
@@ -761,7 +775,11 @@ StackTable::stack_table_func_filename(VALUE self, VALUE idxval) {
761
775
  } else {
762
776
  const auto &func_info = table[idx];
763
777
  const std::string &filename = func_info.file;
764
- return rb_interned_str(filename.c_str(), filename.length());
778
+
779
+ // Technically filesystems are binary and then Ruby interprets that as
780
+ // default_external encoding. But to keep things simple for now we are
781
+ // going to assume UTF-8.
782
+ return rb_enc_interned_str(filename.c_str(), filename.length(), rb_utf8_encoding());
765
783
  }
766
784
  }
767
785
 
@@ -1397,11 +1415,13 @@ class CustomCollector : public BaseCollector {
1397
1415
  VALUE threads = rb_hash_new();
1398
1416
  rb_ivar_set(result, rb_intern("@threads"), threads);
1399
1417
 
1400
- VALUE thread_hash = rb_hash_new();
1401
- samples.write_result(thread_hash);
1418
+ VALUE thread_hash = rb_hash_new();
1419
+ samples.write_result(thread_hash);
1402
1420
 
1403
- rb_hash_aset(threads, ULL2NUM(0), thread_hash);
1404
- rb_hash_aset(thread_hash, sym("tid"), ULL2NUM(0));
1421
+ rb_hash_aset(threads, ULL2NUM(0), thread_hash);
1422
+ rb_hash_aset(thread_hash, sym("tid"), ULL2NUM(0));
1423
+ rb_hash_aset(thread_hash, sym("name"), rb_str_new_cstr("custom"));
1424
+ rb_hash_aset(thread_hash, sym("started_at"), ULL2NUM(started_at.nanoseconds()));
1405
1425
 
1406
1426
  return result;
1407
1427
  }
@@ -525,7 +525,23 @@ module Vernier
525
525
  end
526
526
 
527
527
  def string_table
528
- @strings.keys
528
+ @strings.keys.map do |string|
529
+ if string.ascii_only?
530
+ string
531
+ elsif string.encoding == Encoding::UTF_8
532
+ if string.valid_encoding?
533
+ string
534
+ else
535
+ string.scrub
536
+ end
537
+ elsif string.encoding == Encoding::BINARY
538
+ # TODO: We might want to guess UTF-8 and escape the binary more explicitly
539
+ string.dup.force_encoding("UTF-8").scrub
540
+ else
541
+ # TODO: ideally we should attempt to properly re-encode here, but right now I think this is dead code
542
+ string.dup.force_encoding("UTF-8").scrub
543
+ end
544
+ end
529
545
  end
530
546
 
531
547
  private
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Vernier
4
- VERSION = "1.3.1"
4
+ VERSION = "1.4.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vernier
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Hawthorn
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-11-04 00:00:00.000000000 Z
11
+ date: 2024-11-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -117,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
117
  - !ruby/object:Gem::Version
118
118
  version: '0'
119
119
  requirements: []
120
- rubygems_version: 3.5.16
120
+ rubygems_version: 3.5.22
121
121
  signing_key:
122
122
  specification_version: 4
123
123
  summary: A next generation CRuby profiler