File indexing completed on 2026-04-09 07:48:48
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022 import os, sys, numpy as np
0023 from collections import OrderedDict as odict
0024
0025 decode_ = lambda v:"".join(map( lambda c:str(unichr(c)), filter(None,map(lambda i:(int(v) >> i*8) & 0xff, range(8))) ))
0026
0027
0028 class NGPU(object):
0029 def __init__(self, path):
0030 a = np.load(os.path.expandvars(path))
0031 d = odict()
0032 tot_bytes = 0
0033 for i in range(len(a)):
0034 name, owner, note = map(decode_, a[i,:3])
0035 loc = "/".join([name, owner, note])
0036 num_bytes = a[i,3]
0037 d[loc] = num_bytes
0038 tot_bytes += num_bytes
0039 pass
0040 self.d = d
0041 self.a = a
0042 self.tot_bytes = tot_bytes
0043 self.path = path
0044
0045 def __str__(self):
0046 return "\n".join([" %30s : %s " % (k,self.brief(k)) for k, v in self.d.items()])
0047 def __repr__(self):
0048 return "%10d : %15d : %6.2f : %s " % ( len(self.d), self.tot_bytes, float(self.tot_bytes)/1e6, self.path )
0049
0050 def brief(self, loc):
0051 nb = self.d.get(loc, -1)
0052 return " %15d : %6.2f " % ( nb, float(nb)/1e6 ) if nb > -1 else ""
0053
0054 def index(self, loc):
0055 return self.d.keys().index(loc) if self.d.has_key(loc) else -1
0056
0057
0058
0059 if __name__ == '__main__':
0060
0061
0062 a_name = "OTracerTest"
0063 b_name = "OKX4Test"
0064
0065 a_path = sys.argv[1] if len(sys.argv) > 1 else "$TMP/%s_GPUMon.npy" % a_name
0066 b_path = sys.argv[2] if len(sys.argv) > 2 else "$TMP/%s_GPUMon.npy" % b_name
0067
0068 a = NGPU(a_path)
0069 b = NGPU(b_path)
0070
0071 print repr(a)
0072 print repr(b)
0073
0074 locs = set(a.d.keys()).union(set(b.d.keys()))
0075
0076 fmt = " %30s : %30s : %30s "
0077 print fmt % ( len(locs) , a_path , b_path )
0078 for loc in sorted(locs, key=lambda loc:max(a.index(loc), b.index(loc))):
0079 print fmt % ( loc, a.brief(loc), b.brief(loc) )
0080 pass
0081
0082
0083
0084