rails-profiler 0.44.26 → 0.44.27

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: 21bc2d1a836ed387db93a03b924c8af44d69d0d6f8d9d50e6ebf2ca9117d038f
4
- data.tar.gz: 4afb33c62cc46edae07feb0c3e9fc825f26451b430f3888ae7a71915ece91749
3
+ metadata.gz: 6f2ed2fe704d2027059860b5738d7a188b8374020aa60041d7121be951b6afdb
4
+ data.tar.gz: 3b6a7bfe912382205fdb7b04a390634c2763805b18f6f41c93dda2d2d9d2aefe
5
5
  SHA512:
6
- metadata.gz: 0b048545adaa158803c1beb9d2c8eff6adcd42ab7fc2722dd918a4887096c75cc3ece99ec56b2b5d140323efbdb67fa4b9e16cbdac1734bfe732cdce7cd4db31
7
- data.tar.gz: 2a933760b94b6bc7e2890a69b00431bb013feeb8138ccf0f2827ac9d222de066a340ea2bac2fdafbf0bb3bb1a2d7e5b2648fe6ddd80dfb17a2473105c61f9d75
6
+ metadata.gz: dccc3fb45bcb676d5467e01cead1d205adc52ddde042a9587639b95351300ac622e21ae8db9f2d4a86b255e1ab8b77241bc59d39e26faed7b7c0067172aac60d
7
+ data.tar.gz: 5888e29b8dcccbd98705c36dabfadab10c62bc9e141c4f53b35061c8ea3ecd0d0f7ed70ff217922d676e9282870e2c98f62c767e48b1c8573195fda342a6587c
data/CHANGELOG.md CHANGED
@@ -19,6 +19,14 @@ every commit of every tag interval is accounted for one way or the other.
19
19
 
20
20
  ## [Unreleased]
21
21
 
22
+ ## [0.44.27] - 2026-10-26
23
+
24
+ <!-- stamped -->
25
+
26
+ ### Fixed
27
+
28
+ - **MCP tools:** cursor pagination now uses microsecond precision timestamps, so profiles started within the same second are no longer lost between pages. The SQLite store keeps its times with microseconds too (existing rows are padded once on open), and the `query_mailers` cursor carries the position of the last delivery shown so that the deliveries of one request are not dropped at a page boundary.
29
+
22
30
  ## [0.44.26] - 2026-10-26
23
31
 
24
32
  <!-- stamped -->
@@ -91,7 +91,7 @@ module Profiler
91
91
 
92
92
  if consoles.size == limit
93
93
  lines << ""
94
- lines << "*Next cursor: #{consoles.last.started_at.iso8601}*"
94
+ lines << "*Next cursor: #{consoles.last.started_at.iso8601(6)}*"
95
95
  end
96
96
 
97
97
  lines.join("\n")
@@ -83,7 +83,7 @@ module Profiler
83
83
 
84
84
  if jobs.size == limit
85
85
  lines << ""
86
- lines << "*Next cursor: #{jobs.last.started_at.iso8601}*"
86
+ lines << "*Next cursor: #{jobs.last.started_at.iso8601(6)}*"
87
87
  end
88
88
 
89
89
  lines.join("\n")
@@ -22,8 +22,9 @@ module Profiler
22
22
  next unless mailer_data
23
23
 
24
24
  all_emails = Array(mailer_data["emails"]) + Array(mailer_data["errors"])
25
- all_emails.each do |email|
26
- entry = email.merge("profile_token" => profile.token, "profile_started_at" => profile.started_at)
25
+ all_emails.each_with_index do |email, index|
26
+ entry = email.merge("profile_token" => profile.token, "profile_started_at" => profile.started_at,
27
+ "profile_index" => index)
27
28
 
28
29
  if params["mailer_class"]
29
30
  next unless entry["mailer_class"].to_s.downcase.include?(params["mailer_class"].downcase)
@@ -49,15 +50,23 @@ module Profiler
49
50
  end
50
51
 
51
52
  if params["cursor"]
53
+ # "<time>|<n>": the n-th delivery of the profile started at <time> was the last one
54
+ # shown, so the others of that profile (same start time) still come after it.
55
+ time_part, index_part = params["cursor"].to_s.split("|", 2)
52
56
  cutoff = begin
53
- Time.parse(params["cursor"])
57
+ Time.parse(time_part)
54
58
  rescue ArgumentError, TypeError
55
59
  nil # a cursor that is not a time is ignored, as before
56
60
  end
61
+ last_index = Integer(index_part, exception: false) if index_part
57
62
  if cutoff
63
+ cutoff_key = cutoff.getutc.iso8601(6)
58
64
  emails = emails.select do |e|
59
65
  started = e["profile_started_at"]
60
- started && started < cutoff
66
+ next false unless started
67
+
68
+ started < cutoff ||
69
+ (last_index && started.getutc.iso8601(6) == cutoff_key && e["profile_index"] > last_index)
61
70
  end
62
71
  end
63
72
  end
@@ -109,7 +118,7 @@ module Profiler
109
118
  if emails.size == limit
110
119
  last_started = emails.last["profile_started_at"]
111
120
  lines << ""
112
- lines << "*Next cursor: #{last_started.iso8601}*" if last_started
121
+ lines << "*Next cursor: #{last_started.iso8601(6)}|#{emails.last["profile_index"]}*" if last_started
113
122
  end
114
123
 
115
124
  lines.join("\n")
@@ -77,7 +77,7 @@ module Profiler
77
77
 
78
78
  if profiles.size == limit
79
79
  lines << ""
80
- lines << "*Next cursor: #{profiles.last.started_at.iso8601}*"
80
+ lines << "*Next cursor: #{profiles.last.started_at.iso8601(6)}*"
81
81
  end
82
82
 
83
83
  lines.join("\n")
@@ -90,7 +90,7 @@ module Profiler
90
90
 
91
91
  if tests.size == limit
92
92
  lines << ""
93
- lines << "*Next cursor: #{tests.last.started_at.iso8601}*"
93
+ lines << "*Next cursor: #{tests.last.started_at.iso8601(6)}*"
94
94
  end
95
95
 
96
96
  lines.join("\n")
@@ -149,7 +149,7 @@ module Profiler
149
149
  duration: @duration,
150
150
  allocated_objects: @allocated_objects,
151
151
  memory: memory,
152
- started_at: @started_at&.iso8601,
152
+ started_at: @started_at&.iso8601(6),
153
153
  finished_at: @finished_at&.iso8601,
154
154
  params: @params,
155
155
  params_truncated: @params_truncated,
@@ -196,7 +196,7 @@ module Profiler
196
196
  end
197
197
 
198
198
  def cleanup(older_than: 24 * 60 * 60)
199
- cutoff = (Time.now - older_than).utc.iso8601
199
+ cutoff = (Time.now - older_than).utc.iso8601(6)
200
200
  tokens = @db.execute(
201
201
  "SELECT token FROM profiler_profiles WHERE started_at < :cutoff", cutoff: cutoff
202
202
  ).map { |r| r["token"] }
@@ -323,6 +323,7 @@ module Profiler
323
323
 
324
324
  @db.execute("CREATE INDEX IF NOT EXISTS idx_profiler_trace_id ON profiler_profiles(trace_id)")
325
325
  migrate_times_to_utc
326
+ migrate_times_to_microseconds
326
327
  end
327
328
 
328
329
  # Version 1 stores the times in UTC. The rows written before it carry the local offset of
@@ -343,6 +344,23 @@ module Profiler
343
344
  end
344
345
  end
345
346
 
347
+ # Version 2 stores the times with microseconds. As text, "...:00Z" sorts after "...:00.5Z"
348
+ # ('.' < 'Z'), so the rows written without a fraction are padded to the same width.
349
+ def migrate_times_to_microseconds
350
+ return if @db.get_first_value("PRAGMA user_version").to_i >= 2
351
+
352
+ @db.transaction do
353
+ %w[started_at finished_at].each do |column|
354
+ @db.execute(<<~SQL)
355
+ UPDATE profiler_profiles
356
+ SET #{column} = substr(#{column}, 1, length(#{column}) - 1) || '.000000Z'
357
+ WHERE #{column} LIKE '____-__-__T__:__:__Z'
358
+ SQL
359
+ end
360
+ @db.execute("PRAGMA user_version = 2")
361
+ end
362
+ end
363
+
346
364
  def row_to_profile(row, load_blobs: true)
347
365
  collectors_meta = parse_json(row["collectors_meta"], {})
348
366
 
@@ -396,12 +414,13 @@ module Profiler
396
414
  nil
397
415
  end
398
416
 
399
- # The times are stored in UTC, all in the same form, for the cleanup and the lists to compare
400
- # them as text; a profile gives them with the offset of the process that recorded it.
417
+ # The times are stored in UTC, all in the same fixed-width form (microseconds, so profiles
418
+ # started within the same second keep their order and their MCP cursor), for the cleanup and
419
+ # the lists to compare them as text; a profile gives them with the offset of the process that recorded it.
401
420
  def utc_iso8601(value)
402
421
  return value if value.nil?
403
422
 
404
- Time.iso8601(value.to_s).utc.iso8601
423
+ Time.iso8601(value.to_s).utc.iso8601(6)
405
424
  rescue ArgumentError
406
425
  value
407
426
  end
@@ -410,7 +429,7 @@ module Profiler
410
429
  def local_iso8601(value)
411
430
  return value if value.nil?
412
431
 
413
- Time.iso8601(value).localtime.iso8601
432
+ Time.iso8601(value).localtime.iso8601(6)
414
433
  rescue ArgumentError
415
434
  value
416
435
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Profiler
4
- VERSION = "0.44.26"
4
+ VERSION = "0.44.27"
5
5
 
6
6
  GEM_ROOT = File.expand_path("../..", __dir__)
7
7
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-profiler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.44.26
4
+ version: 0.44.27
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sébastien Duplessy