Skip to content

Commit

Permalink
Add execution profiling
Browse files Browse the repository at this point in the history
  • Loading branch information
mbj committed Nov 21, 2022
1 parent 5b57790 commit 593ccc2
Show file tree
Hide file tree
Showing 19 changed files with 1,076 additions and 383 deletions.
8 changes: 8 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# v0.11.17 [unreleased]

* [#1352](https://github.com/mbj/mutant/pull/1352)

Add execution profiling via `--profile`. The output format is not stable
yet, still this profile is very useful to differentiate mutant load time from
target application load time.

# v0.11.16 2022-09-11

* [#1355](https://github.com/mbj/mutant/pull/1355)
Expand Down
101 changes: 55 additions & 46 deletions bin/mutant
Original file line number Diff line number Diff line change
@@ -1,55 +1,64 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

trap('INT') do |status|
effective_status = status ? status + 128 : 128
exit! effective_status
end
module Mutant
# Record executable timestamp
@executable_timestamp = Process.clock_gettime(Process::CLOCK_MONOTONIC)

trap('INT') do |status|
effective_status = status ? status + 128 : 128
exit! effective_status
end

require 'mutant'
require 'mutant'

Mutant::CLI.parse(
arguments: ARGV,
world: Mutant::WORLD
).either(
->(message) { Mutant::WORLD.stderr.puts(message); Kernel.exit(false) },
# rubocop:disable Metrics/BlockLength
lambda do |command|
status =
WORLD.record(:cli_parse) do
CLI.parse(
arguments: ARGV,
world: Mutant::WORLD
)
end.either(
->(message) { Mutant::WORLD.stderr.puts(message); Kernel.exit(false) },
# rubocop:disable Metrics/BlockLength
lambda do |command|
if command.zombie?
$stderr.puts('Running mutant zombified!')
Mutant::Zombifier.call(
namespace: :Zombie,
load_path: $LOAD_PATH,
kernel: Kernel,
pathname: Pathname,
require_highjack: Mutant::RequireHighjack
.public_method(:call)
.to_proc
.curry
.call(Kernel),
root_require: 'mutant',
includes: %w[
adamantium
anima
concord
equalizer
mprelude
mutant
unparser
variable
]
)
command = WORLD.record(:zombify) do
$stderr.puts('Running mutant zombified!')
Zombifier.call(
namespace: :Zombie,
load_path: $LOAD_PATH,
kernel: Kernel,
pathname: Pathname,
require_highjack: RequireHighjack
.public_method(:call)
.to_proc
.curry
.call(Kernel),
root_require: 'mutant',
includes: %w[
adamantium
anima
concord
equalizer
mprelude
mutant
unparser
variable
]
)

Zombie::Mutant::CLI.parse(
arguments: ARGV,
world: Zombie::Mutant::WORLD
).from_right.call
else
command.call
Zombie::Mutant::CLI.parse(
arguments: ARGV,
world: Mutant::WORLD
).from_right
end
end

Kernel.exit(status)
end
# rubocop:enable Metrics/BlockLength
)
WORLD.record(:execute) { command.call }.tap do |status|
WORLD.recorder.print_profile(WORLD.stderr) if command.print_profile?
WORLD.kernel.exit(status)
end
end
# rubocop:enable Metrics/BlockLength
)
end
Loading

0 comments on commit 593ccc2

Please sign in to comment.