-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathsymCache.py
More file actions
104 lines (81 loc) · 2.8 KB
/
symCache.py
File metadata and controls
104 lines (81 loc) · 2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import os
import cPickle as pickle
from symLogging import LogDebug
from symUtil import mkdir_p
class Cache(object):
def Update(self, oldMRU, newMRU, symbols):
maxSize = self.MAX_SIZE
oldMruSet = set(oldMRU[:maxSize])
newMruSet = set(newMRU[:maxSize])
inserted = newMruSet.difference(oldMruSet)
evicted = oldMruSet.difference(newMruSet)
LogDebug(
"Evicting {} and inserting {} entries in {}".format(
len(evicted),
len(inserted),
self.__class__))
self.Evict(evicted)
self.Insert(inserted, symbols)
class MemoryCache(Cache):
def __init__(self, options):
self.sCache = {}
self.MAX_SIZE = options["maxMemCacheFiles"]
def Evict(self, libs):
for key in libs:
self.sCache.pop(key)
def Insert(self, libs, symbols):
for lib in libs:
self.sCache[lib] = symbols[lib]
def Get(self, lib):
return self.sCache.get(lib)
def LoadCacheEntries(self, MRU, diskCache):
for lib in MRU[:self.MAX_SIZE]:
self.sCache[lib] = diskCache.Get(lib)
class DiskCache(Cache):
def __init__(self, options):
self.diskCachePath = options["diskCachePath"]
self.MAX_SIZE = options["maxDiskCacheFiles"]
mkdir_p(self.diskCachePath)
def Evict(self, libs):
for libName, breakpadId in libs:
path = self.MakePath(libName, breakpadId)
# Remove from the disk
LogDebug("Evicting {} from disk cache.".format(path))
try:
os.remove(path)
except OSError:
pass
def Insert(self, libs, symbols):
for lib in libs:
self.Store(symbols[lib], lib[0], lib[1])
def Get(self, lib):
path = self.MakePath(lib[0], lib[1])
symbolInfo = None
try:
with open(path, 'rb') as f:
symbolInfo = pickle.load(f)
except (IOError, pickle.PickleError) as ex:
LogDebug("Could not load pickled lib [{}] [{}]: {}".format(lib[0], lib[1], ex))
return symbolInfo
# Walk through the cache directory collecting files.
def GetCacheEntries(self):
fileList = []
# The symbolFiles are located at
# {diskCachePath}/{breakpadId}@{libName}
for root, _, filenames in os.walk(self.diskCachePath):
for filename in filenames:
filePath = os.path.relpath(
os.path.normpath(
os.path.join(root, filename)), self.diskCachePath)
# Get the libName and breakpadId components of the path
breakpadId, libName = filePath.split("@")
fileList.append((libName, breakpadId))
return fileList
def Store(self, symbolInfo, libName, breakpadId):
path = self.MakePath(libName, breakpadId)
with open(path, 'wb') as f:
pickle.dump(symbolInfo, f, pickle.HIGHEST_PROTOCOL)
def MakePath(self, libName, breakpadId):
return os.path.join(
self.diskCachePath,
"@".join((breakpadId, libName)))