Skip to content

Commit 6e69754

Browse files
committed
feat: Record parameter and return value size
1 parent b7f41b1 commit 6e69754

File tree

5 files changed

+11
-2
lines changed

5 files changed

+11
-2
lines changed

lib/appmap/event.rb

+2
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ def build_from_invocation(defined_class, method, receiver, arguments, event: Met
243243
value: display_string(value),
244244
kind: param_type
245245
}.tap do |param|
246+
param[:size] = value.size if value.respond_to?(:size) && value.is_a?(Enumerable)
246247
add_schema param, value
247248
end
248249
end
@@ -308,6 +309,7 @@ def build_from_invocation(parent_id, return_value, exception, elapsed: nil, even
308309
value: display_string(return_value),
309310
object_id: return_value.__id__
310311
}.tap do |param|
312+
param[:size] = return_value.size if return_value.respond_to?(:size) && return_value.is_a?(Enumerable)
311313
add_schema param, return_value, always: parameter_schema
312314
end
313315
end

spec/handler/eval_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def record_block
3232
expect(events[0]).to match hash_including \
3333
defined_class: 'Kernel',
3434
method_id: 'eval',
35-
parameters: [{ class: 'Array', kind: :rest, name: 'arg', value: '[12]' }]
35+
parameters: [{ class: 'Array', kind: :rest, name: 'arg', size: 1, value: '[12]' }]
3636
end
3737

3838
# a la Ruby 2.6.3 ruby-token.rb

spec/hook_spec.rb

+5
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,7 @@ def test_hook_behavior(file, events_yaml, setup: nil, &block)
491491
:class: Array
492492
:value: "[4, 5]"
493493
:kind: :rest
494+
:size: 2
494495
- :name: :kw1
495496
:class: String
496497
:value: one
@@ -503,6 +504,7 @@ def test_hook_behavior(file, events_yaml, setup: nil, &block)
503504
:class: Hash
504505
:value: "{:kw3=>:three}"
505506
:kind: :keyrest
507+
:size: 1
506508
:receiver:
507509
:class: InstanceMethod
508510
:value: Instance Method fixture
@@ -1139,6 +1141,7 @@ def secure_compare(a, b)
11391141
:class: Array
11401142
:value: "[foo]"
11411143
:kind: :rest
1144+
:size: 1
11421145
- :name: :kw1
11431146
:class: String
11441147
:value: kw1
@@ -1151,6 +1154,7 @@ def secure_compare(a, b)
11511154
:class: Hash
11521155
:value: "{}"
11531156
:kind: :keyrest
1157+
:size: 0
11541158
:receiver:
11551159
:class: ReportParameters
11561160
:value: ReportParameters
@@ -1160,6 +1164,7 @@ def secure_compare(a, b)
11601164
:return_value:
11611165
:class: Array
11621166
:value: "[[:rest, :args], [:keyreq, :kw1], [:key, :kw2], [:keyrest, :kws]]"
1167+
:size: 4
11631168
YAML
11641169
parameters = [[:rest, :args], [:keyreq, :kw1], [:key, :kw2], [:keyrest, :kws]]
11651170
test_hook_behavior 'spec/fixtures/hook/report_parameters.rb', events do

spec/rails_recording_spec.rb

+1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ def rails_versions
7373
'name' => 'params',
7474
'class' => 'ActiveSupport::HashWithIndifferentAccess',
7575
'object_id' => Integer,
76+
'size' => 1,
7677
'value' => '{login=>alice}',
7778
'kind' => 'req'
7879
),

test/expectations/openssl_test_key_sign2-3.1.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
"name": "arg",
2727
"class": "Array",
2828
"value": "[e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855, the document]",
29-
"kind": "rest"
29+
"kind": "rest",
30+
"size": 2
3031
}
3132
],
3233
"receiver": {

0 commit comments

Comments
 (0)