lumitrace 0.3.0 → 0.3.1

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: 8ffc13efecd8f5143486eff6929c93bf73aaa3934bf24fa57e906a2f90498e2c
4
- data.tar.gz: df8ce2960f59409dc832d21f9d1df7a2b33cc431fde00c76633f1149a5da3ab3
3
+ metadata.gz: ff34ab7d27bf0d9882368d03a66d0409cb093c5d0850f896e4be79d19a06753d
4
+ data.tar.gz: ec55e6059af4babd1ab074d74b17104a1a6b36e576c55d32a44b4f53a3227855
5
5
  SHA512:
6
- metadata.gz: 2030ec337dc9a941f1c9878b1faa74e15e605a715e1d2049675115573c7c1357d821ded3a200b348521a9593faf6f719ff93766f5ffe1c623d9a9c6dcaa663b1
7
- data.tar.gz: 68564fe5bde3b1d00edd5390211c922b72f3565069446affed3dfdf042fc86491949f8170e175df8cdd99c55b1c05f030adab69fe140ce05cfd003f3f3a51719
6
+ metadata.gz: 26c2710ee8a470ae316541d1d833556a14a19f87d775b88904cd06816c4e192b3dd9c6f9f07811235d4350acb1341c78a8b2e7ef47a7880369871280afe7f0b9
7
+ data.tar.gz: d30d9161e9ab43473004b0a694fe7269aa3255ce9763f746b3233d6e6eebf218b06d885a4913c7401a74de5a23bc425ed5435c6aa91297422dd17ee32d186642
data/README.md CHANGED
@@ -93,7 +93,7 @@ require "lumitrace/enable"
93
93
  - `LUMITRACE_HTML`: enable HTML output; `1` uses the default path, otherwise treats the value as the HTML output path. `0`/`false` disables.
94
94
  - `LUMITRACE_JSON`: enable JSON output; `1` uses the default path, otherwise treats the value as the JSON output path. `0`/`false` disables.
95
95
  - `LUMITRACE_ENABLE`: when `1`/`true`, `require "lumitrace"` will call `Lumitrace.enable!`. When set to a non-boolean string, it is parsed as CLI-style arguments and passed to `enable!`.
96
- - `LUMITRACE_VERBOSE`: when `1`/`true`, prints verbose logs to stderr.
96
+ - `LUMITRACE_VERBOSE`: verbosity level (1-3). `1`/`true` enables basic logs, `2` adds instrumented file names, `3` adds instrumented source output.
97
97
  - `LUMITRACE_RANGE`: semicolon-separated range specs (e.g. `a.rb:1-3,5-6;b.rb`).
98
98
  - `LUMITRACE_RESULTS_DIR`: internal use. Shared results directory for fork/exec merge (default: `Dir.tmpdir/lumitrace_results/<user>_<parent_pid>`).
99
99
  - `LUMITRACE_RESULTS_PARENT_PID`: internal use. Parent PID for fork/exec merge (auto-set).
data/Rakefile CHANGED
@@ -10,3 +10,28 @@ Rake::TestTask.new do |t|
10
10
  end
11
11
 
12
12
  task default: :test
13
+
14
+ require "benchmark"
15
+
16
+ desc "Run simple runtime comparison for lumitrace vs ruby"
17
+ task :bench do
18
+ sample = File.expand_path("bench/bench_sample.rb", __dir__)
19
+ unless File.exist?(sample)
20
+ abort "missing bench/bench_sample.rb"
21
+ end
22
+
23
+ env = {}
24
+ env["N"] = ENV["N"] if ENV["N"]
25
+
26
+ def run_cmd(label, env, cmd)
27
+ t = Benchmark.realtime do
28
+ ok = system(env, *cmd, out: File::NULL, err: File::NULL)
29
+ raise "failed: #{cmd.join(' ')}" unless ok
30
+ end
31
+ puts format("%-12s %8.3fs", label, t)
32
+ end
33
+
34
+ puts "N=#{env['N'] || 1000}"
35
+ run_cmd("ruby", env, ["ruby", sample])
36
+ run_cmd("lumitrace", env, ["./exe/lumitrace", sample])
37
+ end
data/docs/spec.md CHANGED
@@ -43,7 +43,7 @@ Lumitrace instruments Ruby source code at load time (via `RubyVM::InstructionSeq
43
43
  - `text`: boolean or string or nil. When nil, determined from environment variables. When string, uses it as the text output path.
44
44
  - `html`: boolean or string or nil. When nil, determined from environment variables.
45
45
  - `json`: boolean or string or nil. When nil, determined from environment variables.
46
- - `verbose`: boolean or nil. When nil, determined from `LUMITRACE_VERBOSE`.
46
+ - `verbose`: integer (level) or nil. When nil, determined from `LUMITRACE_VERBOSE`.
47
47
  - `at_exit`: boolean. When true, registers output at exit.
48
48
  - Returns: `nil`.
49
49
  - Side effects:
@@ -58,7 +58,7 @@ Lumitrace instruments Ruby source code at load time (via `RubyVM::InstructionSeq
58
58
  - `LUMITRACE_TEXT`: control text output. `1` forces text on, `0`/`false` disables. If unset, text is enabled only when both HTML and JSON are disabled. Any other value is treated as the text output path.
59
59
  - `LUMITRACE_JSON`: enable JSON output; `1` uses the default path, otherwise treats the value as the JSON output path. `0`/`false` disables.
60
60
  - `LUMITRACE_GIT_DIFF_UNTRACKED`: include untracked files in git diff ranges (`1` default). Set to `0` to exclude.
61
- - `LUMITRACE_VERBOSE`: when `1`/`true`, prints verbose logs to stderr.
61
+ - `LUMITRACE_VERBOSE`: verbosity level (1-3). `1`/`true` enables basic logs, `2` adds instrumented file names, `3` adds instrumented source output.
62
62
  - `LUMITRACE_ENABLE`: when `1`/`true`, `require "lumitrace"` will call `Lumitrace.enable!`. When set to a non-boolean string, it is parsed as CLI-style arguments and passed to `enable!`.
63
63
  - `LUMITRACE_RANGE`: semicolon-separated range specs, e.g. `a.rb:1-3,5-6;b.rb`.
64
64
  - `LUMITRACE_RESULTS_DIR`: internal use. Shared results directory for fork/exec merge (default: `Dir.tmpdir/lumitrace_results/<user>_<parent_pid>`).
@@ -115,7 +115,7 @@ Lumitrace instruments Ruby source code at load time (via `RubyVM::InstructionSeq
115
115
 
116
116
  - AST is parsed with Prism.
117
117
  - For each node, if it matches “wrapable” expression classes, injects:
118
- - `RecordInstrument.expr_record(file, start_line, start_col, end_line, end_col, (expr))`
118
+ - `Lumitrace::R(id, (expr))` where `id` maps to location metadata.
119
119
  - Insertions are done by offset to preserve original formatting.
120
120
 
121
121
  ### Range Filtering
@@ -140,7 +140,7 @@ Lumitrace instruments Ruby source code at load time (via `RubyVM::InstructionSeq
140
140
  ## Recording
141
141
 
142
142
  - Results are stored per expression key:
143
- - `(file, start_line, start_col, end_line, end_col)`
143
+ - `id` (an integer assigned at instrumentation time) with a separate `id -> location` table.
144
144
  - Keep only the last N values (`max_values_per_expr`, default 3).
145
145
  - Track `total` count for how many times the expression executed.
146
146
  - Values are stored via `inspect` for non-primitive types.
@@ -190,7 +190,7 @@ lumitrace [options] exec CMD [args...]
190
190
  - `--git-diff-context` expands hunks by +/-N lines.
191
191
  - `--git-cmd` overrides the git executable.
192
192
  - `--git-diff-no-untracked` excludes untracked files (untracked files are included by default).
193
- - `--verbose` prints verbose logs to stderr.
193
+ - `--verbose[=LEVEL]` prints verbose logs to stderr (level 1-3).
194
194
  - `LUMITRACE_VALUES_MAX` sets the default max values per expression.
195
195
  - The CLI launches a child process (Ruby or `exec` target) with `RUBYOPT=-rlumitrace` and `LUMITRACE_*` env vars.
196
196
 
@@ -4,7 +4,7 @@
4
4
  # Supported Syntax
5
5
 
6
6
  Lumitrace instruments Ruby source by wrapping selected expression nodes with
7
- `Lumitrace::RecordInstrument.expr_record(...)`. It does **not** rewrite the
7
+ `Lumitrace::R(id, (expr))`. It does **not** rewrite the
8
8
  entire AST, so coverage is best described as "expressions that are safe to wrap
9
9
  in parentheses and call-position contexts."
10
10
 
data/docs/tutorial.ja.md CHANGED
@@ -7,6 +7,8 @@
7
7
 
8
8
  ## 1. クイックスタート(CLI)
9
9
 
10
+ まずは最小のコマンドで動かして、出力形式の雰囲気を掴みます。
11
+
10
12
  同梱の sample を最小のコマンドで実行します(テキストは stdout に出ます):
11
13
 
12
14
  ```bash
@@ -16,9 +18,18 @@ lumitrace sample/sample.rb
16
18
  プログラム本体の stdout はそのまま出力され、続けて Lumitrace のテキストが表示されます。
17
19
 
18
20
  テキスト出力の形式:
19
- - 各ファイルの見出しは `### path/to/file.rb`。
20
- - 行頭に行番号が付きます(例: ` 12| `)。
21
- - 範囲が飛ぶ場合は `...` の行が入ります。
21
+ - 各ファイルの見出しは次のように表示されます:
22
+ ```
23
+ ### path/to/file.rb
24
+ ```
25
+ - 行頭に行番号が付きます(例):
26
+ ```
27
+ 12|
28
+ ```
29
+ - 範囲が飛ぶ場合は次の行が入ります:
30
+ ```
31
+ ...
32
+ ```
22
33
  - 最終値は `#=> ...` で表示され、複数回実行された場合は `(3rd run)` が付きます。
23
34
 
24
35
  出力例(stdout):
@@ -95,6 +106,8 @@ n0=2, n1=5, n2=11
95
106
 
96
107
  ### ファイルに保存
97
108
 
109
+ 結果をあとで見返したり共有したいときは、テキストと HTML をディスクに書き出すのが便利です。
110
+
98
111
  同梱の sample を実行して、テキストと HTML を保存します:
99
112
 
100
113
  ```bash
@@ -112,6 +125,8 @@ HTML 出力を見る:
112
125
 
113
126
  ### 範囲指定の例
114
127
 
128
+ 出力が多いときは、対象行を絞って読みやすくします。
129
+
115
130
  範囲を指定して、別の出力として保存します:
116
131
 
117
132
  ```bash
@@ -162,18 +177,30 @@ LUMITRACE_HTML=/tmp/out.html lumitrace path/to/entry.rb
162
177
 
163
178
  ### 記録する値の数を減らす
164
179
 
180
+ 出力が長すぎたり読みづらいときに、1 行あたりの記録数を制限します。
181
+
165
182
  ```bash
166
183
  LUMITRACE_VALUES_MAX=5 lumitrace path/to/entry.rb
167
184
  ```
168
185
 
169
186
  ### 行範囲を限定する
170
187
 
188
+ 特定の行だけを明示的に追いたいときの指定です。
189
+
171
190
  ```bash
172
191
  lumitrace --range path/to/entry.rb:10-20,30-35 path/to/entry.rb
173
192
  ```
174
193
 
194
+ 別コマンドをラップするときは、環境変数で range を渡せます(`;` 区切り):
195
+
196
+ ```bash
197
+ LUMITRACE_RANGE="a.rb:1-3,5-6;b.rb" ruby your_script.rb
198
+ ```
199
+
175
200
  ### 差分だけ計測(CLI)
176
201
 
202
+ 変更行だけを自動で追うと、レビュー時のノイズが減ります。
203
+
177
204
  ```bash
178
205
  lumitrace -g path/to/entry.rb
179
206
  lumitrace --git-diff=staged path/to/entry.rb
@@ -190,12 +217,16 @@ lumitrace -g --git-diff-no-untracked path/to/entry.rb
190
217
 
191
218
  ### 詳細ログ
192
219
 
220
+ レンジ計算や動作の理由を追いたいときに有効です。
221
+
193
222
  ```bash
194
223
  lumitrace --verbose path/to/entry.rb
195
224
  ```
196
225
 
197
226
  ### JSON も出力する
198
227
 
228
+ ツール連携や後処理のために JSON を出します。
229
+
199
230
  ```bash
200
231
  lumitrace -j path/to/entry.rb
201
232
  ```
@@ -204,24 +235,32 @@ lumitrace -j path/to/entry.rb
204
235
 
205
236
  ### stdout にテキスト出力
206
237
 
238
+ 端末でさっと確認したいとき向けです。
239
+
207
240
  ```bash
208
241
  lumitrace -t path/to/entry.rb
209
242
  ```
210
243
 
211
244
  ### テキストをファイルに出力
212
245
 
246
+ CI アーティファクトなどに残したいときに便利です。
247
+
213
248
  ```bash
214
249
  lumitrace --text=/tmp/lumi.txt path/to/entry.rb
215
250
  ```
216
251
 
217
252
  ### テキストと HTML を両方出力
218
253
 
254
+ 素早い確認と詳細閲覧を一回で得たいときに使います。
255
+
219
256
  ```bash
220
257
  lumitrace -t -h path/to/entry.rb
221
258
  ```
222
259
 
223
260
  ### exec で実行
224
261
 
262
+ テストなど別コマンドをラップして計測します。
263
+
225
264
  ```bash
226
265
  lumitrace --html=sample/lumitrace_rake.html exec rake
227
266
  ```
@@ -229,18 +268,23 @@ lumitrace --html=sample/lumitrace_rake.html exec rake
229
268
  HTML 出力:
230
269
  - [lumitrace_rake.html](https://ko1.github.io/lumitrace/sample/lumitrace_rake.html)
231
270
 
232
- ### Fork/exec のマージ
271
+ ### GitHub Actions
233
272
 
234
- fork/exec の結果はデフォルトでマージされます。親プロセスが最終出力を行い、子プロセスは `LUMITRACE_RESULTS_DIR` に断片 JSON を保存します。
273
+ CI で差分ログを出し、Pages HTML を共有したいときの導線です。
235
274
 
236
- 環境変数で range を渡す場合(`;` 区切り):
275
+ GitHub Actions への追加手順(`LUMITRACE_GIT_DIFF` や Pages へのアップロード設定を含む)は `sample/sample_project/README.md` を参照してください。公開済み Pages はこちらです:
276
+ [https://ko1.github.io/lumitrace_sample_project/](https://ko1.github.io/lumitrace_sample_project/)
237
277
 
238
- ```bash
239
- LUMITRACE_RANGE="a.rb:1-3,5-6;b.rb" ruby your_script.rb
240
- ```
278
+ ### Fork/exec のマージ
279
+
280
+ プロセスが増える構成のとき、結果がどう合流するかを押さえます。
281
+
282
+ fork/exec の結果はデフォルトでマージされます。親プロセスが最終出力を行い、子プロセスは `LUMITRACE_RESULTS_DIR` に断片 JSON を保存します。
241
283
 
242
284
  ## 2. ライブラリとして使う
243
285
 
286
+ CLI を使わずアプリに組み込みたい場合はここから始めます。
287
+
244
288
  終了時にテキストを出力する設定:
245
289
 
246
290
  ```ruby
@@ -303,10 +347,12 @@ ENV["LUMITRACE_ENABLE"] = "-t --html=/tmp/lumi.html -j"
303
347
  require "lumitrace"
304
348
  ```
305
349
 
306
- exec 先でも読み込まれるように、Lumitrace は `RUBYOPT=-rlumitrace` を設定します。
350
+ exec 先でも読み込まれるように、Lumitrace は `RUBYOPT=-rlumitrace` を設定します。これにより fork/exec の結果をマージできます。
307
351
 
308
352
  ### 出力先を変更する
309
353
 
354
+ 用途に合わせて HTML/JSON/テキストの保存先を変えられます。
355
+
310
356
  ```bash
311
357
  LUMITRACE_HTML=/tmp/lumi.html ruby your_script.rb
312
358
  ```
@@ -320,6 +366,8 @@ Lumitrace.enable!(json: "/tmp/lumi.json")
320
366
 
321
367
  ## 3. 差分だけ計測(git diff)
322
368
 
369
+ ライブラリ側で `git diff` に連動させ、変更行だけを追う方法です。
370
+
323
371
  現在のプログラムファイルに対する `git diff` の範囲だけを有効化します。
324
372
 
325
373
  ```ruby
@@ -334,12 +382,16 @@ LUMITRACE_GIT_DIFF=staged ruby your_script.rb
334
382
 
335
383
  ### 差分前後の行数を広げる
336
384
 
385
+ 前後の文脈も含めたいときに範囲を広げます。
386
+
337
387
  ```bash
338
388
  LUMITRACE_GIT_DIFF_CONTEXT=5 ruby your_script.rb
339
389
  ```
340
390
 
341
391
  ## 4. ルート範囲
342
392
 
393
+ 計測対象のディレクトリ範囲を明確にしたいときに使います。
394
+
343
395
  デフォルトは現在のディレクトリ配下のみ計測します。
344
396
  別のルートを指定したい場合:
345
397
 
@@ -355,5 +407,7 @@ lumitrace --root /path/to/project your_script.rb
355
407
 
356
408
  ## 5. Tips
357
409
 
410
+ 日常的に効く小さなコツをまとめます。
411
+
358
412
  - 出力が大きい場合は `LUMITRACE_VALUES_MAX` を下げると軽くなります。
359
413
  - 1 ファイルだけの確認は `enable_git_diff` が便利です。
data/docs/tutorial.md CHANGED
@@ -7,6 +7,8 @@ This is a short, practical guide to using Lumitrace.
7
7
 
8
8
  ## 1. Quick Start (CLI)
9
9
 
10
+ Start here to see what Lumitrace does in one command and what the default text output looks like.
11
+
10
12
  Run the bundled sample with the simplest command (text output goes to stdout by default):
11
13
 
12
14
  ```bash
@@ -16,9 +18,18 @@ lumitrace sample/sample.rb
16
18
  The program’s own stdout is still printed, and Lumitrace text output follows it.
17
19
 
18
20
  Text output format:
19
- - Each file header is `### path/to/file.rb`.
20
- - Each line is prefixed with a line number like ` 12| `.
21
- - Skipped ranges are shown as a line containing `...`.
21
+ - Each file header is shown like:
22
+ ```
23
+ ### path/to/file.rb
24
+ ```
25
+ - Each line is prefixed with a line number like:
26
+ ```
27
+ 12|
28
+ ```
29
+ - Skipped ranges are shown as:
30
+ ```
31
+ ...
32
+ ```
22
33
  - The last value is shown as `#=> ...` (with `(3rd run)` when run multiple times).
23
34
 
24
35
  Example output (stdout):
@@ -95,6 +106,8 @@ n0=2, n1=5, n2=11
95
106
 
96
107
  ### Save outputs to files
97
108
 
109
+ Use this when you want to keep results for review or share them; it writes text and HTML outputs to disk.
110
+
98
111
  Run the bundled sample and write both text and HTML outputs:
99
112
 
100
113
  ```bash
@@ -112,6 +125,8 @@ View the HTML output:
112
125
 
113
126
  ### Range example
114
127
 
128
+ When a full run is too noisy, narrow the scope to specific line ranges so you can focus on the slice you care about.
129
+
115
130
  Run with ranges and save separate outputs:
116
131
 
117
132
  ```bash
@@ -162,18 +177,30 @@ LUMITRACE_HTML=/tmp/out.html lumitrace path/to/entry.rb
162
177
 
163
178
  ### Limit recorded values
164
179
 
180
+ If the output is too long or slow to scan, cap how many values per line are recorded.
181
+
165
182
  ```bash
166
183
  LUMITRACE_VALUES_MAX=5 lumitrace path/to/entry.rb
167
184
  ```
168
185
 
169
186
  ### Limit to specific lines
170
187
 
188
+ Use `--range` when you want precise control over which lines are traced.
189
+
171
190
  ```bash
172
191
  lumitrace --range path/to/entry.rb:10-20,30-35 path/to/entry.rb
173
192
  ```
174
193
 
194
+ You can also pass ranges via env (semicolon-separated) when wrapping another command:
195
+
196
+ ```bash
197
+ LUMITRACE_RANGE="a.rb:1-3,5-6;b.rb" ruby your_script.rb
198
+ ```
199
+
175
200
  ### Diff-based ranges
176
201
 
202
+ Let Git choose the interesting lines by tracing only changes from `git diff`; this keeps review noise low.
203
+
177
204
  ```bash
178
205
  lumitrace -g path/to/entry.rb
179
206
  lumitrace --git-diff=staged path/to/entry.rb
@@ -190,12 +217,16 @@ lumitrace -g --git-diff-no-untracked path/to/entry.rb
190
217
 
191
218
  ### Verbose logs
192
219
 
220
+ Turn this on when you need to understand how ranges were computed or why a line was (not) recorded.
221
+
193
222
  ```bash
194
223
  lumitrace --verbose path/to/entry.rb
195
224
  ```
196
225
 
197
226
  ### Write JSON too
198
227
 
228
+ Use JSON output when you want to post-process results with scripts or other tools.
229
+
199
230
  ```bash
200
231
  lumitrace -j path/to/entry.rb
201
232
  ```
@@ -204,24 +235,32 @@ This creates `lumitrace_recorded.json`. HTML is written only when `--html` is al
204
235
 
205
236
  ### Text output to stdout
206
237
 
238
+ Choose this for quick, interactive feedback in your terminal.
239
+
207
240
  ```bash
208
241
  lumitrace -t path/to/entry.rb
209
242
  ```
210
243
 
211
244
  ### Text output to a file
212
245
 
246
+ Send text output to a file when you want to archive results or attach them to CI artifacts.
247
+
213
248
  ```bash
214
249
  lumitrace --text=/tmp/lumi.txt path/to/entry.rb
215
250
  ```
216
251
 
217
252
  ### Text plus HTML
218
253
 
254
+ Get both the fast terminal view and the richer HTML report in one run.
255
+
219
256
  ```bash
220
257
  lumitrace -t -h path/to/entry.rb
221
258
  ```
222
259
 
223
260
  ### Running with exec
224
261
 
262
+ Wrap another command (like tests) so Lumitrace instruments what that command runs.
263
+
225
264
  ```bash
226
265
  lumitrace --html=sample/lumitrace_rake.html exec rake
227
266
  ```
@@ -229,18 +268,22 @@ lumitrace --html=sample/lumitrace_rake.html exec rake
229
268
  HTML output:
230
269
  - [lumitrace_rake.html](https://ko1.github.io/lumitrace/sample/lumitrace_rake.html)
231
270
 
232
- ### Fork/exec merge
271
+ ### GitHub Actions
233
272
 
234
- Fork/exec results are merged by default. The parent process writes final output; child processes only write fragments under `LUMITRACE_RESULTS_DIR`.
273
+ Use CI to publish diff-scoped results automatically and share the HTML report via GitHub Pages.
235
274
 
236
- You can pass ranges via env (semicolon-separated):
275
+ For a practical CI setup (including `LUMITRACE_GIT_DIFF` and Pages upload), see `sample/sample_project/README.md`. The published Pages example is here: [https://ko1.github.io/lumitrace_sample_project/](https://ko1.github.io/lumitrace_sample_project/).
237
276
 
238
- ```bash
239
- LUMITRACE_RANGE="a.rb:1-3,5-6;b.rb" ruby your_script.rb
240
- ```
277
+ ### Fork/exec merge
278
+
279
+ If your app forks or execs, this explains how Lumitrace merges results across processes.
280
+
281
+ Fork/exec results are merged by default. The parent process writes final output; child processes only write fragments under `LUMITRACE_RESULTS_DIR`.
241
282
 
242
283
  ## 2. Library Mode
243
284
 
285
+ Use this when you want to enable Lumitrace inside an app or script without relying on the CLI wrapper.
286
+
244
287
  Enable instrumentation and text output at exit:
245
288
 
246
289
  ```ruby
@@ -307,6 +350,8 @@ Lumitrace also sets `RUBYOPT=-rlumitrace` to ensure exec'd Ruby processes load i
307
350
 
308
351
  ### Change output paths
309
352
 
353
+ Customize where HTML/JSON/text outputs go when using library mode.
354
+
310
355
  ```bash
311
356
  LUMITRACE_HTML=/tmp/lumi.html ruby your_script.rb
312
357
  ```
@@ -320,6 +365,8 @@ Lumitrace.enable!(json: "/tmp/lumi.json")
320
365
 
321
366
  ## 3. Diff-Based Instrumentation
322
367
 
368
+ Focus on just the changed lines in your codebase by wiring Lumitrace to `git diff` in library mode.
369
+
323
370
  Enable only lines touched by `git diff` for the current program file:
324
371
 
325
372
  ```ruby
@@ -334,12 +381,16 @@ LUMITRACE_GIT_DIFF=staged ruby your_script.rb
334
381
 
335
382
  ### Expand the diff context
336
383
 
384
+ Widen the diff window to include surrounding lines for better context.
385
+
337
386
  ```bash
338
387
  LUMITRACE_GIT_DIFF_CONTEXT=5 ruby your_script.rb
339
388
  ```
340
389
 
341
390
  ## 4. Root Scope
342
391
 
392
+ Limit (or expand) which files are eligible for instrumentation by defining a root directory.
393
+
343
394
  By default, Lumitrace only instruments files under the current directory.
344
395
  Override the root with:
345
396
 
@@ -355,5 +406,7 @@ lumitrace --root /path/to/project your_script.rb
355
406
 
356
407
  ## 5. Tips
357
408
 
409
+ Small knobs that keep outputs readable and noise low in day-to-day use.
410
+
358
411
  - If your output is large, lower `LUMITRACE_VALUES_MAX`.
359
412
  - For quick checks on a single file, `enable_git_diff` keeps noise down.
data/exe/lumitrace CHANGED
@@ -32,7 +32,7 @@ env["LUMITRACE_HTML"] = opts[:html] == true ? "1" : opts[:html] == false ? "0" :
32
32
  env["LUMITRACE_JSON"] = opts[:json] == true ? "1" : opts[:json] == false ? "0" : opts[:json].to_s if !opts[:json].nil?
33
33
  env["LUMITRACE_VALUES_MAX"] = opts[:max_values].to_s if opts[:max_values]
34
34
  env["LUMITRACE_ROOT"] = opts[:root] if opts[:root]
35
- env["LUMITRACE_VERBOSE"] = opts[:verbose] ? "1" : "0" if !opts[:verbose].nil?
35
+ env["LUMITRACE_VERBOSE"] = opts[:verbose].to_s if !opts[:verbose].nil?
36
36
  if opts[:range_specs].any?
37
37
  env["LUMITRACE_RANGE"] = opts[:range_specs].join(";")
38
38
  end
data/lib/lumitrace/env.rb CHANGED
@@ -8,6 +8,14 @@ module Lumitrace
8
8
  value
9
9
  end
10
10
 
11
+ def self.parse_env_int(value)
12
+ return nil if value.nil?
13
+ flag = parse_env_flag(value)
14
+ return 1 if flag == true
15
+ return 0 if flag == false
16
+ flag.to_i
17
+ end
18
+
11
19
  def self.resolve_env_options
12
20
  html_env = parse_env_flag(ENV["LUMITRACE_HTML"])
13
21
  json_env = parse_env_flag(ENV["LUMITRACE_JSON"])
@@ -32,7 +40,7 @@ module Lumitrace
32
40
  text = (text_env != false)
33
41
  end
34
42
 
35
- verbose = parse_env_flag(ENV["LUMITRACE_VERBOSE"]) == true
43
+ verbose = parse_env_int(ENV["LUMITRACE_VERBOSE"])
36
44
  range_specs = if range_env.nil? || range_env.strip.empty?
37
45
  []
38
46
  else