Page MenuHomec4science

profiling.py
No OneTemporary

File Metadata

Created
Fri, May 10, 04:24

profiling.py

#
# @file profiling.py
#
# @brief
#
# @copyright
# Copyright (©) 2021 EPFL (Ecole Polytechnique Fédérale de Lausanne)
# SPC (Swiss Plasma Center)
#
# futils is free software: you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option)
# any later version.
#
# futils is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
# @authors
# (in alphabetical order)
# @author Trach-Minh Tran <trach-minh.tran@epfl.ch>
#
#!/usr/bin/env python
import h5py
from pylab import *
import time, os, sys
file='pprof.h5'
def mem():
pid = os.getpid()
arch = sys.platform
if arch[:5] == 'linux':
a2 = open('/proc/%d/statm'%(pid,)).read()
mb = 4*int(a2.split()[1])/1024.0
elif arch[:6] == 'darwin':
a2 = os.popen('ps -p %d -o rss,vsz' % pid).readlines()
mb = int(a2[1].split()[1])/1024.0
else:
mb = 0
return mb
t0=time.time()
f=h5py.File(file, "r")
timeid=f['/profile_2d/time']
xgid=f['/profile_2d/xg']
ygid=f['/profile_2d/yg']
phiid=f['/profile_2d/phi']
print "\nelapsed time %.3f s" % (time.time()-t0,)
print "memory used %.3f MB\n" % (mem(),)
t0=time.time()
phi=phiid[0,:,:]
print "elapsed time %.3f s" % (time.time()-t0,)
print "size of phi %.3f MB" % (4*size(phi)/1024.0/1024.0,)
print "memory used %.3f MB\n" % (mem(),)
t0=time.time()
phi=phiid[-1,:,:]
print "elapsed time %.3f s" % (time.time()-t0,)
print "size of phi %.3f MB" % (4*size(phi)/1024.0/1024.0,)
print "memory used %.3f MB\n" % (mem(),)
t0=time.time()
phi=phiid[:,:,:]
print "elapsed time %.3f s" % (time.time()-t0,)
print "size of phi %.3f MB" % (4*size(phi)/1024.0/1024.0,)
print "memory used %.3f MB\n" % (mem(),)
print "Using Matlab/hdf5read"
matlab_com = "tic;phi=hdf5read('%s','/profile_2d/phi');toc;quit;"% (file,)
com="""matlab -nojvm -nosplash -r "%s" """ % matlab_com
stat=os.system(com)

Event Timeline