def parse_adb_devices(self, adb_port: int, emulators_found: int, real_devices_found: int) -> Tuple[int, int]: devices_cmd = adb.adb_cmd_prefix + ' devices' try: output, errors, result_code = run_cmd( devices_cmd, env={"ANDROID_ADB_SERVER_PORT": str(adb_port)}) except TimeoutExpired as e: return emulators_found, real_devices_found error_lines = errors.split("\n") for line in error_lines: if "daemon not running" in line: continue if "daemon started successfully" in line: continue if line.strip() != "": raise Exception( f"There was an error running \'adb devices\' command: {errors}" ) lines = output.split("\n") for line in lines: if "List of devices attached" in line: continue if line.strip() == "": continue if "offline" not in line: device_name = line.split("\t")[0].strip() matching_devices = [ device for device in self.devices if device.name == device_name ] if len(matching_devices) > 0: device = matching_devices.pop(0) if device.state < State.reachable: device.state = State.reachable if type(device) is Emulator: emulators_found += 1 else: real_devices_found += 1 elif "emulator" in line and emulators_found < self.emulators_number: self.devices.append( Emulator(self, device_name, state=State.reachable)) emulators_found += 1 elif "device" in line and real_devices_found < self.real_devices_number: self.devices.append( Device(self, device_name, state=State.reachable)) real_devices_found += 1 return emulators_found, real_devices_found
def initialize(devices, chain=5): # Define devices to represent start and finish of simulation start = Device(0, 0) start.start = 0 start.finish = 0 finish = Device(0, 0) # Set length of simulation T = 23 # Find predecessor and successor for each device predSucc(devices, start, finish, chain) # Call getEarly and getLate for every five devices for i in range(0, len(devices), chain): getEarly(devices[i], chain) getLate(devices[i], T)
def _add_volume(self, udi, volume): device = Device() device.device_id = udi device.device_file = volume.GetProperty("block.device") device.label = volume.GetProperty("volume.label") device.fstype = volume.GetProperty("volume.fstype") device.mounted = volume.GetProperty("volume.is_mounted") device.mount_point = volume.GetProperty("volume.mount_point") try: device.size = volume.GetProperty("volume.size") except: device.size = 0 self._devices[udi] = device return device
def generateDevice(n, step=60): # Calculate # of time steps in an hour factor = 60/step # List of possible duration times duration = {1: .35, 2: .25, 3: .2, 4:.1, 5:.1} #duration = {1: .5, 5:.5} # If steps are not an hour if step != 60: # Initialize new dictionary newDur = {} # Create new dictionary for possible task durations for key in duration.keys(): for i in range(factor): newDur[factor*key + i] = duration[key] # Define new dictionaries duration = newDur # Initialize list of devices devices = [] for i in range(n): # Choose duration dur = weighted_choice(duration) # Choose power power = np.random.uniform(1e3, 10e3) # 50% chance to reduce device power by one order of magnitude # if np.random.randint(0, 10) != 0: # power *= 0.1 # Create device device = Device(power, dur, step) devices.append(device) device.index = len(devices) - 1 return devices