tracemake 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 04c0bc7f318a878627268f801a2de991143ba0a801bd8b5f4fa67803825f8f22
4
+ data.tar.gz: c5e7c602dd09f2e99ecd31a51b92d27ecae30790c79986f6a8c60dba43ec8de5
5
+ SHA512:
6
+ metadata.gz: 2232e4ded43946368da649690fe4208d2cb164d9f25cee083ed64645a24a650bd7b0191c86d18044b4186b16e999ca1f3f0e07f295fefb80e4df0c924afb2372
7
+ data.tar.gz: c4374876ff43492d75a4c18a8206feea630994f27b1f859c4ad8412954978b55d30ef9aed8fdab82f2d3550befa31eb7489594b5462ae7fc3c8e3b4f3984ce60
@@ -0,0 +1,132 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our
6
+ community a harassment-free experience for everyone, regardless of age, body
7
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
8
+ identity and expression, level of experience, education, socio-economic status,
9
+ nationality, personal appearance, race, caste, color, religion, or sexual
10
+ identity and orientation.
11
+
12
+ We pledge to act and interact in ways that contribute to an open, welcoming,
13
+ diverse, inclusive, and healthy community.
14
+
15
+ ## Our Standards
16
+
17
+ Examples of behavior that contributes to a positive environment for our
18
+ community include:
19
+
20
+ * Demonstrating empathy and kindness toward other people
21
+ * Being respectful of differing opinions, viewpoints, and experiences
22
+ * Giving and gracefully accepting constructive feedback
23
+ * Accepting responsibility and apologizing to those affected by our mistakes,
24
+ and learning from the experience
25
+ * Focusing on what is best not just for us as individuals, but for the overall
26
+ community
27
+
28
+ Examples of unacceptable behavior include:
29
+
30
+ * The use of sexualized language or imagery, and sexual attention or advances of
31
+ any kind
32
+ * Trolling, insulting or derogatory comments, and personal or political attacks
33
+ * Public or private harassment
34
+ * Publishing others' private information, such as a physical or email address,
35
+ without their explicit permission
36
+ * Other conduct which could reasonably be considered inappropriate in a
37
+ professional setting
38
+
39
+ ## Enforcement Responsibilities
40
+
41
+ Community leaders are responsible for clarifying and enforcing our standards of
42
+ acceptable behavior and will take appropriate and fair corrective action in
43
+ response to any behavior that they deem inappropriate, threatening, offensive,
44
+ or harmful.
45
+
46
+ Community leaders have the right and responsibility to remove, edit, or reject
47
+ comments, commits, code, wiki edits, issues, and other contributions that are
48
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
49
+ decisions when appropriate.
50
+
51
+ ## Scope
52
+
53
+ This Code of Conduct applies within all community spaces, and also applies when
54
+ an individual is officially representing the community in public spaces.
55
+ Examples of representing our community include using an official email address,
56
+ posting via an official social media account, or acting as an appointed
57
+ representative at an online or offline event.
58
+
59
+ ## Enforcement
60
+
61
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
+ reported to the community leaders responsible for enforcement at
63
+ [INSERT CONTACT METHOD].
64
+ All complaints will be reviewed and investigated promptly and fairly.
65
+
66
+ All community leaders are obligated to respect the privacy and security of the
67
+ reporter of any incident.
68
+
69
+ ## Enforcement Guidelines
70
+
71
+ Community leaders will follow these Community Impact Guidelines in determining
72
+ the consequences for any action they deem in violation of this Code of Conduct:
73
+
74
+ ### 1. Correction
75
+
76
+ **Community Impact**: Use of inappropriate language or other behavior deemed
77
+ unprofessional or unwelcome in the community.
78
+
79
+ **Consequence**: A private, written warning from community leaders, providing
80
+ clarity around the nature of the violation and an explanation of why the
81
+ behavior was inappropriate. A public apology may be requested.
82
+
83
+ ### 2. Warning
84
+
85
+ **Community Impact**: A violation through a single incident or series of
86
+ actions.
87
+
88
+ **Consequence**: A warning with consequences for continued behavior. No
89
+ interaction with the people involved, including unsolicited interaction with
90
+ those enforcing the Code of Conduct, for a specified period of time. This
91
+ includes avoiding interactions in community spaces as well as external channels
92
+ like social media. Violating these terms may lead to a temporary or permanent
93
+ ban.
94
+
95
+ ### 3. Temporary Ban
96
+
97
+ **Community Impact**: A serious violation of community standards, including
98
+ sustained inappropriate behavior.
99
+
100
+ **Consequence**: A temporary ban from any sort of interaction or public
101
+ communication with the community for a specified period of time. No public or
102
+ private interaction with the people involved, including unsolicited interaction
103
+ with those enforcing the Code of Conduct, is allowed during this period.
104
+ Violating these terms may lead to a permanent ban.
105
+
106
+ ### 4. Permanent Ban
107
+
108
+ **Community Impact**: Demonstrating a pattern of violation of community
109
+ standards, including sustained inappropriate behavior, harassment of an
110
+ individual, or aggression toward or disparagement of classes of individuals.
111
+
112
+ **Consequence**: A permanent ban from any sort of public interaction within the
113
+ community.
114
+
115
+ ## Attribution
116
+
117
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118
+ version 2.1, available at
119
+ [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
120
+
121
+ Community Impact Guidelines were inspired by
122
+ [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
123
+
124
+ For answers to common questions about this code of conduct, see the FAQ at
125
+ [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
126
+ [https://www.contributor-covenant.org/translations][translations].
127
+
128
+ [homepage]: https://www.contributor-covenant.org
129
+ [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
130
+ [Mozilla CoC]: https://github.com/mozilla/diversity
131
+ [FAQ]: https://www.contributor-covenant.org/faq
132
+ [translations]: https://www.contributor-covenant.org/translations
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in tracemake.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "test-unit", "~> 3.0"
data/Gemfile.lock ADDED
@@ -0,0 +1,26 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ tracemake (0.1.0)
5
+ json (~> 2.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ json (2.8.1)
11
+ power_assert (2.0.5)
12
+ rake (13.2.1)
13
+ test-unit (3.6.8)
14
+ power_assert
15
+
16
+ PLATFORMS
17
+ arm64-darwin-24
18
+ ruby
19
+
20
+ DEPENDENCIES
21
+ rake (~> 13.0)
22
+ test-unit (~> 3.0)
23
+ tracemake!
24
+
25
+ BUNDLED WITH
26
+ 2.6.0.dev
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 Yuta Saito
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,71 @@
1
+ # Tracemake
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/tracemake.svg)](https://badge.fury.io/rb/tracemake)
4
+
5
+ A tool to trace `make` command execution and convert it to Chrome Tracing format. This gem allows tracking the execution time of each command in a make process.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'tracemake'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ ```bash
18
+ $ bundle install
19
+ ```
20
+
21
+ Or install it yourself as:
22
+
23
+ ```bash
24
+ $ gem install tracemake
25
+ ```
26
+
27
+ ## Usage
28
+
29
+ ### 1. Run make with this gem as the shell:
30
+
31
+ ```bash
32
+ make SHELL="tracemake shell" -j8
33
+ ```
34
+
35
+ ### 2. Convert the trace to Chrome Tracing format:
36
+
37
+ ```bash
38
+ tracemake aggregate -o make-trace.json
39
+ ```
40
+
41
+ ### 3. Open the resulting JSON file in Chrome's chrome://tracing or https://ui.perfetto.dev/
42
+
43
+ The trace file will be created in the current directory as `.make.trace`. You can override this location by setting the `TRACE_FILE` environment variable:
44
+
45
+ ```bash
46
+ TRACE_FILE=/path/to/trace make SHELL="tracemake shell" -j8
47
+ ```
48
+
49
+ > **Note**: When running multiple make commands in sequence, make sure to remove the `.make.trace` file before each run to avoid mixing traces from different make processes:
50
+ > ```bash
51
+ > rm -f .make.trace
52
+ > make SHELL="tracemake shell" -j8
53
+ > ```
54
+
55
+ ## Development
56
+
57
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
58
+
59
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
60
+
61
+ ## Contributing
62
+
63
+ Bug reports and pull requests are welcome on GitHub at https://github.com/kateinoigakukun/tracemake.
64
+
65
+ ## License
66
+
67
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
68
+
69
+ ## Code of Conduct
70
+
71
+ Everyone interacting in the Tracemake project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/tracemake/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/**/*_test.rb"]
10
+ end
11
+
12
+ task default: :test
data/bin/console ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "tracemake"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ require "irb"
11
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/exe/tracemake ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "../lib/tracemake"
5
+
6
+ Tracemake::CLI.new(ARGV.dup).run
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Tracemake
4
+ VERSION = "0.1.0"
5
+ end
data/lib/tracemake.rb ADDED
@@ -0,0 +1,240 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+ require "set"
5
+ require "optparse"
6
+ require "fileutils"
7
+ require_relative "tracemake/version"
8
+
9
+ module Tracemake
10
+ class Error < StandardError; end
11
+
12
+ # Represents a time span for a command execution
13
+ class Span < Struct.new(:start, :pid, :sid, :command, :stop)
14
+ def name
15
+ _command = command
16
+ _command = command[1..-1] if command[0] == "-c"
17
+ _command.join(" ")
18
+ end
19
+
20
+ def b_event
21
+ {
22
+ "name" => name,
23
+ "ph" => "B",
24
+ "ts" => start * 1_000_000,
25
+ "pid" => 0,
26
+ "tid" => sid,
27
+ "args" => {
28
+ "command" => command
29
+ }
30
+ }
31
+ end
32
+
33
+ def e_event
34
+ {
35
+ "name" => name,
36
+ "ph" => "E",
37
+ "ts" => stop * 1_000_000,
38
+ "pid" => 0,
39
+ "tid" => sid,
40
+ "args" => {}
41
+ }
42
+ end
43
+ end
44
+
45
+ # Manages slots for process visualization
46
+ class Slots
47
+ attr_reader :slot_by_pid, :busy_slots, :number_of_slots
48
+
49
+ def initialize
50
+ @slot_by_pid = {}
51
+ @busy_slots = Set.new
52
+ @number_of_slots = 0
53
+ end
54
+
55
+ def schedule(pid)
56
+ @number_of_slots.times do |i|
57
+ unless @busy_slots.include?(i)
58
+ @busy_slots.add(i)
59
+ @slot_by_pid[pid] = i
60
+ return i
61
+ end
62
+ end
63
+
64
+ slot_id = @number_of_slots
65
+ @number_of_slots += 1
66
+ @busy_slots.add(slot_id)
67
+ @slot_by_pid[pid] = slot_id
68
+ slot_id
69
+ end
70
+
71
+ def free(pid)
72
+ slot_id = @slot_by_pid[pid]
73
+ return if slot_id.nil?
74
+ @busy_slots.delete(slot_id)
75
+ @slot_by_pid.delete(pid)
76
+ end
77
+ end
78
+
79
+ # Writer for MakeTrace format
80
+ class MakeTraceWriter
81
+ def initialize(trace_file)
82
+ @trace_file = trace_file
83
+ FileUtils.mkdir_p(File.dirname(@trace_file))
84
+ end
85
+
86
+ def write_begin_event(pid, time, args)
87
+ write_event({
88
+ "pid" => pid,
89
+ "type" => "B",
90
+ "time" => time,
91
+ "args" => args
92
+ })
93
+ end
94
+
95
+ def write_end_event(pid, time, exit_status = nil)
96
+ event = {
97
+ "pid" => pid,
98
+ "type" => "E",
99
+ "time" => time
100
+ }
101
+ event["exit_status"] = exit_status if exit_status
102
+ write_event(event)
103
+ end
104
+
105
+ private
106
+
107
+ def write_event(event)
108
+ File.open(@trace_file, "a") do |f|
109
+ f.flock(File::LOCK_EX)
110
+ f.write(JSON.generate(event) + "\n")
111
+ f.flush
112
+ end
113
+ end
114
+ end
115
+
116
+ # Main class for converting make trace to Chrome Tracing format
117
+ class MakeTrace2ChromeTracing
118
+ def initialize
119
+ @open_spans = Set.new
120
+ @closed_spans = []
121
+ end
122
+
123
+ def generate(input_file, output_file)
124
+ events = parse_events(input_file)
125
+ process_events(events)
126
+ spans = @closed_spans.sort_by(&:start)
127
+ generate_output(spans, output_file)
128
+ end
129
+
130
+ private
131
+
132
+ def parse_events(input_file)
133
+ events = []
134
+ lines = File.readlines(input_file)
135
+ while line = lines.shift
136
+ events << JSON.parse(line)
137
+ end
138
+ events.sort_by { |e| e["time"] }
139
+ end
140
+
141
+ def process_events(events)
142
+ slots = Slots.new
143
+
144
+ events.each do |event|
145
+ if event["type"] == "B"
146
+ pid, ts, cmd = event["pid"], event["time"], event["args"]
147
+ sid = slots.schedule(pid)
148
+ @open_spans.add(Span.new(ts, pid, sid, cmd, nil))
149
+ elsif event["type"] == "E"
150
+ pid, ts = event["pid"], event["time"]
151
+ slots.free(pid)
152
+
153
+ found = false
154
+ @open_spans.each do |span|
155
+ if span.pid == pid
156
+ @open_spans.delete(span)
157
+ span.stop = ts
158
+ @closed_spans << span
159
+ found = true
160
+ break
161
+ end
162
+ end
163
+ $stderr.puts "Warning: no start for pid #{pid}" unless found
164
+ end
165
+ end
166
+ end
167
+
168
+ def generate_output(spans, output_file)
169
+ events = []
170
+ spans.each do |span|
171
+ events << span.b_event
172
+ events << span.e_event
173
+ end
174
+
175
+ File.write(
176
+ output_file,
177
+ JSON.generate({ "traceEvents" => events, "displayTimeUnit" => "ms" })
178
+ )
179
+ end
180
+ end
181
+
182
+ # Command line interface
183
+ class CLI
184
+ def initialize(argv)
185
+ @argv = argv
186
+ @trace_file = ENV["TRACE_FILE"] || ".make.trace"
187
+ end
188
+
189
+ def run
190
+ case @argv.shift
191
+ when "shell"
192
+ run_shell
193
+ when "aggregate"
194
+ run_aggregate
195
+ else
196
+ show_usage
197
+ end
198
+ end
199
+
200
+ private
201
+
202
+ def run_shell
203
+ shell_args = @argv
204
+ writer = MakeTraceWriter.new(@trace_file)
205
+ writer.write_begin_event(Process.pid, Time.now.to_f, shell_args)
206
+
207
+ Kernel.system("/bin/sh", *shell_args)
208
+ exit_status = $?
209
+
210
+ writer.write_end_event(Process.pid, Time.now.to_f, exit_status.exitstatus)
211
+ Kernel.exit(exit_status.exitstatus)
212
+ end
213
+
214
+ def run_aggregate
215
+ options = {}
216
+ OptionParser.new do |opts|
217
+ opts.banner = "Usage: tracemake aggregate [options]"
218
+ opts.on("-o", "--output FILE", "Output file") do |v|
219
+ options[:output] = v
220
+ end
221
+ end.parse!(@argv)
222
+
223
+ output_file = options[:output]
224
+ if output_file.nil?
225
+ puts "Output file is required."
226
+ exit 1
227
+ end
228
+
229
+ processor = MakeTrace2ChromeTracing.new
230
+ processor.generate(@trace_file, output_file)
231
+ puts "Trace aggregated to #{output_file}"
232
+ end
233
+
234
+ def show_usage
235
+ puts "Usage: tracemake aggregate [<input_file>] -o <output_file>"
236
+ puts " tracemake shell <command>"
237
+ exit 1
238
+ end
239
+ end
240
+ end
data/sig/tracemake.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Tracemake
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tracemake
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - kateinoigakukun
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 2025-04-15 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: json
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '2.0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '2.0'
26
+ description: This gem allows tracking the execution time of each command in a make
27
+ process by converting the trace to Chrome Tracing format
28
+ email:
29
+ - kateinoigakukun@gmail.com
30
+ executables:
31
+ - tracemake
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - CODE_OF_CONDUCT.md
36
+ - Gemfile
37
+ - Gemfile.lock
38
+ - LICENSE.txt
39
+ - README.md
40
+ - Rakefile
41
+ - bin/console
42
+ - bin/setup
43
+ - exe/tracemake
44
+ - lib/tracemake.rb
45
+ - lib/tracemake/version.rb
46
+ - sig/tracemake.rbs
47
+ homepage: https://github.com/kateinoigakukun/tracemake
48
+ licenses:
49
+ - MIT
50
+ metadata:
51
+ homepage_uri: https://github.com/kateinoigakukun/tracemake
52
+ source_code_uri: https://github.com/kateinoigakukun/tracemake
53
+ changelog_uri: https://github.com/kateinoigakukun/tracemake/blob/main/CHANGELOG.md
54
+ rdoc_options: []
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 2.6.0
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ requirements: []
68
+ rubygems_version: 3.6.0.dev
69
+ specification_version: 4
70
+ summary: A tool to trace make command execution and convert it to Chrome Tracing format
71
+ test_files: []