aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-02-01 02:07:09 +0900
committernsfisis <nsfisis@gmail.com>2026-02-01 02:09:26 +0900
commit1964f77d03eb647dcf46d63dde68d7ae7301604f (patch)
tree0e00d7caf3031fa86decaa0cbc226cc1e521b914
parent9c39c8269e5c8a254081ce6cd43d3cd3da440280 (diff)
downloadnsfisis.dev-1964f77d03eb647dcf46d63dde68d7ae7301604f.tar.gz
nsfisis.dev-1964f77d03eb647dcf46d63dde68d7ae7301604f.tar.zst
nsfisis.dev-1964f77d03eb647dcf46d63dde68d7ae7301604f.zip
feat(nuldoc): add --profile flag to build command
-rw-r--r--services/nuldoc/Rakefile8
-rw-r--r--services/nuldoc/lib/nuldoc/cli.rb6
-rw-r--r--services/nuldoc/lib/nuldoc/commands/build.rb9
-rw-r--r--services/nuldoc/lib/nuldoc/pipeline.rb16
4 files changed, 30 insertions, 9 deletions
diff --git a/services/nuldoc/Rakefile b/services/nuldoc/Rakefile
index 811398f4..4dfe4317 100644
--- a/services/nuldoc/Rakefile
+++ b/services/nuldoc/Rakefile
@@ -6,7 +6,8 @@ RuboCop::RakeTask.new
desc 'Build the site'
task :build do
config = Nuldoc::ConfigLoader.load_config(Nuldoc::ConfigLoader.default_config_path)
- Nuldoc::Commands::Build.run(config)
+ profile = ENV.key?('PROFILE')
+ Nuldoc::Commands::Build.run(config, profile: profile)
end
desc 'Start development server'
@@ -20,3 +21,8 @@ task :new, [:type] do |_t, args|
config = Nuldoc::ConfigLoader.load_config(Nuldoc::ConfigLoader.default_config_path)
Nuldoc::Commands::New.run(config, type: args[:type], date: nil)
end
+
+desc 'Benchmark the build'
+task :bench do
+ sh 'hyperfine', '--warmup', '1', 'rake build'
+end
diff --git a/services/nuldoc/lib/nuldoc/cli.rb b/services/nuldoc/lib/nuldoc/cli.rb
index f3a18da9..0face71c 100644
--- a/services/nuldoc/lib/nuldoc/cli.rb
+++ b/services/nuldoc/lib/nuldoc/cli.rb
@@ -5,9 +5,11 @@ module Nuldoc
class BuildCommand < Dry::CLI::Command
desc 'Build the site'
- def call(**)
+ option :profile, type: :boolean, default: false, desc: 'Profile each build step'
+
+ def call(**options)
config = ConfigLoader.load_config(ConfigLoader.default_config_path)
- Commands::Build.run(config)
+ Commands::Build.run(config, profile: options[:profile])
end
end
diff --git a/services/nuldoc/lib/nuldoc/commands/build.rb b/services/nuldoc/lib/nuldoc/commands/build.rb
index 330d3245..bec741d9 100644
--- a/services/nuldoc/lib/nuldoc/commands/build.rb
+++ b/services/nuldoc/lib/nuldoc/commands/build.rb
@@ -1,12 +1,13 @@
module Nuldoc
module Commands
class Build
- def self.run(config)
- new(config).run
+ def self.run(config, profile: false)
+ new(config, profile: profile).run
end
- def initialize(config)
+ def initialize(config, profile: false)
@config = config
+ @profile = profile
end
def run
@@ -35,7 +36,7 @@ module Nuldoc
pipeline.step(:copy_blog_assets) { copy_blog_asset_files }
pipeline.step(:copy_slides_assets) { copy_slides_asset_files }
- pipeline.execute
+ pipeline.execute(profile: @profile)
end
private
diff --git a/services/nuldoc/lib/nuldoc/pipeline.rb b/services/nuldoc/lib/nuldoc/pipeline.rb
index 7a30049a..802bba75 100644
--- a/services/nuldoc/lib/nuldoc/pipeline.rb
+++ b/services/nuldoc/lib/nuldoc/pipeline.rb
@@ -14,10 +14,22 @@ module Nuldoc
@steps[name] = Step.new(name: name, deps: deps, block: block)
end
- def execute
+ def execute(profile: false)
results = {}
+ total_start = Process.clock_gettime(Process::CLOCK_MONOTONIC) if profile
tsort_each do |name|
- results[name] = @steps[name].block.call(results)
+ if profile
+ start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
+ results[name] = @steps[name].block.call(results)
+ elapsed = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start
+ warn format('[profile] %-30<name>s %8.3<ms>f ms', name: name, ms: elapsed * 1000)
+ else
+ results[name] = @steps[name].block.call(results)
+ end
+ end
+ if profile
+ total_elapsed = Process.clock_gettime(Process::CLOCK_MONOTONIC) - total_start
+ warn format('[profile] %-30<name>s %8.3<ms>f ms', name: 'TOTAL', ms: total_elapsed * 1000)
end
results
end