Skip to content

Commit

Permalink
cleaner
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Applencourt committed Oct 11, 2024
1 parent ad67991 commit 606bee4
Showing 1 changed file with 30 additions and 21 deletions.
51 changes: 30 additions & 21 deletions xprof/xprof.rb.in
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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'
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -635,7 +645,7 @@ end
# | | (_) (_ (/_ _> _> | | | (_|
# _|

# Some naming convension
# Some naming convention
# lm == function executed only local_master
# gm == function executed only global_master

Expand All @@ -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'))
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

#
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 606bee4

Please sign in to comment.