def __GetCriticalPaths(self, pathPrefix): criticalPaths = {} pathPrefix += '/' if pathPrefix[-1] != '/' else '' functionLogFiles = [ pathPrefix + f for f in listdir(pathPrefix) if 'FunctionLog' in f ] for filename in functionLogFiles: with open(filename, 'rb') as latencyLogFile: latencyReader = csv.reader(latencyLogFile) for row in latencyReader: if len(row) == 5: functionIndex = int(row[0]) # Done with all semantic interval latencies if functionIndex > 0: break threadID = row[1] semIntervalID = row[2] startTime = nanotime(int(row[3])) endTime = nanotime(int(row[4])) criticalPath = self.criticalPathBuilder.Build( startTime, endTime, threadID) criticalPaths[semIntervalID] = criticalPath return criticalPaths
def __Parse(self, pathPrefix, numFunctions): pathPrefix += '/' if pathPrefix[-1] != '/' else '' functionLogFiles = [ pathPrefix + f for f in listdir(pathPrefix) if 'FunctionLog' in f ] for filename in functionLogFiles: with open(filename, 'rb') as latencyLogFile: latencyReader = csv.reader(latencyLogFile) for row in latencyReader: if len(row) == 5: functionIndex = int(row[0]) threadID = row[1] semIntervalID = row[2] startTime = nanotime(int(row[3])) endTime = nanotime(int(row[4])) if semIntervalID not in self.semanticIntervals: self.semanticIntervals[semIntervalID] = \ [[] for x in range(numFunctions)] (self.semanticIntervals[semIntervalID] [functionIndex].append( FunctionRecord(startTime, endTime, threadID)))
def AddFunctionTime(self, funcTime): threadID = funcTime[0] # Index 1 is the semantic interval ID. Don't actually think this is # necessary for RequestTracker. startTime = nanotime(int(funcTime[2])) endTime = nanotime(int(funcTime[3])) self.threadRequests[threadID].AddFunctionTime(startTime, endTime)
def test_blank(self): blank = Version(Key('/BLANK')) self.assertEqual(blank.hash, Version.BLANK_HASH) self.assertEqual(blank.type, '') self.assertEqual(blank.shortHash(5), Version.BLANK_HASH[0:5]) self.assertEqual(blank.committed, nanotime.nanotime(0)) self.assertEqual(blank.created, nanotime.nanotime(0)) self.assertEqual(blank.parent, Version.BLANK_HASH) self.assertEqual(blank, Version(Key('/BLANK'))) self.assertTrue(blank.isBlank)
def test_other(self): test = self.subtest_attribute(TimeAttribute) test(5, nanotime.nanotime(5)) test(5.2, nanotime.nanotime(5.2)) self.assertRaises(TypeError, test, self) self.assertRaises(TypeError, test, '5') self.assertRaises(TypeError, test, '5a') test(nanotime.seconds(1000)) test(None) test = self.subtest_attribute(DateTimeAttribute) self.assertRaises(TypeError, test, 5) self.assertRaises(TypeError, test, 5.2) self.assertRaises(TypeError, test, self) self.assertRaises(ValueError, test, '5') self.assertRaises(ValueError, test, '5a') test(datetime.datetime.now()) test(None) d = datetime.datetime(2011, 7, 12, 13, 19, 29, 151455) test(str(d), d) d = datetime.datetime(2011, 7, 12, 13, 19, 29, 0) test(str(d), d) test = self.subtest_attribute(ListAttribute) self.assertRaises(TypeError, test, 5, ['5']) self.assertRaises(TypeError, test, 5.2, ['5.2']) self.assertRaises(TypeError, test, self, [str(self)]) test('5', ['5']) test('5a', ['5', 'a']) test([]) test(['fdgfds', 'gfdsgfds', 'gfdsgfds', 'gfdsgfds']) test([4214, 321, 43, 21], ['4214', '321', '43', '21']) test(xrange(0, 10), map(str, range(0, 10))) test(None) test = self.subtest_attribute(DictAttribute) self.assertRaises(TypeError, test, 5) self.assertRaises(TypeError, test, 5.2) self.assertRaises(TypeError, test, self) self.assertRaises(TypeError, test, '5') self.assertRaises(TypeError, test, '5a') test({}) test({'a':'b'}) test({'1213':3214}, {'1213':'3214'}) test({1213:3214}, {'1213':'3214'}) test(None)
def test_other(self): test = self.subtest_attribute(TimeAttribute) test(5, nanotime.nanotime(5)) test(5.2, nanotime.nanotime(5.2)) self.assertRaises(TypeError, test, self) self.assertRaises(TypeError, test, "5") self.assertRaises(TypeError, test, "5a") test(nanotime.seconds(1000)) test(None) test = self.subtest_attribute(DateTimeAttribute) self.assertRaises(TypeError, test, 5) self.assertRaises(TypeError, test, 5.2) self.assertRaises(TypeError, test, self) self.assertRaises(ValueError, test, "5") self.assertRaises(ValueError, test, "5a") test(datetime.datetime.now()) test(None) d = datetime.datetime(2011, 7, 12, 13, 19, 29, 151455) test(str(d), d) d = datetime.datetime(2011, 7, 12, 13, 19, 29, 0) test(str(d), d) test = self.subtest_attribute(ListAttribute) self.assertRaises(TypeError, test, 5, ["5"]) self.assertRaises(TypeError, test, 5.2, ["5.2"]) self.assertRaises(TypeError, test, self, [str(self)]) test("5", ["5"]) test("5a", ["5", "a"]) test([]) test(["fdgfds", "gfdsgfds", "gfdsgfds", "gfdsgfds"]) test([4214, 321, 43, 21], ["4214", "321", "43", "21"]) test(xrange(0, 10), map(str, range(0, 10))) test(None) test = self.subtest_attribute(DictAttribute) self.assertRaises(TypeError, test, 5) self.assertRaises(TypeError, test, 5.2) self.assertRaises(TypeError, test, self) self.assertRaises(TypeError, test, "5") self.assertRaises(TypeError, test, "5a") test({}) test({"a": "b"}) test({"1213": 3214}, {"1213": "3214"}) test({1213: 3214}, {"1213": "3214"}) test(None)
def test_packers(): r = Stamp(BaseJots.DATA.code, nanotime(0)) pack = Stamp_PACKER.pack(r) r2, offset = Stamp_PACKER.unpack(pack, 0) assert len(pack) == offset assert r.entry_code == r2.entry_code assert r.tstamp.nanoseconds() == r2.tstamp.nanoseconds() packer = BaseJots.CHECK_POINT.header_packer o = CheckpointHeader(NULL_CAKE, 0, 5, CheckPointType.ON_SIZE) pack = packer.pack(o) o2, offset = packer.unpack(pack, 0) assert len(pack) == offset assert o == o2
def __subtest_arithmetic(self, start, extra): eq = self.assertEqual start = float(start) extra = float(extra) t1 = nanotime.seconds(start) eq(nanotime.seconds(start + extra), t1 + nanotime.nanotime(extra * 1e9)) eq(nanotime.seconds(start + extra), t1 + nanotime.seconds(extra)) eq(nanotime.seconds(start - extra), t1 - nanotime.nanotime(extra * 1e9)) eq(nanotime.seconds(start - extra), t1 - nanotime.seconds(extra)) eq(nanotime.seconds(start * extra), t1 * nanotime.nanotime(extra)) eq(nanotime.seconds(start * extra), t1 * nanotime.nanoseconds(extra)) eq(nanotime.seconds(start / extra), t1 / nanotime.nanotime(extra)) eq(nanotime.seconds(start / extra), t1 / nanotime.nanoseconds(extra)) self.assertTrue(nanotime.seconds(start + extra) > t1) self.assertTrue(nanotime.seconds(start - extra) < t1) t2 = nanotime.seconds(start + extra) self.assertTrue(t2 > nanotime.nanotime(0)) self.assertTrue(nanotime.nanotime(0) < t2)
def created(self): return nanotime.nanotime(self._serialRep['created'])
def committed(self): return nanotime.nanotime(self._serialRep['committed'])