From bcda3e1f02dae0a2cad46464f9a9f9e4892b0068 Mon Sep 17 00:00:00 2001 From: Thomas Applencourt Date: Tue, 1 Oct 2024 16:21:20 +0000 Subject: [PATCH 1/6] Save exit code --- xprof/xprof.rb.in | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/xprof/xprof.rb.in b/xprof/xprof.rb.in index 0a2ed09a..c8bac62c 100755 --- a/xprof/xprof.rb.in +++ b/xprof/xprof.rb.in @@ -423,14 +423,17 @@ def launch_usr_bin(env, cmd) begin PTY.spawn(bash_env, *cmd) do |stdout, _stdin, _pid| + # Reading stdout will trigger Errno::EIO stdout.each { |line| print line } rescue Errno::EIO + # Wait for the PTY to finish, to set $? + Process.wait(_pid) + $? end - # Not sure how this exception can be triggered - rescue PTY::ChildExited - LOGGER.warn { 'Application Exited' } rescue Interrupt LOGGER.warn { 'Application Received Interrupt Signal' } + #SigINT is 2 + 2 rescue Errno::ENOENT warn("#{__FILE__}: Can't find executable #{cmd.first}") raise Errno::ENOENT From 563ad245f64682c479022c82592edd3e2d232f8b Mon Sep 17 00:00:00 2001 From: Thomas Applencourt Date: Tue, 1 Oct 2024 16:36:56 +0000 Subject: [PATCH 2/6] used it --- xprof/xprof.rb.in | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/xprof/xprof.rb.in b/xprof/xprof.rb.in index c8bac62c..54db070e 100755 --- a/xprof/xprof.rb.in +++ b/xprof/xprof.rb.in @@ -13,6 +13,8 @@ PREFIX = '@prefix@' DATAROOTDIR = File.join(PREFIX, 'share') DATADIR = DATAROOTDIR +$EXIT_CODE_USER_BINARY = 0 + $LOAD_PATH.unshift(DATADIR) if File.directory?(DATADIR) require 'open3' require 'fileutils' @@ -428,11 +430,11 @@ def launch_usr_bin(env, cmd) rescue Errno::EIO # Wait for the PTY to finish, to set $? Process.wait(_pid) - $? + return $?.exitstatus end rescue Interrupt LOGGER.warn { 'Application Received Interrupt Signal' } - #SigINT is 2 + # SigINT is 2 2 rescue Errno::ENOENT warn("#{__FILE__}: Can't find executable #{cmd.first}") @@ -685,7 +687,7 @@ def trace_and_on_node_processing(usr_argv) # Launch User Command begin - launch_usr_bin(h, usr_argv) + $EXIT_CODE_USER_BINARY = launch_usr_bin(h, usr_argv) rescue Errno::ENOENT teardown_lttng(syncd) raise @@ -742,7 +744,7 @@ def gm_processing(folder) fo.close end - exit(1) unless $?.success? + exit($?.success? ? $EXIT_CODE_USER_BINARY : $?.exitstatus) end # From 5e3721b150cc6ae0356fd597a32976669206e0ba Mon Sep 17 00:00:00 2001 From: Thomas Applencourt Date: Tue, 1 Oct 2024 19:27:27 +0000 Subject: [PATCH 3/6] add test --- integration_tests/general.bats | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/integration_tests/general.bats b/integration_tests/general.bats index fbeac370..8e7f3c8b 100644 --- a/integration_tests/general.bats +++ b/integration_tests/general.bats @@ -67,3 +67,8 @@ teardown_file() { [ "$status" != 0 ] rm out.pftrace } + +@test "exit_code_propagated" { + run $IPROF -- bash -c "exit 55" + [ "$status" == 55 ] +} From e2a19baf359d69820a9c3e2e4aabce9e78c7d2a1 Mon Sep 17 00:00:00 2001 From: Thomas Applencourt Date: Tue, 1 Oct 2024 19:51:54 +0000 Subject: [PATCH 4/6] fix no analysis --- integration_tests/general.bats | 3 +++ xprof/xprof.rb.in | 12 ++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/integration_tests/general.bats b/integration_tests/general.bats index 8e7f3c8b..b4784770 100644 --- a/integration_tests/general.bats +++ b/integration_tests/general.bats @@ -71,4 +71,7 @@ teardown_file() { @test "exit_code_propagated" { run $IPROF -- bash -c "exit 55" [ "$status" == 55 ] + + run $IPROF --no-analysis -- bash -c "exit 55" + [ "$status" == 55 ] } diff --git a/xprof/xprof.rb.in b/xprof/xprof.rb.in index 54db070e..d649cc22 100755 --- a/xprof/xprof.rb.in +++ b/xprof/xprof.rb.in @@ -13,7 +13,7 @@ PREFIX = '@prefix@' DATAROOTDIR = File.join(PREFIX, 'share') DATADIR = DATAROOTDIR -$EXIT_CODE_USER_BINARY = 0 +$EXIT_CODE_XPROF = 0 $LOAD_PATH.unshift(DATADIR) if File.directory?(DATADIR) require 'open3' @@ -687,7 +687,7 @@ def trace_and_on_node_processing(usr_argv) # Launch User Command begin - $EXIT_CODE_USER_BINARY = launch_usr_bin(h, usr_argv) + $EXIT_CODE_XPROF |= launch_usr_bin(h, usr_argv) rescue Errno::ENOENT teardown_lttng(syncd) raise @@ -744,7 +744,7 @@ def gm_processing(folder) fo.close end - exit($?.success? ? $EXIT_CODE_USER_BINARY : $?.exitstatus) + $?.exitstatus end # @@ -865,8 +865,12 @@ if __FILE__ == $PROGRAM_NAME # Right now, `replay` means no tracing. # But we don't have a way of disabling post-processing folder = OPTIONS.include?(:replay) ? OPTIONS[:replay] || last_trace_saved : trace_and_on_node_processing(ARGV) + if mpi_master? warn("THAPI: Trace location: #{folder}") - gm_processing(folder) if OPTIONS[:analysis] + $EXIT_CODE_XPROF |= gm_processing(folder) if OPTIONS[:analysis] end + + exit($EXIT_CODE_XPROF) + end From 2aa726009091c1903c7be6c47145961b00323d3a Mon Sep 17 00:00:00 2001 From: Thomas Applencourt Date: Tue, 1 Oct 2024 21:18:59 +0000 Subject: [PATCH 5/6] correct handling --- xprof/xprof.rb.in | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/xprof/xprof.rb.in b/xprof/xprof.rb.in index d649cc22..adf590b7 100755 --- a/xprof/xprof.rb.in +++ b/xprof/xprof.rb.in @@ -13,7 +13,16 @@ PREFIX = '@prefix@' DATAROOTDIR = File.join(PREFIX, 'share') DATADIR = DATAROOTDIR -$EXIT_CODE_XPROF = 0 +class XprofExitCode + @@exit_code = 0 + def self.update(exit_code) + @@exit_code = exit_code unless exit_code.zero? + end + + def self.get + @@exit_code + end +end $LOAD_PATH.unshift(DATADIR) if File.directory?(DATADIR) require 'open3' @@ -687,7 +696,7 @@ def trace_and_on_node_processing(usr_argv) # Launch User Command begin - $EXIT_CODE_XPROF |= launch_usr_bin(h, usr_argv) + XprofExitCode.update(launch_usr_bin(h, usr_argv)) rescue Errno::ENOENT teardown_lttng(syncd) raise @@ -868,9 +877,9 @@ if __FILE__ == $PROGRAM_NAME if mpi_master? warn("THAPI: Trace location: #{folder}") - $EXIT_CODE_XPROF |= gm_processing(folder) if OPTIONS[:analysis] + XprofExitCode.update(gm_processing(folder)) if OPTIONS[:analysis] end - exit($EXIT_CODE_XPROF) + exit(XprofExitCode.get) end From 26d50fbc6a37e620bdbd4620bba203184874b670 Mon Sep 17 00:00:00 2001 From: Brice Videau Date: Tue, 1 Oct 2024 16:48:20 -0500 Subject: [PATCH 6/6] Update xprof/xprof.rb.in --- xprof/xprof.rb.in | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/xprof/xprof.rb.in b/xprof/xprof.rb.in index adf590b7..6895702e 100755 --- a/xprof/xprof.rb.in +++ b/xprof/xprof.rb.in @@ -16,7 +16,8 @@ DATADIR = DATAROOTDIR class XprofExitCode @@exit_code = 0 def self.update(exit_code) - @@exit_code = exit_code unless exit_code.zero? + # Keep only the first error + @@exit_code = exit_code if @@exit_code == 0 end def self.get