From 606bee40f14418b1151e5d23f89ea8c47c0fbe7a Mon Sep 17 00:00:00 2001 From: Thomas Applencourt Date: Fri, 11 Oct 2024 23:17:31 +0000 Subject: [PATCH] cleaner --- xprof/xprof.rb.in | 51 ++++++++++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/xprof/xprof.rb.in b/xprof/xprof.rb.in index 6d852ca5..98fbf357 100755 --- a/xprof/xprof.rb.in +++ b/xprof/xprof.rb.in @@ -15,13 +15,14 @@ DATADIR = DATAROOTDIR class XprofExitCode @@exit_code = 0 - def self.update(exit_code, name) + def self.update(status, name) # Keep only the first error - if exit_code.nil? - LOGGER.error("#{name} returned with a nil exit code (most probably due to a segault") - exit_code = 137 - end - + exit_code = if status.exitstatus.nil? + LOGGER.error("#{name} : #{status}") + 139 + else + status.exitstatus + end @@exit_code = exit_code if @@exit_code == 0 end @@ -30,6 +31,14 @@ class XprofExitCode end end +class XprofExitStatus + attr_reader :exitstatus + + def initialize(exitstatus) + @exitstatus = exitstatus + end +end + $LOAD_PATH.unshift(DATADIR) if File.directory?(DATADIR) require 'open3' require 'fileutils' @@ -48,8 +57,9 @@ module LoggerRefinement refine(Logger) do def info_block(message, &block) info("#{message}: entry") if message - block.call + r = block.call info("#{message}: exit") if message + r end end end @@ -439,18 +449,18 @@ def launch_usr_bin(env, cmd) end.to_h begin - PTY.spawn(bash_env, *cmd) do |stdout, _stdin, _pid| + PTY.spawn(bash_env, *cmd) do |stdout, _stdin, pid| # Reading stdout will trigger Errno::EIO stdout.each { |line| print line } rescue Errno::EIO # Get the PTY status - _, status = Process.wait2(_pid) - return status.exitstatus + _, status = Process.wait2(pid) + return status end rescue Interrupt LOGGER.warn { 'Application Received Interrupt Signal' } # SigINT is 2 - 2 + XprofExitStatus.new(2) rescue Errno::ENOENT warn("#{__FILE__}: Can't find executable #{cmd.first}") raise Errno::ENOENT @@ -635,7 +645,7 @@ end # | | (_) (_ (/_ _> _> | | | (_| # _| -# Some naming convension +# Some naming convention # lm == function executed only local_master # gm == function executed only global_master @@ -660,7 +670,7 @@ def gm_rename_folder # Replace it with a better name, and update the root metadata. thapi_trace_dir_tmp_root = File.dirname(thapi_trace_dir_tmp) - # Because of `traced-rank`, `mpi_master` may not have any trace avalaible, + # Because of `traced-rank`, `mpi_master` may not have any trace available, # so find the first hostname who have a metadata FileUtils.cp(Dir.glob("#{thapi_trace_dir_tmp_root}/*/thapi_metadata.yaml").first, File.join(thapi_trace_dir_tmp_root, 'thapi_metadata.yaml')) @@ -702,7 +712,7 @@ def trace_and_on_node_processing(usr_argv) # Launch User Command begin - XprofExitCode.update(launch_usr_bin(h, usr_argv), usr_argv.join(" ")) + XprofExitCode.update(launch_usr_bin(h, usr_argv), usr_argv.join(' ')) rescue Errno::ENOENT teardown_lttng(syncd) raise @@ -752,14 +762,13 @@ def gm_processing(folder) else $stdout.dup end - - IO.popen([cmdname, *args]) do |pipe| - fo.puts(pipe.readlines) - end - + pipe = IO.popen([cmdname, *args]) + pid = pipe.pid + fo.puts(pipe.readlines) fo.close + _, status = Process.wait2(pid) + status end - $?.exitstatus end # @@ -883,7 +892,7 @@ if __FILE__ == $PROGRAM_NAME if mpi_master? warn("THAPI: Trace location: #{folder}") - XprofExitCode.update(gm_processing(folder), "babeltrace_thapi") if OPTIONS[:analysis] + XprofExitCode.update(gm_processing(folder), 'babeltrace_thapi') if OPTIONS[:analysis] end exit(XprofExitCode.get)