def get_perf(sched, path, ninf, portIdx, reset=False, select=0xFFFF): """Coroutine to get port counters.""" cnts = IBA.PMPortCounters() if portIdx is None: cnts.portSelect = ninf.localPortNum if ninf.nodeType == IBA.NODE_SWITCH and cnts.portSelect == 0: cnts.portSelect = 1 else: cnts.portSelect = portIdx accumulate = False if cnts.portSelect == 0xFF: cpinf = yield sched.PerformanceGet(IBA.MADClassPortInfo, path) path.resp_time = cpinf.respTimeValue accumulate = not (cpinf.capabilityMask & IBA.allPortSelect) if accumulate and ninf.nodeType == IBA.NODE_CA: raise CmdError("Can't iterate over all ports on a CA.") if reset: cnts.counterSelect = select if accumulate: def get_cnts(port): cnts.portSelect = port if reset: yield sched.PerformanceSet(cnts, path) else: results[port] = yield sched.PerformanceGet(cnts, path) results = [None] * (ninf.numPorts + 1) yield sched.mqueue(get_cnts(I) for I in range(1, ninf.numPorts + 1)) if reset: return res = sum_result(results) else: if reset: yield sched.PerformanceSet(cnts, path) return else: res = yield sched.PerformanceGet(cnts, path) res.portSelect = cnts.portSelect sched.result = res