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.
Files changed (77) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +34 -0
  3. data/README.md +130 -38
  4. data/examples/example.cast +285 -0
  5. data/examples/example.rb +94 -23
  6. data/lib/trace_viz/adapters/base_adapter.rb +0 -2
  7. data/lib/trace_viz/adapters/trace_point_adapter.rb +17 -11
  8. data/lib/trace_viz/collectors/base_collector.rb +83 -0
  9. data/lib/trace_viz/collectors/depth_manager.rb +37 -0
  10. data/lib/trace_viz/collectors/evaluators/base_evaluator.rb +23 -0
  11. data/lib/trace_viz/collectors/evaluators/filter_evaluator.rb +30 -0
  12. data/lib/trace_viz/collectors/evaluators/hidden_evaluator.rb +21 -0
  13. data/lib/trace_viz/collectors/filters/base_filter.rb +23 -0
  14. data/lib/trace_viz/collectors/filters/exclude_classes_filter.rb +28 -0
  15. data/lib/trace_viz/collectors/filters/exclude_default_classes_filter.rb +38 -0
  16. data/lib/trace_viz/collectors/filters/exclude_gems_filter.rb +30 -0
  17. data/lib/trace_viz/collectors/filters/exclude_internal_call_filter.rb +31 -0
  18. data/lib/trace_viz/collectors/filters/exclude_rails_framework_filter.rb +38 -0
  19. data/lib/trace_viz/collectors/filters/include_classes_filter.rb +28 -0
  20. data/lib/trace_viz/collectors/filters/include_gems_filter.rb +54 -0
  21. data/lib/trace_viz/collectors/filters/registry.rb +59 -0
  22. data/lib/trace_viz/collectors/matchers/trace_point_action_matcher.rb +36 -0
  23. data/lib/trace_viz/collectors/matchers/within_depth_matcher.rb +25 -0
  24. data/lib/trace_viz/collectors/trace_point_collector.rb +51 -0
  25. data/lib/trace_viz/collectors/trace_stats.rb +21 -0
  26. data/lib/trace_viz/config/copier.rb +38 -0
  27. data/lib/trace_viz/config/validator.rb +74 -0
  28. data/lib/trace_viz/configuration.rb +36 -30
  29. data/lib/trace_viz/context/config_context.rb +1 -1
  30. data/lib/trace_viz/context/manager.rb +17 -21
  31. data/lib/trace_viz/context/map.rb +29 -0
  32. data/lib/trace_viz/context/registry.rb +37 -0
  33. data/lib/trace_viz/context/tracking/active_calls.rb +37 -0
  34. data/lib/trace_viz/context/tracking_context.rb +7 -2
  35. data/lib/trace_viz/context.rb +2 -2
  36. data/lib/trace_viz/core/tracer.rb +1 -0
  37. data/lib/trace_viz/defaults.rb +139 -0
  38. data/lib/trace_viz/exporters/base_exporter.rb +84 -0
  39. data/lib/trace_viz/exporters/formatters/base_formatter.rb +12 -0
  40. data/lib/trace_viz/exporters/formatters/method_call_formatter.rb +21 -0
  41. data/lib/trace_viz/exporters/formatters/method_return_formatter.rb +22 -0
  42. data/lib/trace_viz/exporters/text_exporter.rb +15 -0
  43. data/lib/trace_viz/exporters/transformers/base_transformer.rb +25 -0
  44. data/lib/trace_viz/exporters/transformers/text_transformer.rb +28 -0
  45. data/lib/trace_viz/formatters/base_formatter.rb +42 -0
  46. data/lib/trace_viz/formatters/helpers/depth_helper.rb +21 -0
  47. data/lib/trace_viz/formatters/helpers/indent_helper.rb +15 -0
  48. data/lib/trace_viz/formatters/helpers/method_details_helper.rb +15 -0
  49. data/lib/trace_viz/formatters/helpers/params_helper.rb +26 -0
  50. data/lib/trace_viz/formatters/helpers/result_helper.rb +21 -0
  51. data/lib/trace_viz/formatters/helpers/source_helper.rb +21 -0
  52. data/lib/trace_viz/formatters/helpers/time_helper.rb +15 -0
  53. data/lib/trace_viz/logger.rb +37 -47
  54. data/lib/trace_viz/loggers/trace_builder.rb +30 -0
  55. data/lib/trace_viz/loggers/trace_formatters/base_formatter.rb +32 -0
  56. data/lib/trace_viz/loggers/trace_formatters/method_call_formatter.rb +21 -0
  57. data/lib/trace_viz/loggers/trace_formatters/method_return_formatter.rb +22 -0
  58. data/lib/trace_viz/loggers/trace_logger.rb +38 -0
  59. data/lib/trace_viz/loggers/trace_stats_logger.rb +33 -0
  60. data/lib/trace_viz/trace_data/base.rb +56 -0
  61. data/lib/trace_viz/trace_data/trace_point/base.rb +68 -0
  62. data/lib/trace_viz/trace_data/trace_point/method_call.rb +42 -0
  63. data/lib/trace_viz/trace_data/trace_point/method_return.rb +25 -0
  64. data/lib/trace_viz/trace_data/trace_point_builder.rb +23 -0
  65. data/lib/trace_viz/utils/colorize.rb +12 -23
  66. data/lib/trace_viz/utils/format_utils.rb +67 -0
  67. data/lib/trace_viz/version.rb +1 -1
  68. metadata +58 -13
  69. data/lib/trace_viz/adapters/trace_point/depth_manager.rb +0 -34
  70. data/lib/trace_viz/adapters/trace_point/event_handler.rb +0 -36
  71. data/lib/trace_viz/adapters/trace_point/trace_data.rb +0 -89
  72. data/lib/trace_viz/adapters/trace_point/trace_formatter.rb +0 -95
  73. data/lib/trace_viz/adapters/trace_point/trace_logger.rb +0 -44
  74. data/lib/trace_viz/context/manager/context_map.rb +0 -31
  75. data/lib/trace_viz/context/manager/context_operations.rb +0 -60
  76. data/lib/trace_viz/context/manager/context_registry.rb +0 -20
  77. data/lib/trace_viz/context/manager/context_validation.rb +0 -34
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dad6986e31d5fab4d42a7e6820086bd39ad16d3dd7461b483425d06122533d56
4
- data.tar.gz: ca9411d76b1134ad5e676264771e7046a6e52fbe250040f61c5b3294071d2578
3
+ metadata.gz: 33ae44f03b5cb5a5e546e27adf7d71e4100adb014659122b51ead6c185203b48
4
+ data.tar.gz: 712c78b3b7cd93f7512fa7f25a1bcf0a3424b45819ec52ae80c4a9b480385282
5
5
  SHA512:
6
- metadata.gz: c66ab56494adc950558f5e9f21f8630178a262443440d70799ee43284ad03b0615e1031df8f24d495b9970b054c841c057d1858e629e5216c05c35a7485071b6
7
- data.tar.gz: c30a273a89fa59c417e3974056916f135083ad50320dbb18c063b3db0c365231bb09118611770e1a158435997733101e9a917026245936ece186c73a7e9fcf71
6
+ metadata.gz: 178cd46ddd00503c6a7783d8697d7d90dfccb15980e3af6b0f8cdb39999809f4e5f0d541bb9809414149c1c0984ebaff485aa634b42b47aee2f2b1615b2d9cef
7
+ data.tar.gz: d61a9e82387c176eb31e06651c894ff3113924bcee1eaef10d23d47355f3eca3363165a6d63cb222c57aa0db908f4557c56e24c295496088c1213113fae14857
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,34 @@
1
+ # Contributing to TraceViz
2
+
3
+ Thank you for your interest in improving TraceViz! 🎉
4
+
5
+ ## Development Setup
6
+
7
+ 1. Fork and clone the repository.
8
+ 2. Run `bundle install` to install dependencies.
9
+ 3. Make your changes.
10
+ 4. Run `bin/rspec` to ensure all tests pass.
11
+ 5. Submit a Pull Request with a clear description.
12
+
13
+ ## Coding Standards
14
+
15
+ - Follow the [Ruby Style Guide](https://github.com/rubocop/ruby-style-guide).
16
+ - Write clear and descriptive commit messages.
17
+
18
+ ## Tests
19
+
20
+ - All new functionality must be covered by tests.
21
+ - Run `bin/rspec` before pushing changes.
22
+ - Ensure 100% passing tests on CI.
23
+
24
+ ## Documentation
25
+
26
+ - Update `README.md` if your changes affect usage.
27
+ - Consider adding examples or improving existing ones.
28
+
29
+ ## Code of Conduct
30
+
31
+ - Please be respectful and supportive of others.
32
+ - Refer to [CODE_OF_CONDUCT.md](./CODE_OF_CONDUCT.md) for details.
33
+
34
+ Thank you for making TraceViz better! 🚀
data/README.md CHANGED
@@ -6,7 +6,15 @@
6
6
  [![Maintainability](https://api.codeclimate.com/v1/badges/e97579abe66f3477e71d/maintainability)](https://codeclimate.com/github/patrick204nqh/trace_viz/maintainability)
7
7
  ![License](https://img.shields.io/github/license/patrick204nqh/trace_viz)
8
8
 
9
- TraceViz is a Ruby library designed to trace and visualize events executed in a block of code. It is useful for logging, debugging, and generating diagrams to understand code execution and flow. The gem allows you to customize how much detail you want to see, such as method calls, parameters, return values, and execution times.
9
+ TraceViz is a Ruby library designed to trace and visualize events executed in a block of code. It is useful for logging, debugging, and generating diagrams to understand code execution and flow.
10
+
11
+ > **Note:** The diagram generation feature is currently under development.
12
+
13
+ The gem allows you to customize how much detail you want to see, such as method calls, parameters, return values, and execution times.
14
+
15
+ ## Demo
16
+
17
+ [![asciicast](https://asciinema.org/a/pKjqLFNPxQFQWucTzcGMpt6QE.svg)](https://asciinema.org/a/pKjqLFNPxQFQWucTzcGMpt6QE)
10
18
 
11
19
  ## Installation
12
20
 
@@ -32,24 +40,55 @@ gem install trace_viz
32
40
 
33
41
  Wrap your code inside the TraceViz.trace block to start tracing its execution. The tracing behavior can be customized using various options:
34
42
 
43
+ <details>
44
+ <summary>Configuration Example</summary>
45
+
35
46
  ```ruby
36
47
  TraceViz.trace(
37
- tab_size: 2,
38
- show_indent: true,
39
- show_depth: true,
40
- max_display_depth: 4, # Recommended to keep this value between 3 and 5
41
- show_method_name: true,
42
- show_source_location: false,
43
- show_params: true,
44
- show_return_value: true,
45
- show_execution_time: true,
46
- show_trace_events: [:call, :return]
48
+ general: {
49
+ tab_size: 4,
50
+ show_indent: true,
51
+ show_depth: true,
52
+ max_display_depth: 3,
53
+ show_method_name: true,
54
+ },
55
+ source_location: {
56
+ show: false,
57
+ truncate_length: 100,
58
+ },
59
+ params: {
60
+ show: true,
61
+ mode: :name_and_value,
62
+ truncate_values: 50,
63
+ },
64
+ result: {
65
+ show: true,
66
+ truncate_length: 50,
67
+ },
68
+ execution: {
69
+ show_time: true,
70
+ show_trace_events: [:call, :return],
71
+ },
72
+ filters: [
73
+ :exclude_internal_call,
74
+ :exclude_default_classes,
75
+ ...
76
+ ],
77
+ export: {
78
+ enabled: true,
79
+ path: "tmp",
80
+ format: :txt,
81
+ overwrite: false,
82
+ }
47
83
  ) do
48
84
  # Your code here
49
85
  end
50
86
  ```
51
87
 
52
- **Example**
88
+ </details>
89
+
90
+ <details>
91
+ <summary>Example Code</summary>
53
92
 
54
93
  ```ruby
55
94
  class Example
@@ -77,27 +116,56 @@ class Example
77
116
  end
78
117
 
79
118
  TraceViz.trace(
119
+ general: {
80
120
  tab_size: 4,
81
121
  show_indent: true,
82
122
  show_depth: true,
83
123
  max_display_depth: 3,
84
124
  show_method_name: true,
85
- show_source_location: false,
86
- show_params: true,
87
- show_return_value: true,
88
- show_execution_time: true,
89
- show_trace_events: [:call, :return]
125
+ },
126
+ source_location: {
127
+ show: false,
128
+ truncate_length: 100,
129
+ },
130
+ params: {
131
+ show: true,
132
+ mode: :name_and_value,
133
+ truncate_values: 50,
134
+ },
135
+ result: {
136
+ show: true,
137
+ truncate_length: 50,
138
+ },
139
+ execution: {
140
+ show_time: true,
141
+ show_trace_events: [:call, :return],
142
+ },
143
+ filters: [
144
+ :exclude_internal_call,
145
+ include_classes: [Example]
146
+ ],
147
+ export: {
148
+ enabled: true,
149
+ path: "tmp",
150
+ format: :txt,
151
+ overwrite: false,
152
+ }
90
153
  ) do
91
154
  example = Example.new
92
155
  example.perform_task(5, 7)
93
156
  end
94
157
  ```
95
158
 
159
+ </details>
160
+
96
161
  **Output**
97
162
 
163
+ <details>
164
+ <summary>Sample Output</summary>
165
+
98
166
  ```bash
99
- 🚀 [START] #depth:0 Example#perform_task (5, 7, nil)
100
- 🚀 [START] #depth:1 Example#add_numbers (5, 7, nil)
167
+ 🚀 [START] #depth:0 Example#perform_task (5, 7)
168
+ 🚀 [START] #depth:1 Example#add_numbers (5, 7)
101
169
  🚀 [START] #depth:2 Example#multiply_by_factor (12, 2)
102
170
  🏁 [FINISH] #depth:2 Example#multiply_by_factor #=> 24
103
171
  🏁 [FINISH] #depth:1 Example#add_numbers #=> 24
@@ -107,22 +175,50 @@ Final result: 24
107
175
  🏁 [FINISH] #depth:0 Example#perform_task #=> 24
108
176
  ```
109
177
 
178
+ </details>
179
+
110
180
  ### Configuration Options
111
181
 
112
- | Option | Type | Description |
113
- | ---------------------- | ---------------- | -------------------------------------------------------------------------------- |
114
- | `tab_size` | Integer | Defines the number of spaces used for indentation when `show_indent` is enabled. |
115
- | `show_indent` | Boolean | Whether to visually indent nested calls. |
116
- | `show_depth` | Boolean | Displays the depth level of the method call. |
117
- | `max_display_depth` | Integer | Limits the display to a maximum depth of calls. |
118
- | `show_method_name` | Boolean | Shows the name of the method being called. |
119
- | `show_source_location` | Boolean | Logs the source file name and line number where the method is defined. |
120
- | `show_params` | Boolean | Logs the parameters passed to the method. |
121
- | `show_return_value` | Boolean | Logs the return value of the method. |
122
- | `show_execution_time` | Boolean | Logs the execution time for methods. |
123
- | `show_trace_events` | Array of Symbols | Specifies the events to trace. Valid values include: |
124
- | | | - `:call` - Log method calls. |
125
- | | | - `:return` - Log method returns. |
182
+ TraceViz provides extensive configuration options to customize tracing behavior.
183
+
184
+ | Group | Option | Type | Default Value | Description |
185
+ | ----------------- | -------------------------- | ---------------- | ------------------ | ----------------------------------------------------------------- |
186
+ | `general` | `tab_size` | Integer | 2 | Number of spaces for indentation. |
187
+ | | `show_indent` | Boolean | true | Enables visual indentation for nested calls. |
188
+ | | `show_depth` | Boolean | true | Displays the depth level of the method call. |
189
+ | | `max_display_depth` | Integer | 3 | Maximum depth of calls to display. |
190
+ | | `show_method_name` | Boolean | true | Logs the name of the method being executed. |
191
+ | `source_location` | `show` | Boolean | false | Logs the source file and line number for methods. |
192
+ | | `truncate_length` | Integer | 100 | Maximum length of displayed source location information. |
193
+ | `params` | `show` | Boolean | true | Logs method parameters. |
194
+ | | `mode` | Symbol | `:name_and_value` | Parameter display mode (`:name`, `:value`, or `:name_and_value`). |
195
+ | | `truncate_values` | Integer | 50 | Maximum length of parameter values to display. |
196
+ | `result` | `show` | Boolean | true | Logs method return values. |
197
+ | | `truncate_length` | Integer | 50 | Maximum length of return value logs. |
198
+ | `execution` | `show_time` | Boolean | true | Logs execution time for methods. |
199
+ | | `show_trace_events` | Array of Symbols | `[:call, :return]` | Specifies the trace events to log (e.g., `:call`, `:return`). |
200
+ | `filters` | `:exclude_internal_call` | Symbol | N/A | Exclude internal Ruby calls. |
201
+ | | `:exclude_default_classes` | Symbol | N/A | Skip logging standard library classes. |
202
+ | | `:exclude_rails_framework` | Symbol | N/A | Ignore Rails framework classes and methods. |
203
+ | | `include_classes` | Hash | N/A | Specify classes to include in tracing. |
204
+ | | - `classes` | Array | [] | List of class names to include (e.g., `["ClassName"]`). |
205
+ | | `exclude_classes` | Hash | N/A | Specify classes to exclude from tracing. |
206
+ | | - `classes` | Array | [] | List of class names to exclude (e.g., `["ClassName"]`). |
207
+ | | `include_gems` | Hash | N/A | Include specific gems or runtime application gems. |
208
+ | | - `app_running` | Boolean | true | Include the code of the application. |
209
+ | | - `app_path` | String | `Dir.pwd` | Path to the application (e.g., `Dir.pwd`). |
210
+ | | - `gems` | Array | [] | List of gems to include (e.g., `["gem1", "gem2"]`). |
211
+ | | `exclude_gems` | Hash | N/A | Exclude specified gems. |
212
+ | | - `gems` | Array | [] | List of gems to exclude (e.g., `["excluded_gem"]`). |
213
+ | `export` | `enabled` | Boolean | true | Enables or disables exporting of trace logs. |
214
+ | | `path` | String | `"tmp"` | Directory for exported trace logs. |
215
+ | | `format` | Symbol | `:txt` | Format for trace logs (`:txt` or other supported formats). |
216
+ | | `overwrite` | Boolean | false | Prevents overwriting of existing exported files. |
217
+
218
+ ### Notes
219
+
220
+ - **Default Skipped Classes**: The following standard library classes are excluded by default when `:exclude_default_classes` is enabled:
221
+ - `Object`, `String`, `Array`, `Hash`, `Numeric`, `Integer`, `Float`, `Symbol`, `Kernel`, `Module`, `Class`, `Range`, `Regexp`.
126
222
 
127
223
  ## Development
128
224
 
@@ -152,7 +248,7 @@ bundle install
152
248
  bin/rspec
153
249
  ```
154
250
 
155
- You can use `irb` or `pry` to test the gem locally. Make your changes, add tests, and ensure all tests pass before submitting a pull request.
251
+ You can use `debug` or `pry` to test the gem locally. Make your changes, add tests, and ensure all tests pass before submitting a pull request.
156
252
 
157
253
  ## Contributing
158
254
 
@@ -161,7 +257,3 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/patric
161
257
  ## License
162
258
 
163
259
  TraceViz is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
164
-
165
- ## Acknowledgements
166
-
167
- Special thanks to the Ruby community for their continued support and inspiration!