gvl-tracing 1.6.0 → 1.6.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: af27ef999bd0dba6070d9faf4e4465f77ae7dc440d77d99999be6ac0c1be07ec
4
- data.tar.gz: 2a0978b7135b22a9827e7f040f04ba7e261bd3ebb9f576218e19473d84560053
3
+ metadata.gz: 2bf28c6665bf4afa02c13299947bb65d7c62c3af783858afdc3a5383e334fa47
4
+ data.tar.gz: b1999e7e17d56e76ba732962708c14979e2690cd78204946d2f05e7146b05725
5
5
  SHA512:
6
- metadata.gz: fc9bb3ac74a50d3103c0acc538ec7ef171324427f78ef62eadcc1afc5a2def15f3ef7063f3f74150aad20f3e93a406d2c3f2a0ca19aa63cff824d1e684637e19
7
- data.tar.gz: cca0048ff2181b6346e0628dcb9710ee83937d2b7a1014c0133b0b7747b2b5328e73d29d4164daedeaddde9cb6e879a52a73646e62ca95e0c8845c2dc044d3d0
6
+ metadata.gz: feb5fb173e07343af18c929608b20b2463fc0b676565b926242585f3fed31991e34ab5f549d7cbfe0e26c883d4a1e6eebf1d8da9e1586f0fa63d0890cdd3b108
7
+ data.tar.gz: 615226e345e230b989d7738754f02a058935d67679b4ca16c610cbbb6fe34f82aff6de3299d9548af579a30d55bccaedf25cd52d4f631023cff93a683fe3c8bb
@@ -83,6 +83,7 @@ static VALUE gc_tracepoint = Qnil;
83
83
  static int thread_storage_key = 0;
84
84
  static VALUE all_seen_threads = Qnil;
85
85
  static pthread_mutex_t all_seen_threads_mutex = PTHREAD_MUTEX_INITIALIZER;
86
+ static pthread_mutex_t output_mutex = PTHREAD_MUTEX_INITIALIZER;
86
87
  static bool os_threads_view_enabled;
87
88
 
88
89
  static VALUE tracing_init_local_storage(VALUE, VALUE);
@@ -95,6 +96,8 @@ static void on_gc_event(VALUE tpval, void *_unused1);
95
96
  static VALUE mark_sleeping(VALUE _self);
96
97
  static size_t thread_local_state_memsize(UNUSED_ARG const void *_unused);
97
98
  static void thread_local_state_mark(void *data);
99
+ static inline void output_mutex_lock(void);
100
+ static inline void output_mutex_unlock(void);
98
101
  static inline int32_t thread_id_for(thread_local_state *state);
99
102
  static VALUE ruby_thread_id_for(UNUSED_ARG VALUE _self, VALUE thread);
100
103
  static VALUE trim_all_seen_threads(UNUSED_ARG VALUE _self);
@@ -259,6 +262,7 @@ static double render_event(thread_local_state *state, const char *event_name) {
259
262
  // Important note: We've observed some rendering issues in perfetto if the tid or pid are numbers that are "too big",
260
263
  // see https://github.com/ivoanjo/gvl-tracing/pull/4#issuecomment-1196463364 for an example.
261
264
 
265
+ output_mutex_lock();
262
266
  fprintf(output_file,
263
267
  // Finish previous duration
264
268
  " {\"ph\": \"E\", \"pid\": %"PRId64", \"tid\": %d, \"ts\": %f},\n" \
@@ -269,6 +273,7 @@ static double render_event(thread_local_state *state, const char *event_name) {
269
273
  // Args for second line
270
274
  process_id, thread_id_for(state), now_microseconds, event_name
271
275
  );
276
+ output_mutex_unlock();
272
277
 
273
278
  return now_microseconds;
274
279
  }
@@ -355,6 +360,18 @@ static inline void all_seen_threads_mutex_unlock(void) {
355
360
  if (error) rb_syserr_fail(error, "Failed to unlock GvlTracing mutex");
356
361
  }
357
362
 
363
+ static inline void output_mutex_lock(void) {
364
+ int error = pthread_mutex_lock(&output_mutex);
365
+ // Can't raise exceptions on error since it gets used from outside the GVL
366
+ if (error) fprintf(stderr, "Failed to lock the GvlTracing output_mutex");
367
+ }
368
+
369
+ static inline void output_mutex_unlock(void) {
370
+ int error = pthread_mutex_unlock(&output_mutex);
371
+ // Can't raise exceptions on error since it gets used from outside the GVL
372
+ if (error) fprintf(stderr, "Failed to unlock the GvlTracing output_mutex");
373
+ }
374
+
358
375
  #ifdef RUBY_3_3_PLUS
359
376
  static inline thread_local_state *GT_LOCAL_STATE(VALUE thread, bool allocate) {
360
377
  thread_local_state *state = rb_internal_thread_specific_get(thread, thread_storage_key);
@@ -444,17 +461,21 @@ static void render_os_thread_event(thread_local_state *state, double now_microse
444
461
  // chars, so here we append a different letter to each thread to cause the color hashing to differ.
445
462
  char color_suffix_hack = ('a' + (thread_id_for(state) % 26));
446
463
 
464
+ output_mutex_lock();
447
465
  fprintf(output_file,
448
466
  " {\"ph\": \"B\", \"pid\": %"PRId64", \"tid\": %u, \"ts\": %f, \"name\": \"Thread %d (%c)\"},\n",
449
467
  OS_THREADS_VIEW_PID, current_native_thread_id(), now_microseconds, thread_id_for(state), color_suffix_hack
450
468
  );
469
+ output_mutex_unlock();
451
470
  }
452
471
 
453
472
  static void finish_previous_os_thread_event(double now_microseconds) {
473
+ output_mutex_lock();
454
474
  fprintf(output_file,
455
475
  " {\"ph\": \"E\", \"pid\": %"PRId64", \"tid\": %u, \"ts\": %f},\n",
456
476
  OS_THREADS_VIEW_PID, current_native_thread_id(), now_microseconds
457
477
  );
478
+ output_mutex_unlock();
458
479
  }
459
480
 
460
481
  static inline uint32_t current_native_thread_id(void) {
data/gvl-tracing.gemspec CHANGED
@@ -42,7 +42,8 @@ Gem::Specification.new do |spec|
42
42
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
43
43
  spec.files = Dir.chdir(__dir__) do
44
44
  `git ls-files -z`.split("\x0").reject do |f|
45
- (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features|examples)/|\.(?:git|travis|circleci)|appveyor)})
45
+ (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features|examples)/|\.(?:git|travis|circleci)|appveyor)}) ||
46
+ [".editorconfig", ".ruby-version", ".standard.yml", "gems.rb", "Rakefile"].include?(f)
46
47
  end
47
48
  end
48
49
  spec.require_paths = ["lib", "ext"]
@@ -26,5 +26,5 @@
26
26
  # frozen_string_literal: true
27
27
 
28
28
  module GvlTracing
29
- VERSION = "1.6.0"
29
+ VERSION = "1.6.1"
30
30
  end
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gvl-tracing
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.0
4
+ version: 1.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivo Anjo
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-10-30 00:00:00.000000000 Z
11
+ date: 2024-12-08 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description:
13
+ description:
14
14
  email:
15
15
  - ivo@ivoanjo.me
16
16
  executables: []
@@ -18,16 +18,11 @@ extensions:
18
18
  - ext/gvl_tracing_native_extension/extconf.rb
19
19
  extra_rdoc_files: []
20
20
  files:
21
- - ".editorconfig"
22
- - ".ruby-version"
23
- - ".standard.yml"
24
21
  - CODE_OF_CONDUCT.adoc
25
22
  - LICENSE
26
23
  - README.adoc
27
- - Rakefile
28
24
  - ext/gvl_tracing_native_extension/extconf.rb
29
25
  - ext/gvl_tracing_native_extension/gvl_tracing.c
30
- - gems.rb
31
26
  - gvl-tracing.gemspec
32
27
  - lib/gvl-tracing.rb
33
28
  - lib/gvl_tracing/sleep_tracking.rb
@@ -37,7 +32,7 @@ homepage: https://github.com/ivoanjo/gvl-tracing
37
32
  licenses:
38
33
  - MIT
39
34
  metadata: {}
40
- post_install_message:
35
+ post_install_message:
41
36
  rdoc_options: []
42
37
  require_paths:
43
38
  - lib
@@ -53,8 +48,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
53
48
  - !ruby/object:Gem::Version
54
49
  version: '0'
55
50
  requirements: []
56
- rubygems_version: 3.5.11
57
- signing_key:
51
+ rubygems_version: 3.4.1
52
+ signing_key:
58
53
  specification_version: 4
59
54
  summary: Get a timeline view of Global VM Lock usage in your Ruby app
60
55
  test_files: []
data/.editorconfig DELETED
@@ -1,22 +0,0 @@
1
- # EditorConfig is awesome: https://EditorConfig.org
2
-
3
- # top-most EditorConfig file
4
- root = true
5
-
6
- # Unix-style newlines with a newline ending every file
7
- [*]
8
- end_of_line = lf
9
- insert_final_newline = true
10
- trim_trailing_whitespace = true
11
-
12
- [*.h]
13
- indent_style = space
14
- indent_size = 2
15
-
16
- [*.c]
17
- indent_style = space
18
- indent_size = 2
19
-
20
- [*.yml]
21
- indent_style = space
22
- indent_size = 2
data/.ruby-version DELETED
@@ -1 +0,0 @@
1
- ruby-3.2.2
data/.standard.yml DELETED
@@ -1,9 +0,0 @@
1
- ruby_version: 3.2
2
-
3
- ignore:
4
- - 'examples/example1.rb':
5
- - Style/InfiniteLoop
6
- - 'examples/example5.rb':
7
- - Style/InfiniteLoop
8
- - 'lib/gvl_tracing/sleep_tracking.rb':
9
- - Style/MixinUsage
data/Rakefile DELETED
@@ -1,36 +0,0 @@
1
- # gvl-tracing: Ruby gem for getting a timelinew view of GVL usage
2
- # Copyright (c) 2022 Ivo Anjo <ivo@ivoanjo.me>
3
- #
4
- # This file is part of gvl-tracing.
5
- #
6
- # MIT License
7
- #
8
- # Permission is hereby granted, free of charge, to any person obtaining a copy
9
- # of this software and associated documentation files (the "Software"), to deal
10
- # in the Software without restriction, including without limitation the rights
11
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
- # copies of the Software, and to permit persons to whom the Software is
13
- # furnished to do so, subject to the following conditions:
14
- #
15
- # The above copyright notice and this permission notice shall be included in all
16
- # copies or substantial portions of the Software.
17
- #
18
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
- # SOFTWARE.
25
-
26
- # frozen_string_literal: true
27
-
28
- require "bundler/gem_tasks"
29
- require "standard/rake"
30
- require "rake/extensiontask"
31
- require "rspec/core/rake_task"
32
-
33
- Rake::ExtensionTask.new("gvl_tracing_native_extension")
34
- RSpec::Core::RakeTask.new(:spec)
35
-
36
- task default: [:compile, :"standard:fix", :spec]
data/gems.rb DELETED
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source "https://rubygems.org"
4
-
5
- gemspec
6
-
7
- gem "rake", "~> 13.0"
8
- gem "rake-compiler", "~> 1.2"
9
- gem "pry"
10
- gem "pry-byebug"
11
- gem "rspec"
12
- gem "standard", "~> 1.41"
13
- gem "concurrent-ruby"
14
- gem "benchmark-ips", "~> 2.13"
15
- gem "rubocop", ">= 1.66.0"