Class: Ast::Merge::Git::BenchmarkAdapterSession
- Inherits:
-
Object
- Object
- Ast::Merge::Git::BenchmarkAdapterSession
- Defined in:
- lib/ast/merge/git/local_benchmark.rb,
sig/ast/merge/git.rbs
Overview
Owns one long-lived benchmark adapter subprocess and its JSONL exchange.
Instance Attribute Summary collapse
-
#spawn_duration_ns ⇒ Integer?
readonly
Returns the value of attribute spawn_duration_ns.
Instance Method Summary collapse
- #close ⇒ void
-
#initialize(driver_path:, chdir:, timeout:, env: {}) ⇒ BenchmarkAdapterSession
constructor
A new instance of BenchmarkAdapterSession.
- #request(payload) ⇒ Hash[String, untyped]
- #start ⇒ BenchmarkAdapterSession
Constructor Details
#initialize(driver_path:, chdir:, timeout:, env: {}) ⇒ BenchmarkAdapterSession
Returns a new instance of BenchmarkAdapterSession.
417 418 419 420 421 422 |
# File 'lib/ast/merge/git/local_benchmark.rb', line 417 def initialize(driver_path:, chdir:, timeout:, env: {}) @driver_path = Pathname(driver_path). @chdir = Pathname(chdir). @timeout = timeout @env = env end |
Instance Attribute Details
#spawn_duration_ns ⇒ Integer? (readonly)
Returns the value of attribute spawn_duration_ns.
415 416 417 |
# File 'lib/ast/merge/git/local_benchmark.rb', line 415 def spawn_duration_ns @spawn_duration_ns end |
Instance Method Details
#close ⇒ void
This method returns an undefined value.
459 460 461 462 463 464 465 466 467 468 |
# File 'lib/ast/merge/git/local_benchmark.rb', line 459 def close return unless @process @stdin.close unless @stdin.closed? terminate unless @process.join(1) @stderr_reader.join(1) ensure [@stdin, @stdout, @stderr].compact.each { |io| io.close unless io.closed? } @process = nil end |
#request(payload) ⇒ Hash[String, untyped]
443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 |
# File 'lib/ast/merge/git/local_benchmark.rb', line 443 def request(payload) start started = monotonic_nanoseconds @stdin.puts(JSON.generate(payload)) @stdin.flush line = read_response_line response = JSON.parse(line) @request_count += 1 response.merge( 'round_trip_duration_ns' => monotonic_nanoseconds - started, 'session_request_index' => @request_count ) rescue Errno::EPIPE, IOError, JSON::ParserError => e raise LocalBenchmark::Error, "benchmark adapter session failed: #{e.}#{stderr_suffix}" end |
#start ⇒ BenchmarkAdapterSession
424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 |
# File 'lib/ast/merge/git/local_benchmark.rb', line 424 def start return self if @process started = monotonic_nanoseconds @stdin, @stdout, @stderr, @process = Open3.popen3( @env, @driver_path.to_s, 'benchmark-provider-session', chdir: @chdir.to_s ) [@stdin, @stdout, @stderr].each(&:binmode) @stderr_reader = Thread.new { @stderr.read } @spawn_duration_ns = monotonic_nanoseconds - started @request_count = 0 self rescue Errno::ENOENT => e raise LocalBenchmark::Error, "cannot start benchmark adapter session: #{e.}" end |