lumitrace 0.2.0 → 0.3.0

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: 638e44a364f468bd57003d05c60492dc697f31faba607292dfa5768b8ede47d2
4
- data.tar.gz: a930badbf11444cd914765dde643a13347414511e1401aad4bf2da55e3e8159b
3
+ metadata.gz: 8ffc13efecd8f5143486eff6929c93bf73aaa3934bf24fa57e906a2f90498e2c
4
+ data.tar.gz: df8ce2960f59409dc832d21f9d1df7a2b33cc431fde00c76633f1149a5da3ab3
5
5
  SHA512:
6
- metadata.gz: 3997b1814e8861e98e5b8dbd2489eab974f8d1671424a190bc2b82e37c65a6a3253eeb47074c507a1984ef5a3db19cb0aa84520e7f54a757d133f510d260c5c5
7
- data.tar.gz: 935834bd5c818a528307f1359815faead6f793ffa5deaf78b039a7fb9dd5b570dd0b07ce1b1bf00edf0c4e51a39edfcb2f4fbddae5c85a6a54e7ff3ae036b699
6
+ metadata.gz: 2030ec337dc9a941f1c9878b1faa74e15e605a715e1d2049675115573c7c1357d821ded3a200b348521a9593faf6f719ff93766f5ffe1c623d9a9c6dcaa663b1
7
+ data.tar.gz: 68564fe5bde3b1d00edd5390211c922b72f3565069446affed3dfdf042fc86491949f8170e175df8cdd99c55b1c05f030adab69fe140ce05cfd003f3f3a51719
data/README.md CHANGED
@@ -20,29 +20,41 @@ Lumitrace hooks `RubyVM::InstructionSequence.translate` (when available) to rewr
20
20
 
21
21
  ### CLI
22
22
 
23
- Run a script and emit HTML (default output: `lumitrace_recorded.html`):
23
+ Run a script and emit text output (default):
24
24
 
25
25
  ```bash
26
- ruby exe/lumitrace path/to/entry.rb
26
+ lumitrace path/to/entry.rb
27
+ ```
28
+
29
+ Run another command via exec:
30
+
31
+ ```bash
32
+ lumitrace exec rake test
33
+ ```
34
+
35
+ Emit HTML output:
36
+
37
+ ```bash
38
+ lumitrace -h path/to/entry.rb
27
39
  ```
28
40
 
29
41
  Limit the number of recorded values per expression (defaults to 3):
30
42
 
31
43
  ```bash
32
- LUMITRACE_VALUES_MAX=5 ruby exe/lumitrace path/to/entry.rb
44
+ LUMITRACE_VALUES_MAX=5 lumitrace path/to/entry.rb
33
45
  ```
34
46
 
35
47
  Write JSON output explicitly:
36
48
 
37
49
  ```bash
38
- ruby exe/lumitrace path/to/entry.rb --json
39
- ruby exe/lumitrace path/to/entry.rb --json out/lumitrace_recorded.json
50
+ lumitrace -j path/to/entry.rb
51
+ lumitrace --json=out/lumitrace_recorded.json path/to/entry.rb
40
52
  ```
41
53
 
42
54
  Restrict to specific line ranges:
43
55
 
44
56
  ```bash
45
- ruby exe/lumitrace path/to/entry.rb --range path/to/entry.rb:10-20,30-35
57
+ lumitrace --range path/to/entry.rb:10-20,30-35 path/to/entry.rb
46
58
  ```
47
59
 
48
60
  ### Library
@@ -68,18 +80,27 @@ require "lumitrace/enable"
68
80
 
69
81
  ## Output
70
82
 
71
- - HTML: `lumitrace_recorded.html` by default, override with `LUMITRACE_HTML_OUT`.
72
- - JSON: written only when `--json` (CLI) or `LUMITRACE_JSON_OUT` (library) is provided. Default filename is `lumitrace_recorded.json`.
83
+ - Text: printed by default; use `--text=PATH` to write to a file.
84
+ - HTML: `lumitrace_recorded.html` by default, or `--html=PATH`.
85
+ - JSON: written only when `--json` (CLI) or `LUMITRACE_JSON` (library/CLI) is provided. Default filename is `lumitrace_recorded.json`.
86
+ - Fork/exec: merged by default. Child processes write fragments under `LUMITRACE_RESULTS_DIR`.
73
87
 
74
88
  ## Environment Variables
75
89
 
76
90
  - `LUMITRACE_VALUES_MAX`: default max values per expression (default 3 if unset).
77
91
  - `LUMITRACE_ROOT`: root directory used to decide which files are instrumented.
78
- - `LUMITRACE_HTML_OUT`: override HTML output path.
79
- - `LUMITRACE_JSON_OUT`: if set, writes JSON to this path at exit.
92
+ - `LUMITRACE_TEXT`: control text output. `1` forces text on, `0`/`false` disables. Any other value is treated as the text output path.
93
+ - `LUMITRACE_HTML`: enable HTML output; `1` uses the default path, otherwise treats the value as the HTML output path. `0`/`false` disables.
94
+ - `LUMITRACE_JSON`: enable JSON output; `1` uses the default path, otherwise treats the value as the JSON output path. `0`/`false` disables.
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.
97
+ - `LUMITRACE_RANGE`: semicolon-separated range specs (e.g. `a.rb:1-3,5-6;b.rb`).
98
+ - `LUMITRACE_RESULTS_DIR`: internal use. Shared results directory for fork/exec merge (default: `Dir.tmpdir/lumitrace_results/<user>_<parent_pid>`).
99
+ - `LUMITRACE_RESULTS_PARENT_PID`: internal use. Parent PID for fork/exec merge (auto-set).
80
100
  - `LUMITRACE_GIT_DIFF=working|staged|base:REV|range:SPEC`: diff source for `enable_git_diff`.
81
101
  - `LUMITRACE_GIT_DIFF_CONTEXT=N`: expand diff hunks by +/-N lines (default 3).
82
102
  - `LUMITRACE_GIT_CMD`: git executable override (default `git`).
103
+ - `LUMITRACE_GIT_DIFF_UNTRACKED`: include untracked files in git diff ranges (`1` default). Set to `0` to exclude.
83
104
 
84
105
  ## Notes And Limitations
85
106
 
@@ -98,5 +119,5 @@ bundle install
98
119
  Run the CLI locally:
99
120
 
100
121
  ```bash
101
- ruby exe/lumitrace path/to/entry.rb
122
+ lumitrace path/to/entry.rb
102
123
  ```
data/docs/spec.md CHANGED
@@ -33,7 +33,7 @@ Lumitrace instruments Ruby source code at load time (via `RubyVM::InstructionSeq
33
33
  - `require "lumitrace/enable"` (calls `Lumitrace.enable!`)
34
34
  - `require "lumitrace/enable_git_diff"` (diff-scoped `Lumitrace.enable!`)
35
35
  - `LUMITRACE_ENABLE=1` + `require "lumitrace"` (auto-`enable!`)
36
- - `LUMITRACE_ENABLE="--text --html --json ..."` + `require "lumitrace"` (CLI-style options parsed and passed to `enable!`)
36
+ - `LUMITRACE_ENABLE="-t -h -j ..."` + `require "lumitrace"` (CLI-style options parsed and passed to `enable!`)
37
37
 
38
38
  ### `Lumitrace.enable!(max_values: nil, ranges_by_file: nil, root: nil, text: nil, html: nil, json: nil, verbose: nil, at_exit: true)`
39
39
 
@@ -60,6 +60,9 @@ Lumitrace instruments Ruby source code at load time (via `RubyVM::InstructionSeq
60
60
  - `LUMITRACE_GIT_DIFF_UNTRACKED`: include untracked files in git diff ranges (`1` default). Set to `0` to exclude.
61
61
  - `LUMITRACE_VERBOSE`: when `1`/`true`, prints verbose logs to stderr.
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
+ - `LUMITRACE_RANGE`: semicolon-separated range specs, e.g. `a.rb:1-3,5-6;b.rb`.
64
+ - `LUMITRACE_RESULTS_DIR`: internal use. Shared results directory for fork/exec merge (default: `Dir.tmpdir/lumitrace_results/<user>_<parent_pid>`).
65
+ - `LUMITRACE_RESULTS_PARENT_PID`: internal use. Parent PID for fork/exec merge (auto-set).
63
66
 
64
67
  ### `Lumitrace.disable!`
65
68
 
@@ -85,6 +88,7 @@ Lumitrace instruments Ruby source code at load time (via `RubyVM::InstructionSeq
85
88
  - `LUMITRACE_GIT_DIFF=working|staged|base:REV|range:SPEC` selects diff source.
86
89
  - `LUMITRACE_GIT_DIFF_CONTEXT=N` expands hunks by +/-N lines (default 3; negative treated as 0).
87
90
  - `LUMITRACE_GIT_CMD` overrides the git executable (default: `git`).
91
+ - `LUMITRACE_RANGE` can be used to pass explicit ranges via env.
88
92
 
89
93
  ## Instrumentation
90
94
 
@@ -142,6 +146,14 @@ Lumitrace instruments Ruby source code at load time (via `RubyVM::InstructionSeq
142
146
  - Values are stored via `inspect` for non-primitive types.
143
147
  - String values are truncated to 1000 bytes for storage.
144
148
 
149
+ ## Fork/Exec Merge
150
+
151
+ - Fork/exec results are merged by default.
152
+ - The parent process writes final text/HTML/JSON.
153
+ - Child processes write JSON fragments under `LUMITRACE_RESULTS_DIR` and do not write final outputs.
154
+ - When `Process._fork` is available, Lumitrace hooks it to reset child events immediately after fork.
155
+ - `exec` inherits `LUMITRACE_RESULTS_DIR` and `LUMITRACE_RESULTS_PARENT_PID` via the environment. `Lumitrace.enable!` also appends `-rlumitrace` to `RUBYOPT` to ensure the exec'd process loads Lumitrace.
156
+
145
157
  ### Output JSON
146
158
 
147
159
  `lumitrace_recorded.json` contains an array of entries:
@@ -160,25 +172,27 @@ Lumitrace instruments Ruby source code at load time (via `RubyVM::InstructionSeq
160
172
 
161
173
  ## CLI
162
174
 
163
- ### `exe/lumitrace`
175
+ ### `lumitrace`
164
176
 
165
177
  ```
166
- lumitrace FILE [--text [PATH]] [--html [PATH]] [--json [PATH]] [--max N] [--range SPEC] [--git-diff [MODE]] [--git-diff-context N] [--git-cmd PATH] [--git-diff-no-untracked]
178
+ lumitrace [options] script.rb [ruby_opt]
179
+ lumitrace [options] exec CMD [args...]
167
180
  ```
168
181
 
169
182
  - Text is rendered by default (from in-memory events; no JSON file is required).
170
- - `--text` writes text output to stdout (default). When a PATH is provided, writes text output to that file.
171
- - `--html` enables HTML output; optionally specify the output path.
172
- - JSON is written only when `--json` is provided.
173
- - `--json` writes JSON output (default: `lumitrace_recorded.json`).
183
+ - `-t` enables text output to stdout. `--text=PATH` writes to a file.
184
+ - `-h` enables HTML output (default path). `--html=PATH` writes to a file.
185
+ - `-j` enables JSON output (default path). `--json=PATH` writes to a file.
186
+ - `-g` enables git diff with `working` mode. `--git-diff=MODE` selects `staged|base:REV|range:SPEC`.
174
187
  - `--max` sets max values per expression.
175
188
  - `--range` restricts instrumentation per file (`FILE` or `FILE:1-5,10-12`). Can be repeated.
176
- - `--git-diff` restricts instrumentation to diff hunks (`working` default; `staged|base:REV|range:SPEC`).
189
+ - `--git-diff=MODE` restricts instrumentation to diff hunks (`staged|base:REV|range:SPEC`).
177
190
  - `--git-diff-context` expands hunks by +/-N lines.
178
191
  - `--git-cmd` overrides the git executable.
179
192
  - `--git-diff-no-untracked` excludes untracked files (untracked files are included by default).
180
193
  - `--verbose` prints verbose logs to stderr.
181
194
  - `LUMITRACE_VALUES_MAX` sets the default max values per expression.
195
+ - The CLI launches a child process (Ruby or `exec` target) with `RUBYOPT=-rlumitrace` and `LUMITRACE_*` env vars.
182
196
 
183
197
  ### Text Output (CLI)
184
198
 
data/docs/tutorial.ja.md CHANGED
@@ -10,7 +10,7 @@
10
10
  同梱の sample を最小のコマンドで実行します(テキストは stdout に出ます):
11
11
 
12
12
  ```bash
13
- ruby exe/lumitrace sample/sample.rb
13
+ lumitrace sample/sample.rb
14
14
  ```
15
15
 
16
16
  プログラム本体の stdout はそのまま出力され、続けて Lumitrace のテキストが表示されます。
@@ -98,7 +98,7 @@ n0=2, n1=5, n2=11
98
98
  同梱の sample を実行して、テキストと HTML を保存します:
99
99
 
100
100
  ```bash
101
- ruby exe/lumitrace sample/sample.rb \
101
+ lumitrace sample/sample.rb \
102
102
  --text sample/lumitrace_results_01.txt \
103
103
  --html sample/lumitrace_results_01.html
104
104
  ```
@@ -115,7 +115,7 @@ HTML 出力を見る:
115
115
  範囲を指定して、別の出力として保存します:
116
116
 
117
117
  ```bash
118
- ruby exe/lumitrace sample/sample.rb \
118
+ lumitrace sample/sample.rb \
119
119
  --text sample/lumitrace_results_02.txt \
120
120
  --html sample/lumitrace_results_02.html \
121
121
  --range sample/sample.rb:4-18,28-32
@@ -156,68 +156,87 @@ HTML 出力を見る:
156
156
  環境変数で HTML を有効化:
157
157
 
158
158
  ```bash
159
- LUMITRACE_HTML=1 ruby exe/lumitrace path/to/entry.rb
160
- LUMITRACE_HTML=/tmp/out.html ruby exe/lumitrace path/to/entry.rb
159
+ LUMITRACE_HTML=1 lumitrace path/to/entry.rb
160
+ LUMITRACE_HTML=/tmp/out.html lumitrace path/to/entry.rb
161
161
  ```
162
162
 
163
163
  ### 記録する値の数を減らす
164
164
 
165
165
  ```bash
166
- LUMITRACE_VALUES_MAX=5 ruby exe/lumitrace path/to/entry.rb
166
+ LUMITRACE_VALUES_MAX=5 lumitrace path/to/entry.rb
167
167
  ```
168
168
 
169
169
  ### 行範囲を限定する
170
170
 
171
171
  ```bash
172
- ruby exe/lumitrace path/to/entry.rb --range path/to/entry.rb:10-20,30-35
172
+ lumitrace --range path/to/entry.rb:10-20,30-35 path/to/entry.rb
173
173
  ```
174
174
 
175
175
  ### 差分だけ計測(CLI)
176
176
 
177
177
  ```bash
178
- ruby exe/lumitrace path/to/entry.rb --git-diff
179
- ruby exe/lumitrace path/to/entry.rb --git-diff staged
180
- ruby exe/lumitrace path/to/entry.rb --git-diff base:HEAD~1
181
- ruby exe/lumitrace path/to/entry.rb --git-diff-context 5
182
- ruby exe/lumitrace path/to/entry.rb --git-cmd /usr/local/bin/git
178
+ lumitrace -g path/to/entry.rb
179
+ lumitrace --git-diff=staged path/to/entry.rb
180
+ lumitrace --git-diff=base:HEAD~1 path/to/entry.rb
181
+ lumitrace --git-diff-context 5 path/to/entry.rb
182
+ lumitrace --git-cmd /usr/local/bin/git path/to/entry.rb
183
183
  ```
184
184
 
185
185
  未追跡ファイルを除外:
186
186
 
187
187
  ```bash
188
- ruby exe/lumitrace path/to/entry.rb --git-diff --git-diff-no-untracked
188
+ lumitrace -g --git-diff-no-untracked path/to/entry.rb
189
189
  ```
190
190
 
191
191
  ### 詳細ログ
192
192
 
193
193
  ```bash
194
- ruby exe/lumitrace path/to/entry.rb --verbose
194
+ lumitrace --verbose path/to/entry.rb
195
195
  ```
196
196
 
197
197
  ### JSON も出力する
198
198
 
199
199
  ```bash
200
- ruby exe/lumitrace path/to/entry.rb --json
200
+ lumitrace -j path/to/entry.rb
201
201
  ```
202
202
 
203
- `lumitrace_recorded.json` HTML と同じ場所に生成されます。
203
+ `lumitrace_recorded.json` が生成されます(HTML は `--html` を指定したときだけ出力されます)。
204
204
 
205
205
  ### stdout にテキスト出力
206
206
 
207
207
  ```bash
208
- ruby exe/lumitrace path/to/entry.rb --text
208
+ lumitrace -t path/to/entry.rb
209
209
  ```
210
210
 
211
211
  ### テキストをファイルに出力
212
212
 
213
213
  ```bash
214
- ruby exe/lumitrace path/to/entry.rb --text /tmp/lumi.txt
214
+ lumitrace --text=/tmp/lumi.txt path/to/entry.rb
215
215
  ```
216
216
 
217
217
  ### テキストと HTML を両方出力
218
218
 
219
219
  ```bash
220
- ruby exe/lumitrace path/to/entry.rb --text --html
220
+ lumitrace -t -h path/to/entry.rb
221
+ ```
222
+
223
+ ### exec で実行
224
+
225
+ ```bash
226
+ lumitrace --html=sample/lumitrace_rake.html exec rake
227
+ ```
228
+
229
+ HTML 出力:
230
+ - [lumitrace_rake.html](https://ko1.github.io/lumitrace/sample/lumitrace_rake.html)
231
+
232
+ ### Fork/exec のマージ
233
+
234
+ fork/exec の結果はデフォルトでマージされます。親プロセスが最終出力を行い、子プロセスは `LUMITRACE_RESULTS_DIR` に断片 JSON を保存します。
235
+
236
+ 環境変数で range を渡す場合(`;` 区切り):
237
+
238
+ ```bash
239
+ LUMITRACE_RANGE="a.rb:1-3,5-6;b.rb" ruby your_script.rb
221
240
  ```
222
241
 
223
242
  ## 2. ライブラリとして使う
@@ -280,10 +299,12 @@ require "lumitrace"
280
299
  `LUMITRACE_ENABLE` に CLI 互換のオプションを渡すこともできます:
281
300
 
282
301
  ```ruby
283
- ENV["LUMITRACE_ENABLE"] = "--text --html /tmp/lumi.html --json"
302
+ ENV["LUMITRACE_ENABLE"] = "-t --html=/tmp/lumi.html -j"
284
303
  require "lumitrace"
285
304
  ```
286
305
 
306
+ exec 先でも読み込まれるように、Lumitrace は `RUBYOPT=-rlumitrace` を設定します。
307
+
287
308
  ### 出力先を変更する
288
309
 
289
310
  ```bash
data/docs/tutorial.md CHANGED
@@ -10,7 +10,7 @@ This is a short, practical guide to using Lumitrace.
10
10
  Run the bundled sample with the simplest command (text output goes to stdout by default):
11
11
 
12
12
  ```bash
13
- ruby exe/lumitrace sample/sample.rb
13
+ lumitrace sample/sample.rb
14
14
  ```
15
15
 
16
16
  The program’s own stdout is still printed, and Lumitrace text output follows it.
@@ -98,7 +98,7 @@ n0=2, n1=5, n2=11
98
98
  Run the bundled sample and write both text and HTML outputs:
99
99
 
100
100
  ```bash
101
- ruby exe/lumitrace sample/sample.rb \
101
+ lumitrace sample/sample.rb \
102
102
  --text sample/lumitrace_results_01.txt \
103
103
  --html sample/lumitrace_results_01.html
104
104
  ```
@@ -115,7 +115,7 @@ View the HTML output:
115
115
  Run with ranges and save separate outputs:
116
116
 
117
117
  ```bash
118
- ruby exe/lumitrace sample/sample.rb \
118
+ lumitrace sample/sample.rb \
119
119
  --text sample/lumitrace_results_02.txt \
120
120
  --html sample/lumitrace_results_02.html \
121
121
  --range sample/sample.rb:4-18,28-32
@@ -156,68 +156,87 @@ View the HTML output:
156
156
  Enable HTML output via env:
157
157
 
158
158
  ```bash
159
- LUMITRACE_HTML=1 ruby exe/lumitrace path/to/entry.rb
160
- LUMITRACE_HTML=/tmp/out.html ruby exe/lumitrace path/to/entry.rb
159
+ LUMITRACE_HTML=1 lumitrace path/to/entry.rb
160
+ LUMITRACE_HTML=/tmp/out.html lumitrace path/to/entry.rb
161
161
  ```
162
162
 
163
163
  ### Limit recorded values
164
164
 
165
165
  ```bash
166
- LUMITRACE_VALUES_MAX=5 ruby exe/lumitrace path/to/entry.rb
166
+ LUMITRACE_VALUES_MAX=5 lumitrace path/to/entry.rb
167
167
  ```
168
168
 
169
169
  ### Limit to specific lines
170
170
 
171
171
  ```bash
172
- ruby exe/lumitrace path/to/entry.rb --range path/to/entry.rb:10-20,30-35
172
+ lumitrace --range path/to/entry.rb:10-20,30-35 path/to/entry.rb
173
173
  ```
174
174
 
175
175
  ### Diff-based ranges
176
176
 
177
177
  ```bash
178
- ruby exe/lumitrace path/to/entry.rb --git-diff
179
- ruby exe/lumitrace path/to/entry.rb --git-diff staged
180
- ruby exe/lumitrace path/to/entry.rb --git-diff base:HEAD~1
181
- ruby exe/lumitrace path/to/entry.rb --git-diff-context 5
182
- ruby exe/lumitrace path/to/entry.rb --git-cmd /usr/local/bin/git
178
+ lumitrace -g path/to/entry.rb
179
+ lumitrace --git-diff=staged path/to/entry.rb
180
+ lumitrace --git-diff=base:HEAD~1 path/to/entry.rb
181
+ lumitrace --git-diff-context 5 path/to/entry.rb
182
+ lumitrace --git-cmd /usr/local/bin/git path/to/entry.rb
183
183
  ```
184
184
 
185
185
  Exclude untracked files:
186
186
 
187
187
  ```bash
188
- ruby exe/lumitrace path/to/entry.rb --git-diff --git-diff-no-untracked
188
+ lumitrace -g --git-diff-no-untracked path/to/entry.rb
189
189
  ```
190
190
 
191
191
  ### Verbose logs
192
192
 
193
193
  ```bash
194
- ruby exe/lumitrace path/to/entry.rb --verbose
194
+ lumitrace --verbose path/to/entry.rb
195
195
  ```
196
196
 
197
197
  ### Write JSON too
198
198
 
199
199
  ```bash
200
- ruby exe/lumitrace path/to/entry.rb --json
200
+ lumitrace -j path/to/entry.rb
201
201
  ```
202
202
 
203
- This creates `lumitrace_recorded.json` alongside the HTML.
203
+ This creates `lumitrace_recorded.json`. HTML is written only when `--html` is also specified.
204
204
 
205
205
  ### Text output to stdout
206
206
 
207
207
  ```bash
208
- ruby exe/lumitrace path/to/entry.rb --text
208
+ lumitrace -t path/to/entry.rb
209
209
  ```
210
210
 
211
211
  ### Text output to a file
212
212
 
213
213
  ```bash
214
- ruby exe/lumitrace path/to/entry.rb --text /tmp/lumi.txt
214
+ lumitrace --text=/tmp/lumi.txt path/to/entry.rb
215
215
  ```
216
216
 
217
217
  ### Text plus HTML
218
218
 
219
219
  ```bash
220
- ruby exe/lumitrace path/to/entry.rb --text --html
220
+ lumitrace -t -h path/to/entry.rb
221
+ ```
222
+
223
+ ### Running with exec
224
+
225
+ ```bash
226
+ lumitrace --html=sample/lumitrace_rake.html exec rake
227
+ ```
228
+
229
+ HTML output:
230
+ - [lumitrace_rake.html](https://ko1.github.io/lumitrace/sample/lumitrace_rake.html)
231
+
232
+ ### Fork/exec merge
233
+
234
+ Fork/exec results are merged by default. The parent process writes final output; child processes only write fragments under `LUMITRACE_RESULTS_DIR`.
235
+
236
+ You can pass ranges via env (semicolon-separated):
237
+
238
+ ```bash
239
+ LUMITRACE_RANGE="a.rb:1-3,5-6;b.rb" ruby your_script.rb
221
240
  ```
222
241
 
223
242
  ## 2. Library Mode
@@ -280,10 +299,12 @@ require "lumitrace"
280
299
  You can also pass CLI-style options via `LUMITRACE_ENABLE`:
281
300
 
282
301
  ```ruby
283
- ENV["LUMITRACE_ENABLE"] = "--text --html /tmp/lumi.html --json"
302
+ ENV["LUMITRACE_ENABLE"] = "-t --html=/tmp/lumi.html -j"
284
303
  require "lumitrace"
285
304
  ```
286
305
 
306
+ Lumitrace also sets `RUBYOPT=-rlumitrace` to ensure exec'd Ruby processes load it, so fork/exec output can be merged.
307
+
287
308
  ### Change output paths
288
309
 
289
310
  ```bash
data/exe/lumitrace CHANGED
@@ -1,36 +1,72 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
+ require "rbconfig"
4
5
  require_relative "../lib/lumitrace"
5
6
 
6
7
  opts, args, parser = Lumitrace.parse_cli_options(
7
8
  ARGV,
8
- banner: "usage: lumitrace FILE [options]",
9
- allow_help: true
9
+ banner: "usage: lumitrace [options] script.rb [ruby_opt] | lumitrace [options] exec CMD [args...]",
10
+ allow_help: true,
11
+ order: :preserve
10
12
  )
11
13
  if opts[:help]
12
14
  puts parser
13
15
  exit 0
14
16
  end
15
- path = args.shift or abort(parser.to_s)
16
17
 
17
- opts[:root] = File.expand_path(opts[:root]) if opts[:root] && !opts[:root].strip.empty?
18
- opts[:ranges_by_file] = Lumitrace.resolve_ranges_by_file(
19
- opts[:range_specs],
20
- git_diff_mode: opts[:git_diff_mode],
21
- git_diff_context: opts[:git_diff_context],
22
- git_cmd: opts[:git_cmd],
23
- git_diff_no_untracked: opts[:git_diff_no_untracked]
24
- )
18
+ if args.empty?
19
+ warn parser.to_s
20
+ exit 1
21
+ end
25
22
 
26
- Lumitrace.enable!(
27
- max_values: opts[:max_values],
28
- ranges_by_file: opts[:ranges_by_file],
29
- root: opts[:root],
30
- text: opts[:text],
31
- html: opts[:html],
32
- json: opts[:json],
33
- verbose: opts[:verbose],
34
- at_exit: true
35
- )
36
- load File.expand_path(path)
23
+ if opts[:git_diff_mode] == "exec" && args.first != "exec"
24
+ args.unshift("exec")
25
+ opts[:git_diff_mode] = "working"
26
+ end
27
+
28
+ env = {}
29
+ env["LUMITRACE_ENABLE"] = "1"
30
+ env["LUMITRACE_TEXT"] = opts[:text] == true ? "1" : opts[:text] == false ? "0" : opts[:text].to_s if !opts[:text].nil?
31
+ env["LUMITRACE_HTML"] = opts[:html] == true ? "1" : opts[:html] == false ? "0" : opts[:html].to_s if !opts[:html].nil?
32
+ env["LUMITRACE_JSON"] = opts[:json] == true ? "1" : opts[:json] == false ? "0" : opts[:json].to_s if !opts[:json].nil?
33
+ env["LUMITRACE_VALUES_MAX"] = opts[:max_values].to_s if opts[:max_values]
34
+ env["LUMITRACE_ROOT"] = opts[:root] if opts[:root]
35
+ env["LUMITRACE_VERBOSE"] = opts[:verbose] ? "1" : "0" if !opts[:verbose].nil?
36
+ if opts[:range_specs].any?
37
+ env["LUMITRACE_RANGE"] = opts[:range_specs].join(";")
38
+ end
39
+ if opts[:git_diff_mode]
40
+ env["LUMITRACE_GIT_DIFF"] = opts[:git_diff_mode]
41
+ end
42
+ if opts[:git_diff_context]
43
+ env["LUMITRACE_GIT_DIFF_CONTEXT"] = opts[:git_diff_context].to_s
44
+ end
45
+ if opts[:git_cmd]
46
+ env["LUMITRACE_GIT_CMD"] = opts[:git_cmd]
47
+ end
48
+ if opts[:git_diff_no_untracked]
49
+ env["LUMITRACE_GIT_DIFF_UNTRACKED"] = "0"
50
+ end
51
+
52
+ lib_dir = File.expand_path("../lib", __dir__)
53
+ ruby_lib = ENV["RUBYLIB"].to_s
54
+ env["RUBYLIB"] = ([lib_dir] + ruby_lib.split(":")).uniq.join(":")
55
+
56
+ rubyopt = ENV["RUBYOPT"].to_s
57
+ unless rubyopt.split.any? { |t| t == "-rlumitrace" || t == "-rlumitrace/enable" }
58
+ rubyopt = rubyopt.strip.empty? ? "-rlumitrace" : "#{rubyopt} -rlumitrace"
59
+ end
60
+ env["RUBYOPT"] = rubyopt
61
+
62
+ if args[0] == "exec"
63
+ cmd = args[1..]
64
+ if cmd.nil? || cmd.empty?
65
+ warn "lumitrace exec: missing command"
66
+ exit 1
67
+ end
68
+ exec(env, *cmd)
69
+ else
70
+ script = args.shift
71
+ exec(env, RbConfig.ruby, script, *args)
72
+ end
data/lib/lumitrace/env.rb CHANGED
@@ -13,6 +13,11 @@ module Lumitrace
13
13
  json_env = parse_env_flag(ENV["LUMITRACE_JSON"])
14
14
  raw_text = ENV["LUMITRACE_TEXT"]
15
15
  text_env = parse_env_flag(raw_text)
16
+ range_env = ENV["LUMITRACE_RANGE"]
17
+ git_diff_env = ENV["LUMITRACE_GIT_DIFF"]
18
+ git_diff_context_env = ENV["LUMITRACE_GIT_DIFF_CONTEXT"]
19
+ git_cmd_env = ENV["LUMITRACE_GIT_CMD"]
20
+ git_diff_untracked_env = parse_env_flag(ENV["LUMITRACE_GIT_DIFF_UNTRACKED"])
16
21
  max_env = ENV["LUMITRACE_VALUES_MAX"]
17
22
  root_env = ENV["LUMITRACE_ROOT"]
18
23
 
@@ -28,6 +33,13 @@ module Lumitrace
28
33
  end
29
34
 
30
35
  verbose = parse_env_flag(ENV["LUMITRACE_VERBOSE"]) == true
36
+ range_specs = if range_env.nil? || range_env.strip.empty?
37
+ []
38
+ else
39
+ range_env.split(";").map(&:strip).reject(&:empty?)
40
+ end
41
+ git_diff_context = git_diff_context_env ? git_diff_context_env.to_i : nil
42
+ git_diff_untracked = git_diff_untracked_env.nil? ? nil : (git_diff_untracked_env != false)
31
43
 
32
44
  {
33
45
  text: text,
@@ -35,6 +47,11 @@ module Lumitrace
35
47
  html: html,
36
48
  html_out: html_out,
37
49
  json: json,
50
+ range_specs: range_specs,
51
+ git_diff_mode: git_diff_env,
52
+ git_diff_context: git_diff_context,
53
+ git_cmd: git_cmd_env,
54
+ git_diff_untracked: git_diff_untracked,
38
55
  max_values: max_env,
39
56
  root: root_env,
40
57
  verbose: verbose
@@ -620,7 +620,7 @@ module GenerateResultedHtml
620
620
  render_text_from_events(src, events, filename: path, ranges: ranges, with_header: true, header_label: rel)
621
621
  end.compact
622
622
 
623
- header = "=== Lumitrace Results (text) ===\n\n"
623
+ header = "\n=== Lumitrace Results (text) ===\n\n"
624
624
  header + sections.join("\n")
625
625
  end
626
626