MCPcopy Index your code
hub / github.com/nodejs/node / MountSharedData

Method MountSharedData

deps/v8/tools/stats-viewer.py:99–130  ·  view source on GitHub ↗

Mount the binary counters file as a memory-mapped file. If something goes wrong print an informative message and exit the program.

(self)

Source from the content-addressed store, hash-verified

97 self.CleanUp()
98
99 def MountSharedData(self):
100 """Mount the binary counters file as a memory-mapped file. If
101 something goes wrong print an informative message and exit the
102 program."""
103 if not os.path.exists(self.data_name):
104 maps_name = "/proc/%s/maps" % self.data_name
105 if not os.path.exists(maps_name):
106 print("\"%s\" is neither a counter file nor a PID." % self.data_name)
107 sys.exit(1)
108 maps_file = open(maps_name, "r")
109 try:
110 self.data_name = None
111 for m in re.finditer(r"/dev/shm/\S*", maps_file.read()):
112 if os.path.exists(m.group(0)):
113 self.data_name = m.group(0)
114 break
115 if self.data_name is None:
116 print("Can't find counter file in maps for PID %s." % self.data_name)
117 sys.exit(1)
118 finally:
119 maps_file.close()
120 data_file = open(self.data_name, "r")
121 size = os.fstat(data_file.fileno()).st_size
122 fileno = data_file.fileno()
123 self.shared_mmap = mmap.mmap(fileno, size, access=mmap.ACCESS_READ)
124 data_access = SharedDataAccess(self.shared_mmap)
125 if data_access.IntAt(0) == COUNTERS_FILE_MAGIC_NUMBER:
126 return CounterCollection(data_access)
127 elif data_access.IntAt(0) == CHROME_COUNTERS_FILE_MAGIC_NUMBER:
128 return ChromeCounterCollection(data_access)
129 print("File %s is not stats data." % self.data_name)
130 sys.exit(1)
131
132 def CleanUp(self):
133 """Cleans up the memory mapped file if necessary."""

Callers 1

RunMethod · 0.95

Calls 11

IntAtMethod · 0.95
SharedDataAccessClass · 0.85
CounterCollectionClass · 0.85
fstatMethod · 0.80
printFunction · 0.70
closeMethod · 0.65
openFunction · 0.50
existsMethod · 0.45
exitMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected