dial 0.1.9 → 0.2.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: 31949e2dbaf8b3ca4f422ae02115747913ce3bd704b0aaf8d45d5956d0ba2ac5
4
- data.tar.gz: aecdd78df3d7e50c0dd9b98c67c0f7633d6cc2fa43ea33d01987a148dff53cf0
3
+ metadata.gz: 60920a66ef5fc1cfba31a668f5b582c26d95a821b589bda396964a6946bb82bb
4
+ data.tar.gz: de23202b1c41cc4be4e0f51c40904001fc573ce1894802c7c331fc99fa45ad47
5
5
  SHA512:
6
- metadata.gz: 21ed80548f3559308cfdc13ff69df8168ef87ffa6268faea8d5901e2209cbd1e9f775bcbd48db355e83c1d3e48cb59f285af0c0271fc1fa14442852c84dab521
7
- data.tar.gz: 202f8d84d6ce0520b7bf53df0cac7545a85f1c6f723c845158c9161cf52f1a1a6fbe55e70671a70c9bf1ca43aad052d28d2f10b3a7572ea34c5747090121ab98
6
+ metadata.gz: b5852b9db8040af2e14c082b38fe2a31dabcb9a6191db373eaee5f4fa18c45db8577b54309e41c3a065ef7aa5277262483f8cff72286c8ef554808eb083c4ab8
7
+ data.tar.gz: 15616a0cb158f916b6e1d0b61fe1e3ca10ddfab848f87eb51d65edc9a986553f23a1e48487bbea991fbc28c8d934a60d3a229d5c3b69ae89100a827c94563d03
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.2.0] - 2025-02-22
4
+
5
+ - Perf: Eagerly check content type to avoid profiling incompatible requests
6
+ - Perf: Manually write vernier output files in background thread
7
+ - Use gzipped vernier output files by default
8
+ - UI: Use inline color properties to prevent overriding by user styles
9
+
3
10
  ## [0.1.9] - 2025-01-27
4
11
 
5
12
  - Increase default vernier allocation interval from 10k to 100k
@@ -1,11 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "rack"
4
+
3
5
  require_relative "version"
4
6
 
5
7
  module Dial
6
8
  PROGRAM_ID = Process.getsid Process.pid
7
9
 
8
- REQUEST_TIMING_HEADER = "dial_request_timing"
10
+ HTTP_ACCEPT = "HTTP_ACCEPT"
11
+ CONTENT_TYPE = ::Rack::CONTENT_TYPE
12
+ CONTENT_LENGTH = ::Rack::CONTENT_LENGTH
13
+ REQUEST_TIMING = "dial_request_timing"
9
14
 
10
15
  FILE_STALE_SECONDS = 60 * 60
11
16
 
@@ -4,7 +4,7 @@ Dial::Engine.routes.draw do
4
4
  scope path: "/dial", as: "dial" do
5
5
  get "profile", to: lambda { |env|
6
6
  uuid = env[::Rack::QUERY_STRING].sub "uuid=", ""
7
- path = String ::Rails.root.join Dial::VERNIER_PROFILE_OUT_RELATIVE_DIRNAME, "#{uuid}.json"
7
+ path = String ::Rails.root.join Dial::VERNIER_PROFILE_OUT_RELATIVE_DIRNAME, "#{uuid}.json.gz"
8
8
 
9
9
  if File.exist? path
10
10
  [
@@ -91,7 +91,6 @@ module Dial
91
91
  flex-direction: column;
92
92
  padding: 0.5rem;
93
93
  font-size: 0.85rem;
94
- color: black;
95
94
 
96
95
  #dial-preview {
97
96
  display: flex;
@@ -121,12 +120,17 @@ module Dial
121
120
 
122
121
  span {
123
122
  text-align: left;
123
+ color: black;
124
+ }
125
+
126
+ a {
127
+ color: blue;
124
128
  }
125
129
 
126
130
  hr {
127
131
  width: -moz-available;
128
132
  margin: 0.65rem 0 0 0;
129
- background-color: black;
133
+ border-color: black;
130
134
  }
131
135
 
132
136
  details {
@@ -137,6 +141,7 @@ module Dial
137
141
  summary {
138
142
  margin: 0.25rem 0 0 0;
139
143
  cursor: pointer;
144
+ color: black;
140
145
  }
141
146
  }
142
147
  CSS
@@ -171,18 +176,18 @@ module Dial
171
176
  rescue ::ActionController::RoutingError
172
177
  {}
173
178
  end.then do |info|
174
- "<b>Controller:</b> #{info[:controller] || "NA"} | <b>Action:</b> #{info[:action] || "NA"}"
179
+ "<b>Controller:</b> #{info[:controller] || "N/A"} | <b>Action:</b> #{info[:action] || "N/A"}"
175
180
  end
176
181
  end
177
182
 
178
183
  def formatted_request_timing env
179
- "<b>Request timing:</b> #{env[REQUEST_TIMING_HEADER]}ms"
184
+ "<b>Request timing:</b> #{env[REQUEST_TIMING]}ms"
180
185
  end
181
186
 
182
187
  def formatted_profile_output env, profile_out_filename
183
188
  url_base = ::Rails.application.routes.url_helpers.dial_url host: env[::Rack::HTTP_HOST]
184
189
  prefix = "/" unless url_base.end_with? "/"
185
- uuid = profile_out_filename.delete_suffix ".json"
190
+ uuid = profile_out_filename.delete_suffix ".json.gz"
186
191
  profile_out_url = URI.encode_www_form_component url_base + "#{prefix}dial/profile?uuid=#{uuid}"
187
192
 
188
193
  "<a href='https://vernier.prof/from-url/#{profile_out_url}' target='_blank'>View profile</a>"
@@ -206,7 +211,7 @@ module Dial
206
211
  .sort_by { |_, timing| -timing }
207
212
  .map { |event, timing| "<span><b>#{event}:</b> #{timing}</span>" }.join
208
213
  else
209
- "NA"
214
+ "<span>N/A</span>"
210
215
  end
211
216
  end
212
217
 
@@ -224,7 +229,7 @@ module Dial
224
229
  HTML
225
230
  end.join
226
231
  else
227
- "NA"
232
+ "<span>N/A</span>"
228
233
  end
229
234
  end
230
235
 
@@ -17,15 +17,18 @@ module Dial
17
17
  end
18
18
 
19
19
  def call env
20
+ unless env[HTTP_ACCEPT]&.include? "text/html"
21
+ return @app.call env
22
+ end
23
+
20
24
  start_time = Process.clock_gettime Process::CLOCK_MONOTONIC
21
25
 
22
- profile_out_filename = "#{Util.uuid}_vernier.json"
26
+ profile_out_filename = "#{Util.uuid}_vernier.json.gz"
23
27
  profile_out_pathname = "#{profile_out_dir_pathname}/#{profile_out_filename}"
24
28
 
25
- status, headers, rack_body = nil
26
- ruby_vm_stat, gc_stat, gc_stat_heap = nil
29
+ status, headers, rack_body, ruby_vm_stat, gc_stat, gc_stat_heap, vernier_result = nil
27
30
  ::Prosopite.scan do
28
- ::Vernier.profile out: profile_out_pathname, interval: VERNIER_INTERVAL, allocation_interval: VERNIER_ALLOCATION_INTERVAL, hooks: [:memory_usage, :rails] do
31
+ vernier_result = ::Vernier.profile interval: VERNIER_INTERVAL, allocation_interval: VERNIER_ALLOCATION_INTERVAL, hooks: [:memory_usage, :rails] do
29
32
  ruby_vm_stat, gc_stat, gc_stat_heap = with_diffed_ruby_stats do
30
33
  status, headers, rack_body = @app.call env
31
34
  end
@@ -33,14 +36,15 @@ module Dial
33
36
  end
34
37
  server_timing = server_timing headers
35
38
 
36
- unless headers[::Rack::CONTENT_TYPE]&.include? "text/html"
39
+ unless headers[CONTENT_TYPE]&.include? "text/html"
37
40
  return [status, headers, rack_body]
38
41
  end
39
42
 
43
+ write_vernier_result! vernier_result, profile_out_pathname
40
44
  query_logs = clear_query_logs!
41
45
 
42
46
  finish_time = Process.clock_gettime Process::CLOCK_MONOTONIC
43
- env[REQUEST_TIMING_HEADER] = ((finish_time - start_time) * 1_000).round 2
47
+ env[REQUEST_TIMING] = ((finish_time - start_time) * 1_000).round 2
44
48
 
45
49
  body = String.new.tap do |str|
46
50
  rack_body.each { |chunk| str << chunk }
@@ -50,7 +54,7 @@ module Dial
50
54
  </body>
51
55
  HTML
52
56
 
53
- headers[::Rack::CONTENT_LENGTH] = body.bytesize.to_s
57
+ headers[CONTENT_LENGTH] = body.bytesize.to_s
54
58
 
55
59
  [status, headers, [body]]
56
60
  end
@@ -69,6 +73,15 @@ module Dial
69
73
  ]
70
74
  end
71
75
 
76
+ def write_vernier_result! result, pathname
77
+ Thread.new do
78
+ Thread.current.name = "Dial::Middleware#write_vernier_result!"
79
+ Thread.current.report_on_exception = false
80
+
81
+ result.write out: pathname
82
+ end
83
+ end
84
+
72
85
  def clear_query_logs!
73
86
  [].tap do |query_logs|
74
87
  File.open("#{query_log_dir_pathname}/#{PROSOPITE_LOG_FILENAME}", "r+") do |file|
data/lib/dial/railtie.rb CHANGED
@@ -19,7 +19,7 @@ module Dial
19
19
  end
20
20
 
21
21
  initializer "dial.clean_up_vernier_profile_out_files" do |app|
22
- stale_files("#{profile_out_dir_pathname}/*.json").each do |profile_out_file|
22
+ stale_files("#{profile_out_dir_pathname}/*.json.gz").each do |profile_out_file|
23
23
  File.delete profile_out_file rescue nil
24
24
  end
25
25
  end
data/lib/dial/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Dial
4
- VERSION = "0.1.9"
4
+ VERSION = "0.2.0"
5
5
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dial
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joshua Young
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-01-27 00:00:00.000000000 Z
10
+ date: 2025-02-22 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: railties