humann/tools/humann_benchmark.py
def main():
    """ Capture time and memory from command run """
    known_args, unknown_args = parse_known_args()
    if not unknown_args:
        # return an error message if no command is provided
        sys.exit("Please provide a command to benchmark: $ humann_benchmark COMMAND")
    try:
        process = subprocess.Popen(" ".join(unknown_args),shell=True)
    except (EnvironmentError, subprocess.CalledProcessError):
        sys.exit("Unable to execute command: " + " ".join(unknown_args))
    pid=str(process.pid)
    start=time.time()
    max_memory=0
    while process.poll() is None:
        time.sleep(1)
        # while the process is running check on the memory use
        # get the pids of the main process and all children (and their children)
        pids=get_pids(pid)
        stdout=subprocess.check_output(["ps","--pid",",".join(pids),"-o","pid,rss,command"]).decode("utf-8")
        print("\n"+stdout+"\n")
        # remove the header from the process output
        status=[i.split() for i in filter(lambda x: x, stdout.split("\n")[1:])]
        # memory is the sum of all rss
        memory=sum(int(i[1]) for i in status)
        if memory > max_memory:
            max_memory=memory
    
    end=time.time()
    print("Time: {:.0f} minutes".format((end-start)/60))
    print("Max Memory (RSS): {:.1f} GB".format(max_memory*1.0/1024**2))
 Capture time and memory from command run 
Capture time and memory from command run
Capture time and memory from command run
def main():
    known_args, unknown_args = parse_known_args()
    if not unknown_args:
        sys.exit("Please provide a command to benchmark: $ humann_benchmark COMMAND")
    try:
        process = subprocess.Popen(" ".join(unknown_args),shell=True)
    except (EnvironmentError, subprocess.CalledProcessError):
        sys.exit("Unable to execute command: " + " ".join(unknown_args))
    pid=str(process.pid)
    start=time.time()
    max_memory=0
    while process.poll() is None:
        time.sleep(1)
        pids=get_pids(pid)
        stdout=subprocess.check_output(["ps","--pid",",".join(pids),"-o","pid,rss,command"]).decode("utf-8")
        print("\n"+stdout+"\n")
        status=[i.split() for i in filter(lambda x: x, stdout.split("\n")[1:])]
        memory=sum(int(i[1]) for i in status)
        if memory > max_memory:
            max_memory=memory
    end=time.time()
    print("Time: {:.0f} minutes".format((end-start)/60))
    print("Max Memory (RSS): {:.1f} GB".format(max_memory*1.0/1024**2))
def main ( ) : known_args , unknown_args = parse_known_args ( ) if not unknown_args : sys . exit ( "Please provide a command to benchmark: $ humann_benchmark COMMAND" ) try : process = subprocess . Popen ( " " . join ( unknown_args ) , shell = True ) except ( EnvironmentError , subprocess . CalledProcessError ) : sys . exit ( "Unable to execute command: " + " " . join ( unknown_args ) ) pid = str ( process . pid ) start = time . time ( ) max_memory = 0 while process . poll ( ) is None : time . sleep ( 1 ) pids = get_pids ( pid ) stdout = subprocess . check_output ( [ "ps" , "--pid" , "," . join ( pids ) , "-o" , "pid,rss,command" ] ) . decode ( "utf-8" ) print ( "\n" + stdout + "\n" ) status = [ i . split ( ) for i in filter ( lambda x : x , stdout . split ( "\n" ) [ 1 : ] ) ] memory = sum ( int ( i [ 1 ] ) for i in status ) if memory > max_memory : max_memory = memory end = time . time ( ) print ( "Time: {:.0f} minutes" . format ( ( end - start ) / 60 ) ) print ( "Max Memory (RSS): {:.1f} GB" . format ( max_memory * 1.0 / 1024 ** 2 ) )
Capture time and memory from command run
Capture time and memory from command run
""" Capture time and memory from command run """ # return an error message if no command is provided # while the process is running check on the memory use # get the pids of the main process and all children (and their children) # remove the header from the process output # memory is the sum of all rss