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

Class CustomMachineConfiguration

deps/v8/tools/run_perf.py:1046–1148  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1044
1045
1046class CustomMachineConfiguration:
1047 def __init__(self, disable_aslr = False, governor = None):
1048 self.aslr_backup = None
1049 self.governor_backup = None
1050 self.disable_aslr = disable_aslr
1051 self.governor = governor
1052
1053 def __enter__(self):
1054 if self.disable_aslr:
1055 self.aslr_backup = CustomMachineConfiguration.GetASLR()
1056 CustomMachineConfiguration.SetASLR(0)
1057 if self.governor is not None:
1058 self.governor_backup = CustomMachineConfiguration.GetCPUGovernor()
1059 CustomMachineConfiguration.SetCPUGovernor(self.governor)
1060 return self
1061
1062 def __exit__(self, type, value, traceback):
1063 if self.aslr_backup is not None:
1064 CustomMachineConfiguration.SetASLR(self.aslr_backup)
1065 if self.governor_backup is not None:
1066 CustomMachineConfiguration.SetCPUGovernor(self.governor_backup)
1067
1068 @staticmethod
1069 def GetASLR():
1070 try:
1071 with open('/proc/sys/kernel/randomize_va_space', 'r') as f:
1072 return int(f.readline().strip())
1073 except Exception:
1074 logging.exception('Failed to get current ASLR settings.')
1075 raise
1076
1077 @staticmethod
1078 def SetASLR(value):
1079 try:
1080 with open('/proc/sys/kernel/randomize_va_space', 'w') as f:
1081 f.write(str(value))
1082 except Exception:
1083 logging.exception(
1084 'Failed to update ASLR to %s. Are we running under sudo?', value)
1085 raise
1086
1087 new_value = CustomMachineConfiguration.GetASLR()
1088 if value != new_value:
1089 raise Exception('Present value is %s' % new_value)
1090
1091 @staticmethod
1092 def GetCPUCoresRange():
1093 try:
1094 with open('/sys/devices/system/cpu/present', 'r') as f:
1095 indexes = f.readline()
1096 r = list(map(int, indexes.split('-')))
1097 if len(r) == 1:
1098 return list(range(r[0], r[0] + 1))
1099 return list(range(r[0], r[1] + 1))
1100 except Exception:
1101 logging.exception('Failed to retrieve number of CPUs.')
1102 raise
1103

Callers 1

MainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…