2
\$\begingroup\$

I wrote a function that returns a dictionary with statistics (memory usage, time, speed) based on another function that copies files/folders. I want to check if this is a good method or if you have any other suggestions or methods to improve it.

def get_copy_stats(funct, args):
    stats = {}
    mem_usg_bef = get_process_memory_usage("process.exe") #process of the app I am testing
    time_bef = timer()
    size = funct(*args) #calls the function that copies the file and returns the file/folder size
    time_aft = timer()
    mem_usg_aft = get_process_memory_usage("process.exe")
    stats['copy_time'] = time_aft-time_bef
    stats['copy_speed'] = size/(time_aft-time_bef)
    stats['mem_usg_bef'] = mem_usg_bef
    stats['mem_usg_aft'] = mem_usg_aft
    return stats

Example on how to call it:

get_copy_stats(copy_files,("C:\Users\me\Desktop\Source","C:\Users\me\Desktop\Dest"))
\$\endgroup\$
  • 2
    \$\begingroup\$ Well, you won't have exact memory usage with that. Since GC already does some job at this point. This is more like estimated memory usage. Also, it will display just latest value, not the maximum one. \$\endgroup\$ – Alex Jan 30 '17 at 15:25
  • \$\begingroup\$ For get_process_memory_usage() I used the code I found on this site, from memory_usage_psutil() function: fa.bianp.net/blog/2013/…. I want to know if the memory won't increase very much after the files are copied. Is there a way to also find the maximum memory that was used during file transfer? Maybe check memory every second and return the maximum value? \$\endgroup\$ – return Jan 31 '17 at 12:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.