trace_viz 0.0.1 → 0.0.2
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 +4 -4
- data/CONTRIBUTING.md +34 -0
- data/README.md +130 -38
- data/examples/example.cast +285 -0
- data/examples/example.rb +94 -23
- data/lib/trace_viz/adapters/base_adapter.rb +0 -2
- data/lib/trace_viz/adapters/trace_point_adapter.rb +17 -11
- data/lib/trace_viz/collectors/base_collector.rb +83 -0
- data/lib/trace_viz/collectors/depth_manager.rb +37 -0
- data/lib/trace_viz/collectors/evaluators/base_evaluator.rb +23 -0
- data/lib/trace_viz/collectors/evaluators/filter_evaluator.rb +30 -0
- data/lib/trace_viz/collectors/evaluators/hidden_evaluator.rb +21 -0
- data/lib/trace_viz/collectors/filters/base_filter.rb +23 -0
- data/lib/trace_viz/collectors/filters/exclude_classes_filter.rb +28 -0
- data/lib/trace_viz/collectors/filters/exclude_default_classes_filter.rb +38 -0
- data/lib/trace_viz/collectors/filters/exclude_gems_filter.rb +30 -0
- data/lib/trace_viz/collectors/filters/exclude_internal_call_filter.rb +31 -0
- data/lib/trace_viz/collectors/filters/exclude_rails_framework_filter.rb +38 -0
- data/lib/trace_viz/collectors/filters/include_classes_filter.rb +28 -0
- data/lib/trace_viz/collectors/filters/include_gems_filter.rb +54 -0
- data/lib/trace_viz/collectors/filters/registry.rb +59 -0
- data/lib/trace_viz/collectors/matchers/trace_point_action_matcher.rb +36 -0
- data/lib/trace_viz/collectors/matchers/within_depth_matcher.rb +25 -0
- data/lib/trace_viz/collectors/trace_point_collector.rb +51 -0
- data/lib/trace_viz/collectors/trace_stats.rb +21 -0
- data/lib/trace_viz/config/copier.rb +38 -0
- data/lib/trace_viz/config/validator.rb +74 -0
- data/lib/trace_viz/configuration.rb +36 -30
- data/lib/trace_viz/context/config_context.rb +1 -1
- data/lib/trace_viz/context/manager.rb +17 -21
- data/lib/trace_viz/context/map.rb +29 -0
- data/lib/trace_viz/context/registry.rb +37 -0
- data/lib/trace_viz/context/tracking/active_calls.rb +37 -0
- data/lib/trace_viz/context/tracking_context.rb +7 -2
- data/lib/trace_viz/context.rb +2 -2
- data/lib/trace_viz/core/tracer.rb +1 -0
- data/lib/trace_viz/defaults.rb +139 -0
- data/lib/trace_viz/exporters/base_exporter.rb +84 -0
- data/lib/trace_viz/exporters/formatters/base_formatter.rb +12 -0
- data/lib/trace_viz/exporters/formatters/method_call_formatter.rb +21 -0
- data/lib/trace_viz/exporters/formatters/method_return_formatter.rb +22 -0
- data/lib/trace_viz/exporters/text_exporter.rb +15 -0
- data/lib/trace_viz/exporters/transformers/base_transformer.rb +25 -0
- data/lib/trace_viz/exporters/transformers/text_transformer.rb +28 -0
- data/lib/trace_viz/formatters/base_formatter.rb +42 -0
- data/lib/trace_viz/formatters/helpers/depth_helper.rb +21 -0
- data/lib/trace_viz/formatters/helpers/indent_helper.rb +15 -0
- data/lib/trace_viz/formatters/helpers/method_details_helper.rb +15 -0
- data/lib/trace_viz/formatters/helpers/params_helper.rb +26 -0
- data/lib/trace_viz/formatters/helpers/result_helper.rb +21 -0
- data/lib/trace_viz/formatters/helpers/source_helper.rb +21 -0
- data/lib/trace_viz/formatters/helpers/time_helper.rb +15 -0
- data/lib/trace_viz/logger.rb +37 -47
- data/lib/trace_viz/loggers/trace_builder.rb +30 -0
- data/lib/trace_viz/loggers/trace_formatters/base_formatter.rb +32 -0
- data/lib/trace_viz/loggers/trace_formatters/method_call_formatter.rb +21 -0
- data/lib/trace_viz/loggers/trace_formatters/method_return_formatter.rb +22 -0
- data/lib/trace_viz/loggers/trace_logger.rb +38 -0
- data/lib/trace_viz/loggers/trace_stats_logger.rb +33 -0
- data/lib/trace_viz/trace_data/base.rb +56 -0
- data/lib/trace_viz/trace_data/trace_point/base.rb +68 -0
- data/lib/trace_viz/trace_data/trace_point/method_call.rb +42 -0
- data/lib/trace_viz/trace_data/trace_point/method_return.rb +25 -0
- data/lib/trace_viz/trace_data/trace_point_builder.rb +23 -0
- data/lib/trace_viz/utils/colorize.rb +12 -23
- data/lib/trace_viz/utils/format_utils.rb +67 -0
- data/lib/trace_viz/version.rb +1 -1
- metadata +58 -13
- data/lib/trace_viz/adapters/trace_point/depth_manager.rb +0 -34
- data/lib/trace_viz/adapters/trace_point/event_handler.rb +0 -36
- data/lib/trace_viz/adapters/trace_point/trace_data.rb +0 -89
- data/lib/trace_viz/adapters/trace_point/trace_formatter.rb +0 -95
- data/lib/trace_viz/adapters/trace_point/trace_logger.rb +0 -44
- data/lib/trace_viz/context/manager/context_map.rb +0 -31
- data/lib/trace_viz/context/manager/context_operations.rb +0 -60
- data/lib/trace_viz/context/manager/context_registry.rb +0 -20
- data/lib/trace_viz/context/manager/context_validation.rb +0 -34
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "base"
|
4
|
+
|
5
|
+
module TraceViz
|
6
|
+
module TraceData
|
7
|
+
module TracePoint
|
8
|
+
class MethodCall < Base
|
9
|
+
attr_reader :params
|
10
|
+
|
11
|
+
def initialize(trace_point)
|
12
|
+
super(trace_point)
|
13
|
+
|
14
|
+
populate_params
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def populate_params
|
20
|
+
@params = extract_params(trace_point.binding)
|
21
|
+
end
|
22
|
+
|
23
|
+
def extract_params(binding)
|
24
|
+
method = binding.eval("method(:#{action})")
|
25
|
+
method.parameters.each_with_object({}) do |(_, name), hash|
|
26
|
+
next unless name
|
27
|
+
next if name.to_s.include?("*") # Skip invalid or special variable names
|
28
|
+
|
29
|
+
value = safe_local_variable_get(binding, name)
|
30
|
+
hash[name] = value
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def safe_local_variable_get(binding, name)
|
35
|
+
binding.local_variable_defined?(name) ? binding.local_variable_get(name) : nil
|
36
|
+
rescue NameError
|
37
|
+
nil
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "base"
|
4
|
+
|
5
|
+
module TraceViz
|
6
|
+
module TraceData
|
7
|
+
module TracePoint
|
8
|
+
class MethodReturn < Base
|
9
|
+
attr_reader :result
|
10
|
+
|
11
|
+
def initialize(trace_point)
|
12
|
+
super(trace_point)
|
13
|
+
|
14
|
+
populate_result
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def populate_result
|
20
|
+
@result = @trace_point.return_value
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "trace_point/method_call"
|
4
|
+
require_relative "trace_point/method_return"
|
5
|
+
|
6
|
+
module TraceViz
|
7
|
+
module TraceData
|
8
|
+
class TracePointBuilder
|
9
|
+
class << self
|
10
|
+
def build(tp)
|
11
|
+
case tp.event
|
12
|
+
when :call
|
13
|
+
TracePoint::MethodCall.new(tp)
|
14
|
+
when :return
|
15
|
+
TracePoint::MethodReturn.new(tp)
|
16
|
+
else
|
17
|
+
raise ArgumentError, "Unsupported TracePoint event: #{tp.event}"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -3,31 +3,20 @@
|
|
3
3
|
module TraceViz
|
4
4
|
module Utils
|
5
5
|
module Colorize
|
6
|
-
ANSI_COLORS = {
|
7
|
-
reset: "\e[0m",
|
8
|
-
black: "\e[30m",
|
9
|
-
red: "\e[31m",
|
10
|
-
green: "\e[32m",
|
11
|
-
yellow: "\e[33m",
|
12
|
-
blue: "\e[34m",
|
13
|
-
magenta: "\e[35m",
|
14
|
-
cyan: "\e[36m",
|
15
|
-
light_gray: "\e[37m",
|
16
|
-
dark_gray: "\e[90m",
|
17
|
-
light_red: "\e[91m",
|
18
|
-
light_green: "\e[92m",
|
19
|
-
light_yellow: "\e[93m",
|
20
|
-
light_blue: "\e[94m",
|
21
|
-
light_magenta: "\e[95m",
|
22
|
-
light_cyan: "\e[96m",
|
23
|
-
white: "\e[97m",
|
24
|
-
}.freeze
|
25
|
-
|
26
6
|
class << self
|
27
|
-
def colorize(text,
|
28
|
-
return text
|
7
|
+
def colorize(text, *styles)
|
8
|
+
return text if text.nil? || styles.empty?
|
9
|
+
|
10
|
+
"#{build_color_sequence(styles)}#{text}#{Defaults.colors[:reset]}"
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
29
14
|
|
30
|
-
|
15
|
+
def build_color_sequence(styles)
|
16
|
+
styles
|
17
|
+
.map { |style| Defaults.colors[style] }
|
18
|
+
.compact
|
19
|
+
.join
|
31
20
|
end
|
32
21
|
end
|
33
22
|
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module TraceViz
|
4
|
+
module Utils
|
5
|
+
module FormatUtils
|
6
|
+
class << self
|
7
|
+
# Formats a hash or array of key-value pairs based on the specified mode
|
8
|
+
def format_key_value_pairs(data, mode)
|
9
|
+
data.map { |key, value| display_mode(mode).call(key, value) }.join(", ")
|
10
|
+
end
|
11
|
+
|
12
|
+
# Determines how key-value pairs are displayed based on the mode
|
13
|
+
def display_mode(mode)
|
14
|
+
{
|
15
|
+
name_and_value: ->(name, value) { "#{name}: #{value}" },
|
16
|
+
name_only: ->(name, _) { name.to_s },
|
17
|
+
value_only: ->(_, value) { value },
|
18
|
+
}.fetch(mode)
|
19
|
+
end
|
20
|
+
|
21
|
+
# Truncates a string or array to the specified length
|
22
|
+
def truncate_value(value, length)
|
23
|
+
return value unless length.is_a?(Integer) && length.positive?
|
24
|
+
|
25
|
+
case value
|
26
|
+
when String
|
27
|
+
truncate_string(value, length)
|
28
|
+
when Array
|
29
|
+
truncate_array(value, length)
|
30
|
+
when Hash
|
31
|
+
truncate_hash(value, length)
|
32
|
+
else
|
33
|
+
truncate_object(value, length)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def truncate_string(string, length)
|
40
|
+
string.length > length ? "#{string[0, length]}..." : string
|
41
|
+
end
|
42
|
+
|
43
|
+
def truncate_array(array, length)
|
44
|
+
truncated_array = array.take(length)
|
45
|
+
truncated_array << "..." if array.size > length
|
46
|
+
truncated_array
|
47
|
+
end
|
48
|
+
|
49
|
+
def truncate_hash(hash, length)
|
50
|
+
keys = hash.keys.take(length)
|
51
|
+
truncated_pairs = keys.map { |key| "#{key}: #{truncate_value(hash[key], length)}" }
|
52
|
+
truncated_pairs << "..." if hash.size > length
|
53
|
+
"{#{truncated_pairs.join(", ")}}"
|
54
|
+
end
|
55
|
+
|
56
|
+
def truncate_object(object, length)
|
57
|
+
object_string = object.inspect
|
58
|
+
if object.is_a?(Hash) || object.is_a?(Array)
|
59
|
+
truncate_value(object, length)
|
60
|
+
else
|
61
|
+
object_string.length > length ? "#{object.class}(#{object_string[0, length]}...)" : object_string
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
data/lib/trace_viz/version.rb
CHANGED
metadata
CHANGED
@@ -1,17 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trace_viz
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Huy Nguyen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-12-
|
11
|
+
date: 2024-12-26 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description:
|
14
|
-
|
13
|
+
description: "TraceViz is a Ruby library designed to trace and visualize events executed
|
14
|
+
\nin a block of code. Useful for debugging and logging. \nDiagram generation is
|
15
|
+
currently under development.\n"
|
15
16
|
email:
|
16
17
|
- patrick204nqh@gmail.com
|
17
18
|
executables: []
|
@@ -24,34 +25,78 @@ files:
|
|
24
25
|
- ".vscode/launch.json"
|
25
26
|
- ".vscode/settings.json"
|
26
27
|
- CODE_OF_CONDUCT.md
|
28
|
+
- CONTRIBUTING.md
|
27
29
|
- LICENSE.txt
|
28
30
|
- README.md
|
29
31
|
- Rakefile
|
32
|
+
- examples/example.cast
|
30
33
|
- examples/example.rb
|
31
34
|
- lib/trace_viz.rb
|
32
35
|
- lib/trace_viz/adapters/base_adapter.rb
|
33
|
-
- lib/trace_viz/adapters/trace_point/depth_manager.rb
|
34
|
-
- lib/trace_viz/adapters/trace_point/event_handler.rb
|
35
|
-
- lib/trace_viz/adapters/trace_point/trace_data.rb
|
36
|
-
- lib/trace_viz/adapters/trace_point/trace_formatter.rb
|
37
|
-
- lib/trace_viz/adapters/trace_point/trace_logger.rb
|
38
36
|
- lib/trace_viz/adapters/trace_point_adapter.rb
|
37
|
+
- lib/trace_viz/collectors/base_collector.rb
|
38
|
+
- lib/trace_viz/collectors/depth_manager.rb
|
39
|
+
- lib/trace_viz/collectors/evaluators/base_evaluator.rb
|
40
|
+
- lib/trace_viz/collectors/evaluators/filter_evaluator.rb
|
41
|
+
- lib/trace_viz/collectors/evaluators/hidden_evaluator.rb
|
42
|
+
- lib/trace_viz/collectors/filters/base_filter.rb
|
43
|
+
- lib/trace_viz/collectors/filters/exclude_classes_filter.rb
|
44
|
+
- lib/trace_viz/collectors/filters/exclude_default_classes_filter.rb
|
45
|
+
- lib/trace_viz/collectors/filters/exclude_gems_filter.rb
|
46
|
+
- lib/trace_viz/collectors/filters/exclude_internal_call_filter.rb
|
47
|
+
- lib/trace_viz/collectors/filters/exclude_rails_framework_filter.rb
|
48
|
+
- lib/trace_viz/collectors/filters/include_classes_filter.rb
|
49
|
+
- lib/trace_viz/collectors/filters/include_gems_filter.rb
|
50
|
+
- lib/trace_viz/collectors/filters/registry.rb
|
51
|
+
- lib/trace_viz/collectors/matchers/trace_point_action_matcher.rb
|
52
|
+
- lib/trace_viz/collectors/matchers/within_depth_matcher.rb
|
53
|
+
- lib/trace_viz/collectors/trace_point_collector.rb
|
54
|
+
- lib/trace_viz/collectors/trace_stats.rb
|
55
|
+
- lib/trace_viz/config/copier.rb
|
56
|
+
- lib/trace_viz/config/validator.rb
|
39
57
|
- lib/trace_viz/configuration.rb
|
40
58
|
- lib/trace_viz/context.rb
|
41
59
|
- lib/trace_viz/context/base_context.rb
|
42
60
|
- lib/trace_viz/context/config_context.rb
|
43
61
|
- lib/trace_viz/context/manager.rb
|
44
|
-
- lib/trace_viz/context/
|
45
|
-
- lib/trace_viz/context/
|
46
|
-
- lib/trace_viz/context/
|
47
|
-
- lib/trace_viz/context/manager/context_validation.rb
|
62
|
+
- lib/trace_viz/context/map.rb
|
63
|
+
- lib/trace_viz/context/registry.rb
|
64
|
+
- lib/trace_viz/context/tracking/active_calls.rb
|
48
65
|
- lib/trace_viz/context/tracking/depth.rb
|
49
66
|
- lib/trace_viz/context/tracking_context.rb
|
50
67
|
- lib/trace_viz/core.rb
|
51
68
|
- lib/trace_viz/core/tracer.rb
|
69
|
+
- lib/trace_viz/defaults.rb
|
52
70
|
- lib/trace_viz/errors.rb
|
71
|
+
- lib/trace_viz/exporters/base_exporter.rb
|
72
|
+
- lib/trace_viz/exporters/formatters/base_formatter.rb
|
73
|
+
- lib/trace_viz/exporters/formatters/method_call_formatter.rb
|
74
|
+
- lib/trace_viz/exporters/formatters/method_return_formatter.rb
|
75
|
+
- lib/trace_viz/exporters/text_exporter.rb
|
76
|
+
- lib/trace_viz/exporters/transformers/base_transformer.rb
|
77
|
+
- lib/trace_viz/exporters/transformers/text_transformer.rb
|
78
|
+
- lib/trace_viz/formatters/base_formatter.rb
|
79
|
+
- lib/trace_viz/formatters/helpers/depth_helper.rb
|
80
|
+
- lib/trace_viz/formatters/helpers/indent_helper.rb
|
81
|
+
- lib/trace_viz/formatters/helpers/method_details_helper.rb
|
82
|
+
- lib/trace_viz/formatters/helpers/params_helper.rb
|
83
|
+
- lib/trace_viz/formatters/helpers/result_helper.rb
|
84
|
+
- lib/trace_viz/formatters/helpers/source_helper.rb
|
85
|
+
- lib/trace_viz/formatters/helpers/time_helper.rb
|
53
86
|
- lib/trace_viz/logger.rb
|
87
|
+
- lib/trace_viz/loggers/trace_builder.rb
|
88
|
+
- lib/trace_viz/loggers/trace_formatters/base_formatter.rb
|
89
|
+
- lib/trace_viz/loggers/trace_formatters/method_call_formatter.rb
|
90
|
+
- lib/trace_viz/loggers/trace_formatters/method_return_formatter.rb
|
91
|
+
- lib/trace_viz/loggers/trace_logger.rb
|
92
|
+
- lib/trace_viz/loggers/trace_stats_logger.rb
|
93
|
+
- lib/trace_viz/trace_data/base.rb
|
94
|
+
- lib/trace_viz/trace_data/trace_point/base.rb
|
95
|
+
- lib/trace_viz/trace_data/trace_point/method_call.rb
|
96
|
+
- lib/trace_viz/trace_data/trace_point/method_return.rb
|
97
|
+
- lib/trace_viz/trace_data/trace_point_builder.rb
|
54
98
|
- lib/trace_viz/utils/colorize.rb
|
99
|
+
- lib/trace_viz/utils/format_utils.rb
|
55
100
|
- lib/trace_viz/version.rb
|
56
101
|
- sig/trace_viz.rbs
|
57
102
|
homepage: https://github.com/patrick204nqh/trace_viz
|
@@ -1,34 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module TraceViz
|
4
|
-
module Adapters
|
5
|
-
module TracePoint
|
6
|
-
class DepthManager
|
7
|
-
def initialize(trace_data)
|
8
|
-
@trace_data = trace_data
|
9
|
-
@context = Context.for(:tracking)
|
10
|
-
end
|
11
|
-
|
12
|
-
def assign_depth
|
13
|
-
context_depth = context&.depth
|
14
|
-
return 0 unless context_depth
|
15
|
-
|
16
|
-
case trace_data.event
|
17
|
-
when :call
|
18
|
-
current_depth = context_depth.current || 0
|
19
|
-
context_depth.increment
|
20
|
-
current_depth
|
21
|
-
when :return
|
22
|
-
context_depth.decrement
|
23
|
-
else
|
24
|
-
0 # Disables depth tracking for other events
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
private
|
29
|
-
|
30
|
-
attr_reader :trace_data, :context
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module TraceViz
|
4
|
-
module Adapters
|
5
|
-
module TracePoint
|
6
|
-
class EventHandler
|
7
|
-
def initialize(trace_data)
|
8
|
-
@trace_data = trace_data
|
9
|
-
end
|
10
|
-
|
11
|
-
def handle
|
12
|
-
case trace_data.event
|
13
|
-
when :call
|
14
|
-
handle_call
|
15
|
-
when :return
|
16
|
-
handle_return
|
17
|
-
else
|
18
|
-
raise AdapterError, "Unknown event type #{trace_data.event}"
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
private
|
23
|
-
|
24
|
-
attr_reader :trace_data
|
25
|
-
|
26
|
-
def handle_call
|
27
|
-
trace_data.log_trace
|
28
|
-
end
|
29
|
-
|
30
|
-
def handle_return
|
31
|
-
trace_data.log_trace
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
@@ -1,89 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "trace_viz/adapters/trace_point/depth_manager"
|
4
|
-
|
5
|
-
module TraceViz
|
6
|
-
module Adapters
|
7
|
-
module TracePoint
|
8
|
-
class TraceData
|
9
|
-
attr_reader :trace_point, :config, :timestamp, :depth
|
10
|
-
|
11
|
-
def initialize(trace_point)
|
12
|
-
@trace_point = trace_point
|
13
|
-
@config = Context.for(:config).configuration
|
14
|
-
@logger = TraceLogger.new(self)
|
15
|
-
@depth_manager = DepthManager.new(self)
|
16
|
-
|
17
|
-
record_timestamp
|
18
|
-
assign_depth
|
19
|
-
end
|
20
|
-
|
21
|
-
def id
|
22
|
-
trace_point.method_id
|
23
|
-
end
|
24
|
-
|
25
|
-
def event
|
26
|
-
trace_point.event
|
27
|
-
end
|
28
|
-
|
29
|
-
def path
|
30
|
-
trace_point.path
|
31
|
-
end
|
32
|
-
|
33
|
-
def line_number
|
34
|
-
trace_point.lineno
|
35
|
-
end
|
36
|
-
|
37
|
-
def klass
|
38
|
-
trace_point.defined_class
|
39
|
-
end
|
40
|
-
|
41
|
-
def params
|
42
|
-
trace_point.binding.local_variables
|
43
|
-
end
|
44
|
-
|
45
|
-
def result
|
46
|
-
trace_point.return_value
|
47
|
-
end
|
48
|
-
|
49
|
-
def internal_call?
|
50
|
-
internal_path? || internal_class?
|
51
|
-
end
|
52
|
-
|
53
|
-
def exceeded_max_depth?
|
54
|
-
return false unless config.max_display_depth
|
55
|
-
|
56
|
-
depth > config.max_display_depth
|
57
|
-
end
|
58
|
-
|
59
|
-
def duration
|
60
|
-
# TODO: Implement duration calculation
|
61
|
-
end
|
62
|
-
|
63
|
-
def log_trace
|
64
|
-
logger.log_trace
|
65
|
-
end
|
66
|
-
|
67
|
-
private
|
68
|
-
|
69
|
-
attr_reader :logger, :depth_manager
|
70
|
-
|
71
|
-
def internal_path?
|
72
|
-
path.include?("<internal:")
|
73
|
-
end
|
74
|
-
|
75
|
-
def internal_class?
|
76
|
-
klass.to_s.start_with?("TracePoint")
|
77
|
-
end
|
78
|
-
|
79
|
-
def record_timestamp
|
80
|
-
@timestamp = Time.now
|
81
|
-
end
|
82
|
-
|
83
|
-
def assign_depth
|
84
|
-
@depth = @depth_manager.assign_depth
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
@@ -1,95 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "trace_viz/utils/colorize"
|
4
|
-
|
5
|
-
module TraceViz
|
6
|
-
module Adapters
|
7
|
-
module TracePoint
|
8
|
-
class TraceFormatter
|
9
|
-
def initialize(trace_data)
|
10
|
-
@trace_data = trace_data
|
11
|
-
@config = @trace_data.config
|
12
|
-
@logger = TraceViz.logger
|
13
|
-
end
|
14
|
-
|
15
|
-
def format_call
|
16
|
-
return "" if trace_data.exceeded_max_depth?
|
17
|
-
|
18
|
-
[
|
19
|
-
indent_if_enabled,
|
20
|
-
colorize(depth_if_enabled, :blue),
|
21
|
-
colorize(method_name_if_enabled, :light_green),
|
22
|
-
colorize(source_location_if_enabled, :dark_gray),
|
23
|
-
colorize(params_if_enabled, :yellow),
|
24
|
-
].compact.join(" ")
|
25
|
-
end
|
26
|
-
|
27
|
-
def format_return
|
28
|
-
return "" if trace_data.exceeded_max_depth?
|
29
|
-
|
30
|
-
[
|
31
|
-
indent_if_enabled,
|
32
|
-
colorize(depth_if_enabled, :blue),
|
33
|
-
colorize(method_name_if_enabled, :light_green),
|
34
|
-
colorize(result_if_enabled, :cyan),
|
35
|
-
colorize(source_location_if_enabled, :dark_gray),
|
36
|
-
colorize(execution_time_if_enabled, :red),
|
37
|
-
].compact.join(" ")
|
38
|
-
end
|
39
|
-
|
40
|
-
private
|
41
|
-
|
42
|
-
attr_reader :trace_data, :config, :logger
|
43
|
-
|
44
|
-
def indent_if_enabled
|
45
|
-
return unless config.show_indent && config.show_depth
|
46
|
-
|
47
|
-
" " * (config.tab_size * trace_data.depth)
|
48
|
-
end
|
49
|
-
|
50
|
-
def depth_if_enabled
|
51
|
-
return unless config.show_depth
|
52
|
-
|
53
|
-
"#depth:#{trace_data.depth}"
|
54
|
-
end
|
55
|
-
|
56
|
-
def method_name_if_enabled
|
57
|
-
return unless config.show_method_name
|
58
|
-
|
59
|
-
"#{trace_data.klass}##{trace_data.id}"
|
60
|
-
end
|
61
|
-
|
62
|
-
def source_location_if_enabled
|
63
|
-
return unless config.show_source_location
|
64
|
-
|
65
|
-
"at #{trace_data.path}:#{trace_data.line_number}"
|
66
|
-
end
|
67
|
-
|
68
|
-
def params_if_enabled
|
69
|
-
return unless config.show_params
|
70
|
-
|
71
|
-
param_values = trace_data.params.map do |var|
|
72
|
-
trace_data.trace_point.binding.local_variable_get(var).inspect
|
73
|
-
end.join(", ")
|
74
|
-
"(#{param_values})"
|
75
|
-
end
|
76
|
-
|
77
|
-
def result_if_enabled
|
78
|
-
return unless config.show_return_value
|
79
|
-
|
80
|
-
"#=> #{trace_data.result.inspect}"
|
81
|
-
end
|
82
|
-
|
83
|
-
def execution_time_if_enabled
|
84
|
-
return unless config.show_execution_time && trace_data.duration
|
85
|
-
|
86
|
-
"in #{trace_data.duration}ms"
|
87
|
-
end
|
88
|
-
|
89
|
-
def colorize(text, color_key)
|
90
|
-
Utils::Colorize.colorize(text, color_key)
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
@@ -1,44 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module TraceViz
|
4
|
-
module Adapters
|
5
|
-
module TracePoint
|
6
|
-
class TraceLogger
|
7
|
-
def initialize(trace_data)
|
8
|
-
@trace_data = trace_data
|
9
|
-
@config = @trace_data.config
|
10
|
-
@formatter = TraceFormatter.new(@trace_data)
|
11
|
-
end
|
12
|
-
|
13
|
-
def log_trace
|
14
|
-
return unless should_log?
|
15
|
-
|
16
|
-
case trace_data.event
|
17
|
-
when :call
|
18
|
-
log_call
|
19
|
-
when :return
|
20
|
-
log_return
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
private
|
25
|
-
|
26
|
-
attr_reader :trace_data, :config, :formatter
|
27
|
-
|
28
|
-
def log_call
|
29
|
-
formatted_call = formatter.format_call
|
30
|
-
TraceViz.logger.start(formatted_call)
|
31
|
-
end
|
32
|
-
|
33
|
-
def log_return
|
34
|
-
formatted_return = formatter.format_return
|
35
|
-
TraceViz.logger.finish(formatted_return)
|
36
|
-
end
|
37
|
-
|
38
|
-
def should_log?
|
39
|
-
config.show_trace_events.include?(trace_data.event)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module TraceViz
|
4
|
-
module Context
|
5
|
-
class Manager
|
6
|
-
module ContextMap
|
7
|
-
def get_context(key)
|
8
|
-
validate_key!(key)
|
9
|
-
@context_map[key]
|
10
|
-
end
|
11
|
-
|
12
|
-
def clear
|
13
|
-
@context_map.clear
|
14
|
-
end
|
15
|
-
|
16
|
-
def empty?
|
17
|
-
@context_map.empty?
|
18
|
-
end
|
19
|
-
|
20
|
-
def all_contexts
|
21
|
-
@context_map.map do |key, context|
|
22
|
-
{
|
23
|
-
key: key,
|
24
|
-
context: context,
|
25
|
-
}
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|