@@ -29,11 +29,31 @@ def build_from_invocation(event_type, event:)
29
29
30
30
# Gets a display string for a value. This is not meant to be a machine deserializable value.
31
31
def display_string ( value )
32
- return nil unless value
32
+ return nil if value . equal? ( nil )
33
33
34
+ # With setting APPMAP_PROFILE_DISPLAY_STRING, stringifying this class is shown to take 9 seconds(!) of a 17 second test run.
35
+ return nil if best_class_name ( value ) == 'ActiveSupport::Callbacks::Filters::Environment'
36
+
37
+ if @times . nil? && ENV [ 'APPMAP_PROFILE_DISPLAY_STRING' ] == 'true'
38
+ @times = Hash . new { |memo , key | memo [ key ] = 0 }
39
+ Thread . new do
40
+ sleep 0.5
41
+ while true
42
+ warn @times . to_a . sort { |a , b | b [ 1 ] <=> a [ 1 ] } [ 0 ..9 ] . join ( "\n " )
43
+ sleep 3
44
+ end
45
+ end
46
+ end
47
+
48
+ start = Time . now
34
49
value_string = custom_display_string ( value ) || default_display_string ( value )
35
50
36
- ( value_string ||'' ) [ 0 ...LIMIT ] . encode ( 'utf-8' , invalid : :replace , undef : :replace , replace : '_' )
51
+ if @times
52
+ elapsed = Time . now - start
53
+ @times [ best_class_name ( value ) ] += elapsed
54
+ end
55
+
56
+ encode_dislay_string ( value_string )
37
57
end
38
58
39
59
def object_properties ( hash_like )
@@ -57,8 +77,16 @@ def best_class_name(value)
57
77
value_cls . name
58
78
end
59
79
80
+ def encode_dislay_string ( value )
81
+ ( value ||'' ) [ 0 ...LIMIT ] . encode ( 'utf-8' , invalid : :replace , undef : :replace , replace : '_' )
82
+ end
83
+
60
84
def custom_display_string ( value )
61
85
case value
86
+ when NilClass , TrueClass , FalseClass , Numeric , Time , Date
87
+ value . to_s
88
+ when String
89
+ value [ 0 ...LIMIT ] . encode ( 'utf-8' , invalid : :replace , undef : :replace , replace : '_' )
62
90
when File
63
91
"#{ value . class } [path=#{ value . path } ]"
64
92
when Net ::HTTP
@@ -71,6 +99,8 @@ def custom_display_string(value)
71
99
end
72
100
73
101
def default_display_string ( value )
102
+ return nil if ENV [ 'APPMAP_OBJECT_STRING' ] == 'false'
103
+
74
104
last_resort_string = lambda do
75
105
warn "AppMap encountered an error inspecting a #{ value . class . name } : #{ $!. message } "
76
106
'*Error inspecting variable*'
0 commit comments