def copy_proc_files(output_dir, pid, iteration): tag = "copy_proc_files" pid = str(pid) iteration = str(iteration).zfill(3) # http://stackoverflow.com/questions/339007/python-nicest-way-to-pad-zeroes-to-string proc_root = "/proc" proc_files = ["smaps", "maps", "status", "stat"] for fname in proc_files: src_fname = ("{0}/{1}/{2}").format(proc_root, pid, fname) #dst_fname = ("{0}/{1}-{2}-{3}").format( # output_dir, iteration, fname, pid) dst_fname = ("{0}/{1}-{2}").format( output_dir, iteration, fname) #print_debug(tag, ("src_fname={0} dst_fname={1}").format( # src_fname, dst_fname)) vm.copy_proc_file_old(src_fname, dst_fname) save_pstree("{}/{}-pstree".format(output_dir, fname)) cmdline = "ls -ahl {0}/{1}/".format(proc_root, pid) dst_fname = "{0}/{1}-ls-ahl".format(output_dir, iteration) retcode = exec_cmd_save_output(cmdline, dst_fname, dst_fname) if retcode != 0: print_warning(tag, ("got back non-zero retcode {0} from " "exec_cmd_save_output()").format(retcode)) return
def copy_proc_files(pid_dir, output_subdir): tag = "copy_proc_files" # pid_dir is a /proc/[pid] directory, and output_subdir is a corresponding # [pid] subdirectory in the output directory. Scan through the list of # files that we care about and copy the contents of each one to the output # directory. Because /proc files are not normal file system files, we # don't use a copy command, but instead open every file for reading and # then write every line to the output file. for fname in proc_files_we_care_about: proc_fname = "{0}/{1}".format(pid_dir, fname) out_fname = "{0}/{1}".format(output_subdir, fname) print_debug(tag, ("copying '{0}' to '{1}'".format( proc_fname, out_fname))) vm.copy_proc_file_old(proc_fname, out_fname)