Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-09 07:49:18

0001 #!/usr/bin/env python
0002 """
0003 sleak.py
0004 ======================
0005 
0006 ::
0007 
0008    ~/o/sysrap/tests/sleak.sh 
0009    DRM=1 ~/o/sysrap/tests/sleak.sh
0010    DRM=1 YLIM=0,3 ~/o/sysrap/tests/sleak.sh ana 
0011 
0012 
0013 """
0014 
0015 import os, numpy as np
0016 from opticks.ana.fold import Fold
0017 from opticks.ana.npmeta import NPMeta
0018 
0019 COMMANDLINE = os.environ.get("COMMANDLINE", "")
0020 STEM =  os.environ.get("STEM", "")
0021 HEADLINE = "%s ## %s " % (COMMANDLINE, STEM ) 
0022 JOB =  os.environ.get("JOB", "")
0023 PLOT =  os.environ.get("PLOT", "Runprof_ALL")
0024 STEM =  os.environ.get("STEM", "")
0025 PICK =  os.environ.get("PICK", "AB")
0026 TLIM =  np.array(list(map(int,os.environ.get("TLIM", "0,0").split(","))),dtype=np.int32)
0027 YLIM = np.array(list(map(float, os.environ.get("YLIM","0,0").split(","))),dtype=np.float32)
0028  
0029 
0030 MODE =  int(os.environ.get("MODE", "2"))
0031 
0032 if MODE != 0:
0033     from opticks.ana.pvplt import * 
0034 pass
0035 
0036 
0037 
0038 class Subprofile(object):
0039     """
0040     Why VM is so large with CUDA
0041 
0042     * https://forums.developer.nvidia.com/t/high-virtual-memory-consumption-on-linux-for-cuda-programs-is-it-possible-to-avoid-it/67706/4
0043 
0044     """
0045     FONTSIZE = 20 
0046     XLABEL = "Time from 1st sprof.h stamp (seconds)"
0047     YLABEL_VM = "sprof.h VM memory (GB) "
0048     YLABEL_RS = "sprof.h RSS memory (GB) "
0049     YLABEL_DRM = "sprof.h DRM per event leak (MB) "
0050 
0051 
0052 
0053 class Runprof_ALL(object):
0054     """
0055     PLOT=Runprof_ALL ~/o/sysrap/tests/sleak.sh 
0056     """
0057     def __init__(self, fold, symbol="fold.runprof"):
0058         rp = eval(symbol)
0059         self.rp = rp
0060         label = "Runprof_ALL " 
0061         fontsize = Subprofile.FONTSIZE
0062         if MODE == 2 or MODE == 3:
0063             fig, axs = mpplt_plotter(nrows=1, ncols=1, label=label, equal=False)
0064             ax = axs[0]
0065 
0066             tp = (rp[:,0] - rp[0,0])/1e6  # seconds
0067             vm = rp[:,1]/1e6              # GB
0068             rs = rp[:,2]/1e6              # GB
0069 
0070             #tpm = tp[0::2]
0071             #drm = (rp[1::2,2] - rp[0::2,2])/1e3  # MB 
0072             
0073             tpm = tp[2::2]
0074             drm = np.diff(rp[0::2,2])/1e3  # MB 
0075             slm = slice(1,None)
0076             tpm = tpm[slm]
0077             drm = drm[slm]
0078 
0079             self.tp = tp
0080             self.vm = vm
0081             self.rs = rs
0082             self.drm = drm 
0083             self.tpm = tpm 
0084 
0085             if "DRM" in os.environ:
0086                 label = "%s : %s vs starttime(s)" % (symbol, Subprofile.YLABEL_DRM)
0087                 ax.scatter( tpm, drm, label=label )
0088                 ax.plot(    tpm, drm )
0089                 ax.set_ylabel(Subprofile.YLABEL_DRM, fontsize=Subprofile.FONTSIZE )
0090                 pass
0091             elif "VM" in os.environ:
0092                 label = "%s : %s vs time(s)" % (symbol, Subprofile.YLABEL_VM)
0093                 ax.scatter( tp, vm, label=label )
0094                 ax.plot(    tp, vm )
0095             else:
0096                 label = "%s : %s vs time(s)" % (symbol, Subprofile.YLABEL_RS)
0097                 ax.scatter( tp, rs, label=label  )
0098                 ax.plot( tp, rs )
0099             pass
0100             ax.set_xlabel(Subprofile.XLABEL, fontsize=Subprofile.FONTSIZE )
0101             if YLIM[1] > YLIM[0]:
0102                 ax.set_ylim(*YLIM)
0103             pass
0104 
0105             yl = ax.get_ylim()
0106             ## THIS ASSUMES A AND B SEVT STAMPS 
0107             #ax.vlines( tp[0::4], yl[0], yl[1], color="blue", label="nBeg" ) 
0108             #ax.vlines( tp[1::4], yl[0], yl[1], color="red", label="nEnd" ) 
0109             #ax.vlines( tp[2::4], yl[0], yl[1], color="cyan", label="pBeg" ) 
0110             #ax.vlines( tp[3::4], yl[0], yl[1], color="pink", label="pEnd" ) 
0111 
0112             if "DRM" in os.environ:
0113                 pass
0114             else:
0115                 ax.vlines( tp[0::2], yl[0], yl[1], color="blue", label="ABeg" ) 
0116                 ax.vlines( tp[1::2], yl[0], yl[1], color="red", label="AEnd" ) 
0117             pass
0118 
0119             ax.legend()
0120             fig.show()
0121         else:
0122             print("MODE:%d " % MODE)
0123         pass  
0124 
0125 
0126 
0127 if __name__ == '__main__':
0128     fold = Fold.Load("$SLEAK_FOLD", symbol="fold")
0129     print("SLEAK_FOLD:%s " % os.environ["SLEAK_FOLD"] )
0130     print(repr(fold))
0131     if PLOT.startswith("Runprof_ALL") and hasattr(fold, "runprof"):
0132         RPA = Runprof_ALL(fold, symbol="fold.runprof" )  ## RSS vs time : profile plot 
0133         rp = RPA.rp
0134         drm = RPA.drm
0135     else:
0136         print("PLOT:%s UNHANDLED" % PLOT)
0137     pass
0138 pass
0139