From cf1619acb33f0b8c624decba1985b230f828bdb0 Mon Sep 17 00:00:00 2001 From: Jorge Morante Date: Wed, 13 Sep 2023 16:40:08 +0200 Subject: [PATCH] some testing and benchmarking fixes --- Dockerfile | 45 ++++------------------------- Makefile | 7 +---- Vagrantfile | 16 ---------- benchmark.sh | 16 +++++----- install-wizard.sh | 4 +-- spec/conf/basic.conf | 1 - spec/conf/benchmark.conf | 3 +- spec/fill_screen.cr | 28 ++++++++++++++++++ spec/fill_screen.rb | 10 ------- spec/install-tmux-versions.sh | 6 ++-- spec/lib/fingers/hinter_spec.cr | 1 + spec/lib/priority_queue_spec.cr | 20 ++++++------- spec/tmux_spec.cr | 31 ++++++++++++++++++++ spec/use-tmux.sh | 1 + src/fingers/commands/load_config.cr | 2 ++ src/fingers/commands/start.cr | 4 +++ src/fingers/config.cr | 4 ++- 17 files changed, 101 insertions(+), 98 deletions(-) delete mode 100644 Vagrantfile create mode 100644 spec/fill_screen.cr delete mode 100644 spec/fill_screen.rb create mode 100644 spec/tmux_spec.cr diff --git a/Dockerfile b/Dockerfile index 453991b..a28ec6f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,40 +1,7 @@ -ARG RUBY_VERSION=2.6.10 -FROM ruby:$RUBY_VERSION - -ARG TMUX_VERSION=3.2 - -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 /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 - -# 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 +FROM crystallang/crystal:latest-alpine +RUN apk upgrade && apk add bash libevent-dev ncurses-dev ncurses hyperfine +COPY ./spec/install-tmux-versions.sh /opt/install-tmux-versions.sh +COPY ./spec/use-tmux.sh /opt/use-tmux.sh +RUN bash /opt/install-tmux-versions.sh 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 - -CMD ["bundle", "exec", "rspec"] +CMD ["/bin/sh"] diff --git a/Makefile b/Makefile index e4fbc40..a03252a 100644 --- a/Makefile +++ b/Makefile @@ -2,9 +2,4 @@ default: docker build . -t fingers shell: default - docker run -it --rm fingers /bin/bash - -perf: default - docker run --security-opt seccomp=./docker-perf.json -it --rm fingers /bin/bash -#latest: - #docker build . -t fingers:ruby-latest-tmux-latest --build_arg TMUX_VERSION=3.3-rc --build-arg RUBY_VERSION=latest + docker run -it --rm -v $(shell pwd):/app fingers bash diff --git a/Vagrantfile b/Vagrantfile deleted file mode 100644 index 43446a1..0000000 --- a/Vagrantfile +++ /dev/null @@ -1,16 +0,0 @@ -# -*- mode: ruby -*- -# vi: set ft=ruby : - -# requires nfs-utils on host - -Vagrant.configure(2) do |config| - config.vm.provider 'virtualbox' do |v| - v.customize ['modifyvm', :id, '--cpuexecutioncap', '50'] - end - - config.vm.define 'ubuntu' do |machine| - machine.vm.box = 'ubuntu/focal64' - machine.vm.synced_folder '.', '/home/vagrant/shared' - machine.vm.provision 'shell', path: './spec/provisioning/ubuntu.sh' - end -end diff --git a/benchmark.sh b/benchmark.sh index 43c61c6..987a32e 100755 --- a/benchmark.sh +++ b/benchmark.sh @@ -1,13 +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' +/opt/use-tmux.sh 3.3a + +shards build --production +tmux -f /app/spec/conf/benchmark.conf new-session -d +tmux resize-window -t '@0' -x 300 -y 300 +tmux send-keys 'COLUMNS=300 LINES=100 crystal run spec/fill_screen.cr' 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 +sleep 5 -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 +tmux new-window 'hyperfine --warmup 5 "bin/tmux-fingers start %0 self" --export-markdown /tmp/benchmark-output' diff --git a/install-wizard.sh b/install-wizard.sh index 8e635a8..2057eef 100755 --- a/install-wizard.sh +++ b/install-wizard.sh @@ -113,7 +113,7 @@ tmux display-menu -T "tmux-fingers" \ "- $(get_message) " "" "" \ "- " "" ""\ "" \ - "$(binary_or_brew_label)" b "popup -E \"$CURRENT_DIR/install-wizard.sh $(binary_or_brew_action)\"" \ - "Build from source" s "popup -E \"$CURRENT_DIR/install-wizard.sh install-from-source\"" \ + "$(binary_or_brew_label)" b "new-window \"$CURRENT_DIR/install-wizard.sh $(binary_or_brew_action)\"" \ + "Build from source" s "new-window \"$CURRENT_DIR/install-wizard.sh install-from-source\"" \ "" \ "Exit" q "" diff --git a/spec/conf/basic.conf b/spec/conf/basic.conf index 213da0f..fd9fd3f 100644 --- a/spec/conf/basic.conf +++ b/spec/conf/basic.conf @@ -1,3 +1,2 @@ -set -g prefix C-a set -g default-terminal 'screen-256color' run '/app/tmux-fingers.tmux' diff --git a/spec/conf/benchmark.conf b/spec/conf/benchmark.conf index 11c5cb2..d5de235 100644 --- a/spec/conf/benchmark.conf +++ b/spec/conf/benchmark.conf @@ -1,4 +1,3 @@ -set -g prefix C-a -set -g @fingers-trace-perf '1' +set -g @fingers-benchmark-mode '1' set -g default-terminal 'screen-256color' run '/app/tmux-fingers.tmux' diff --git a/spec/fill_screen.cr b/spec/fill_screen.cr new file mode 100644 index 0000000..6835259 --- /dev/null +++ b/spec/fill_screen.cr @@ -0,0 +1,28 @@ +require "uuid" + +SEGMENT_LENGTH = 16 +COLUMNS = ENV["COLUMNS"].to_i +LINES = ENV["LINES"].to_i + +def compute_divisions + result = (COLUMNS / SEGMENT_LENGTH).floor.to_i + + loop do + break if (result * SEGMENT_LENGTH + (result - 1)) <= COLUMNS + result = result - 1 + end + + result +end + +DIVISIONS = compute_divisions + +LINES.times do + codes = [] of String + + DIVISIONS.times do + codes << UUID.random.to_s.gsub("-", "").to_s[0..SEGMENT_LENGTH - 1] + end + + puts codes.join(" ") +end diff --git a/spec/fill_screen.rb b/spec/fill_screen.rb deleted file mode 100644 index 4c35438..0000000 --- a/spec/fill_screen.rb +++ /dev/null @@ -1,10 +0,0 @@ -require 'securerandom' - -ENV['LINES'].to_i.times do - codes = [] - (ENV['COLUMNS'].to_i / 16 - 1).times do - codes << SecureRandom.hex(8).to_s.tr('abcdef', '123456') - end - - puts codes.join(' ') -end diff --git a/spec/install-tmux-versions.sh b/spec/install-tmux-versions.sh index e8a6a95..1a12593 100755 --- a/spec/install-tmux-versions.sh +++ b/spec/install-tmux-versions.sh @@ -3,11 +3,11 @@ if [[ -n "$CI_TMUX_VERSION" ]]; then VERSIONS=("$CI_TMUX_VERSION") else - VERSIONS=("2.1" "2.2" "2.3" "2.4" "2.5" "2.6" "2.7" "2.8" "2.9" "2.9a" "3.0" "3.0a") + VERSIONS=("3.0a" "3.1c" "3.2a" "3.3a") fi -sudo mkdir -p /opt -sudo chmod a+w /opt +mkdir -p /opt +chmod a+w /opt pushd /tmp for version in "${VERSIONS[@]}"; diff --git a/spec/lib/fingers/hinter_spec.cr b/spec/lib/fingers/hinter_spec.cr index 783d325..7effc36 100644 --- a/spec/lib/fingers/hinter_spec.cr +++ b/spec/lib/fingers/hinter_spec.cr @@ -1,4 +1,5 @@ require "spec" +require "../../spec_helper.cr" require "../../../src/fingers/hinter" require "../../../src/fingers/state" require "../../../src/fingers/config" diff --git a/spec/lib/priority_queue_spec.cr b/spec/lib/priority_queue_spec.cr index e47ad80..e7f5052 100644 --- a/spec/lib/priority_queue_spec.cr +++ b/spec/lib/priority_queue_spec.cr @@ -4,13 +4,13 @@ require "../../src/priority_queue" describe PriorityQueue do it "transforms tmux status line format into escape sequences" do test = [ - [6, "drink tea"], [3, "Clear drains"], - [4, "Feed cat"], + [6, "drink tea"], [5, "Make tea"], - [6, "eat biscuit"], - [1, "Solve RC tasks"], + [4, "Feed cat"], + [7, "eat biscuit"], [2, "Tax return"], + [1, "Solve RC tasks"], ] results = [] of String @@ -25,13 +25,13 @@ describe PriorityQueue do end expected = [ - "Solve RC tasks", - "Tax return", - "Clear drains", - "Feed cat", - "Make tea", - "drink tea", "eat biscuit", + "drink tea", + "Make tea", + "Feed cat", + "Clear drains", + "Tax return", + "Solve RC tasks", ] results.should eq expected diff --git a/spec/tmux_spec.cr b/spec/tmux_spec.cr new file mode 100644 index 0000000..2ac6a13 --- /dev/null +++ b/spec/tmux_spec.cr @@ -0,0 +1,31 @@ +require "./spec_helper" +require "../src/tmux" + +describe Tmux do + it "returns a semantic version for versions without letters" do + result = Tmux.tmux_version_to_semver("3.1") + result.major.should eq 3 + result.minor.should eq 1 + result.patch.should eq 0 + end + + it "returns a semantic version for versions with letters" do + result = Tmux.tmux_version_to_semver("3.1b") + result.major.should eq 3 + result.minor.should eq 1 + result.patch.should eq 2 + end + + it "returns a semantic version for versions with letters" do + result = Tmux.tmux_version_to_semver("3.3a") + result.major.should eq 3 + result.minor.should eq 3 + result.patch.should eq 1 + end + + it "returns comparable semversions" do + result = Tmux.tmux_version_to_semver("3.0a") >= Tmux.tmux_version_to_semver("3.1") + + result.should eq false + end +end diff --git a/spec/use-tmux.sh b/spec/use-tmux.sh index 1a0c39f..9d2a40b 100755 --- a/spec/use-tmux.sh +++ b/spec/use-tmux.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash version="$1" +rm -rf /usr/bin/tmux rm -rf /usr/local/bin/tmux ln -s /opt/tmux-${version}/tmux /usr/local/bin/tmux ln -s /opt/tmux-${version}/tmux /usr/bin/tmux diff --git a/src/fingers/commands/load_config.cr b/src/fingers/commands/load_config.cr index fd3fd1a..e540007 100644 --- a/src/fingers/commands/load_config.cr +++ b/src/fingers/commands/load_config.cr @@ -43,6 +43,8 @@ class Fingers::Commands::LoadConfig < Fingers::Commands::Base config.alt_action = value when "shift_action" config.shift_action = value + when "benchmark_mode" + config.benchmark_mode = value when "hint_style" config.hint_style = tmux.parse_style(value) when "selected_hint_style" diff --git a/src/fingers/commands/start.cr b/src/fingers/commands/start.cr index e19d42a..1ac0ed5 100644 --- a/src/fingers/commands/start.cr +++ b/src/fingers/commands/start.cr @@ -31,6 +31,10 @@ module Fingers::Commands track_options_to_restore! show_hints + if Fingers.config.benchmark_mode == "1" + exit(0) + end + handle_input teardown diff --git a/src/fingers/config.cr b/src/fingers/config.cr index d4334b4..0d245c9 100644 --- a/src/fingers/config.cr +++ b/src/fingers/config.cr @@ -8,6 +8,7 @@ module Fingers property keyboard_layout : String property patterns : Array(String) property alphabet : Array(String) + property benchmark_mode : String property main_action : String property ctrl_action : String property alt_action : String @@ -69,7 +70,8 @@ module Fingers @selected_highlight_style = FORMAT_PRINTER.print("fg=green,dim"), @highlight_style = FORMAT_PRINTER.print("fg=yellow,dim"), @backdrop_style = FORMAT_PRINTER.print("bg=black,fg=color250"), - @tmux_version = "" + @tmux_version = "", + @benchmark_mode = "0" ) end