From 4d45983f71ab8b701fefd7ef5cdc30992e1d35ea Mon Sep 17 00:00:00 2001 From: Jorge Morante Date: Wed, 18 May 2022 15:11:54 +0200 Subject: [PATCH] WIP all the things --- .gitignore | 1 + Dockerfile | 24 +++++++++++++++++++----- benchmark.sh | 13 +++++++++++++ docker-compose.yml | 10 ++++++++++ lib/fingers/commands/load_config.rb | 2 +- lib/fingers/commands/start.rb | 6 ++++++ lib/fingers/commands/trace_start.rb | 3 +-- lib/fingers/hinter.rb | 1 + lib/fingers/logger.rb | 2 +- lib/tmux.rb | 6 ++++++ spec/acceptance/performance_spec.rb | 21 ++++----------------- spec/conf/basic.conf | 2 +- spec/conf/benchmark.conf | 2 +- 13 files changed, 65 insertions(+), 28 deletions(-) create mode 100755 benchmark.sh create mode 100644 docker-compose.yml diff --git a/.gitignore b/.gitignore index d00b45e..0361a56 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ node_modules/ vendor/bundle .cache .byebug_history +shared diff --git a/Dockerfile b/Dockerfile index 81109c5..453991b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,14 +1,14 @@ ARG RUBY_VERSION=2.6.10 FROM ruby:$RUBY_VERSION -ARG TMUX_VERSION=2.9 +ARG TMUX_VERSION=3.2 -COPY . /app -WORKDIR /app +COPY spec/use-tmux.sh /tmp/use-tmux.sh +COPY spec/install-tmux-versions.sh /tmp/install-tmux-versions.sh # Run CI scripts -RUN CI_TMUX_VERSION=$TMUX_VERSION /app/spec/install-tmux-versions.sh -RUN /app/spec/use-tmux.sh $TMUX_VERSION +RUN CI_TMUX_VERSION=$TMUX_VERSION /tmp/install-tmux-versions.sh +RUN /tmp/use-tmux.sh $TMUX_VERSION # Install linux-perf RUN apt-get update && apt-get install -y linux-perf-5.10 @@ -16,10 +16,24 @@ RUN apt-get update && apt-get install -y linux-perf-5.10 # Mock action stub globally RUN ln -s /app/spec/action-stub.sh /usr/local/bin/action-stub +# Install hyperfine +RUN wget https://github.com/sharkdp/hyperfine/releases/download/v1.13.0/hyperfine_1.13.0_amd64.deb +RUN dpkg -i hyperfine_1.13.0_amd64.deb + +COPY Gemfile /app/Gemfile +COPY Gemfile.lock /app/Gemfile.lock +WORKDIR /app + # Install ruby stuff RUN gem install bundler RUN bundle install +# Install rbspy +RUN wget https://github.com/rbspy/rbspy/releases/download/v0.12.1/rbspy-x86_64-musl.tar.gz -O /tmp/rbspy.tar.gz +RUN cd /tmp && tar pfx /tmp/rbspy.tar.gz +RUN mv /tmp/rbspy-x86_64-musl /usr/local/bin/rbspy +RUN chmod a+x /usr/local/bin/rbspy + # Expose byebug remote debugging port EXPOSE 1048 diff --git a/benchmark.sh b/benchmark.sh new file mode 100755 index 0000000..43c61c6 --- /dev/null +++ b/benchmark.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +tmux -f spec/conf/benchmark.conf new-session -d +tmux resize-window -t '@0' -x 300 -y 100 +tmux send-keys 'COLUMNS=$COLUMNS LINES=$LINES ruby spec/fill_screen.rb' +tmux send-keys Enter + +#tmux send-keys 'rbspy record -f /app/shared/report.svg -- /usr/local/bin/ruby --disable-gems bin/fingers start fingers-mode $TMUX_PANE self' +#tmux send-keys Enter + +tmux send-keys 'hyperfine "/usr/local/bin/ruby --disable-gems bin/fingers trace_start"' +#tmux send-keys 'hyperfine "/usr/local/bin/ruby --disable-gems bin/fingers start fingers-mode $TMUX_PANE self"' +tmux send-keys Enter diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..5b742fd --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,10 @@ +version: "3.9" +services: + shell: + cap_add: + - SYS_PTRACE + build: + context: . + dockerfile: Dockerfile + volumes: + - .:/app diff --git a/lib/fingers/commands/load_config.rb b/lib/fingers/commands/load_config.rb index c10defb..e68775e 100644 --- a/lib/fingers/commands/load_config.rb +++ b/lib/fingers/commands/load_config.rb @@ -98,7 +98,7 @@ class Fingers::Commands::LoadConfig < Fingers::Commands::Base ruby_bin = "#{RbConfig.ruby} --disable-gems" `tmux bind-key #{Fingers.config.key} run-shell -b "#{ruby_bin} #{cli} start '#{input_mode}' '\#{pane_id}' self >>#{Fingers::Dirs::LOG_PATH} 2>&1"` - `tmux bind-key F run-shell -b "#{ruby_bin} #{cli} start '#{input_mode}' '\#{pane_id}' other >>#{Fingers::Dirs::LOG_PATH} 2>&1"` + `tmux bind-key O run-shell -b "#{ruby_bin} #{cli} start '#{input_mode}' '\#{pane_id}' other >>#{Fingers::Dirs::LOG_PATH} 2>&1"` setup_fingers_mode_bindings if input_mode == 'fingers-mode' end diff --git a/lib/fingers/commands/start.rb b/lib/fingers/commands/start.rb index 900243f..8d36f46 100644 --- a/lib/fingers/commands/start.rb +++ b/lib/fingers/commands/start.rb @@ -1,11 +1,17 @@ class PanePrinter def initialize(pane_tty) @pane_tty = pane_tty + @buf = '' @file = File.open(@pane_tty, 'w') end def print(msg) @file.print(msg) + #@buf += msg + end + + def flush + #@file.print(@buf) end end diff --git a/lib/fingers/commands/trace_start.rb b/lib/fingers/commands/trace_start.rb index e067b30..9a82725 100644 --- a/lib/fingers/commands/trace_start.rb +++ b/lib/fingers/commands/trace_start.rb @@ -1,6 +1,5 @@ class Fingers::Commands::TraceStart < Fingers::Commands::Base def run - Fingers.benchmark_stamp('boot:start') - Fingers.benchmark_stamp('ready-for-input:start') + exit 0 end end diff --git a/lib/fingers/hinter.rb b/lib/fingers/hinter.rb index cf4502a..cf9aeac 100644 --- a/lib/fingers/hinter.rb +++ b/lib/fingers/hinter.rb @@ -25,6 +25,7 @@ class ::Fingers::Hinter process_line(lines[-1], '') STDOUT.flush + output.flush build_lookup_table! end diff --git a/lib/fingers/logger.rb b/lib/fingers/logger.rb index 23482c6..fa1deea 100644 --- a/lib/fingers/logger.rb +++ b/lib/fingers/logger.rb @@ -7,7 +7,7 @@ module Fingers @logger = Logger.new( Fingers::Dirs::LOG_PATH ) - @logger.level = Logger.const_get(ENV.fetch('FINGERS_LOG_LEVEL', 'DEBUG')) + @logger.level = Logger.const_get(ENV.fetch('FINGERS_LOG_LEVEL', 'INFO')) @logger end diff --git a/lib/tmux.rb b/lib/tmux.rb index ca3ef88..27e8fd2 100644 --- a/lib/tmux.rb +++ b/lib/tmux.rb @@ -1,3 +1,6 @@ +# frozen_string_literal: true + +# rubocop:disable Metrics/ClassLength class Tmux include Singleton @@ -211,3 +214,6 @@ class Tmux socket end end + +#Tmux = TmuxControl +# rubocop:enable Metrics/ClassLength diff --git a/spec/acceptance/performance_spec.rb b/spec/acceptance/performance_spec.rb index 86f9c5f..0d86c1e 100644 --- a/spec/acceptance/performance_spec.rb +++ b/spec/acceptance/performance_spec.rb @@ -5,25 +5,12 @@ require 'benchmark' describe 'performance', performance: true do include_context 'tmuxomatic setup' let(:config_name) { 'benchmark' } - let(:tmuxomatic_window_width) { 1000 } - let(:tmuxomatic_window_height) { 1000 } + let(:tmuxomatic_window_width) { 100 } + let(:tmuxomatic_window_height) { 100 } it 'runs smooooooth' do - exec('COLUMNS=$COLUMNS LINES=$LINES ruby spec/fill_screen.rb') - - pane_id = tmuxomatic.panes.first.pane_id - ruby = RbConfig.ruby - - byebug - - #puts "Measuring fingers execution" - #fingers_measurement = Benchmark.measure do - #`FINGERS_TMUX_SOCKET=tmuxomatic_inner #{ruby} -e "puts :hello"` - ##`FINGERS_TMUX_SOCKET=tmuxomatic_inner #{ruby} --disable-gems bin/fingers start fingers-mode '#{pane_id}'` - #end - - #puts fingers_measurement - #puts "measure: #{fingers_measurement.real * 1000.0} ms" + exec('COLUMNS=$COLUMNS LINES=$LINES ruby spec/fill_screen.rb') + exec(%(hyperfine --export-json /tmp/perf.json "#{ruby} --disable-gems bin/fingers start fingers-mode $TMUX_PANE self")) end end diff --git a/spec/conf/basic.conf b/spec/conf/basic.conf index aecd907..213da0f 100644 --- a/spec/conf/basic.conf +++ b/spec/conf/basic.conf @@ -1,3 +1,3 @@ set -g prefix C-a set -g default-terminal 'screen-256color' -run 'tmux-fingers.tmux' +run '/app/tmux-fingers.tmux' diff --git a/spec/conf/benchmark.conf b/spec/conf/benchmark.conf index a7ac57e..11c5cb2 100644 --- a/spec/conf/benchmark.conf +++ b/spec/conf/benchmark.conf @@ -1,4 +1,4 @@ set -g prefix C-a set -g @fingers-trace-perf '1' set -g default-terminal 'screen-256color' -run 'tmux-fingers.tmux' +run '/app/tmux-fingers.tmux'