示例#1
0
 def testRefCountingAndVectorAssignment(self):
     x = Hello()
     y = Hello()
     self.assertEqual(x.GetRefCounts()[1], 1)
     y.helloVector.append(x)
     self.assertEqual(x.GetRefCounts()[1], 2)
     self.assertEqual(blue.GetID(x), blue.GetID(y.helloVector[0]))
示例#2
0
 def testSaveToRedLoadFromRed(self):
     x = Hello()
     testString = 'Test String'
     x.myString = testString
     y = Hello()
     x.next = y
     x.helloVector.append(y)
     blue.resMan.SaveObject(x, 'cache:/test.red')
     z = blue.resMan.LoadObject('cache:/test.red')
     self.assertEqual(z.myString, testString)
     self.assertEqual(len(z.helloVector), 1)
     self.assertEqual(blue.GetID(x.next), blue.GetID(x.helloVector[0]),
                      'Instancing not working')
     self.assertEqual(blue.GetID(z.next), blue.GetID(z.helloVector[0]),
                      'Instancing not maintained across saves')
示例#3
0
def WriteMemorySnapshot(name=''):
    """
    Writes a memory snapshot to disk, comprising a memory allocation report and
    a yaml file of some basic data (resources that were alive etc).
    
    """
    global workingSetStatistic
    CreateSnapshotsFolder()
    frameCounter = blue.os.framesTotal
    dateString = datetime.date.today().isoformat()
    if name == '':
        extraName = ''
    else:
        extraName = '_' + name
    dumpFileName = dateString + '_' + str(frameCounter) + extraName + '.txt'
    summaryFileName = dateString + '_' + str(
        frameCounter) + extraName + '_summary.txt'
    yamlFileName = dateString + '_' + str(frameCounter) + extraName + '.yaml'
    summaryFilePath = os.path.join(snapShotsFolder, summaryFileName)
    dumpFilePath = os.path.join(snapShotsFolder, dumpFileName)
    yamlFilePath = os.path.join(snapShotsFolder, yamlFileName)
    stats = {}
    heaps = blue.memoryTracker.GetAllHeaps()
    fullHeapSize = 0L
    for heapID, heapSize in heaps.iteritems():
        fullHeapSize += heapSize

    stats['heaps'] = heaps
    stats['heapSize'] = fullHeapSize
    stats['workingSet'] = workingSetStatistic.value
    stats['CRTHeapUnaccounted'] = CRTHeapUnaccountedStatistic.value
    stats['CRTHeap'] = CRTHeapStatistic.value
    stats['PageFile'] = PageFileStatistic.value
    stats['trackedAllocationsSize'] = trackedAllocationsSizeStatistic.value
    stats['liveCount'] = blue.classes.LiveCount()
    stats['resources'] = []
    for classname, obj, count, a, b in blue.classes.LiveList():
        if not classname.endswith('Res'):
            continue
        elif obj is not None:
            if hasattr(obj, 'GetMemoryUsage'):
                objInfo = {}
                objInfo['id'] = blue.GetID(obj)
                objInfo['memUsage'] = obj.GetMemoryUsage()
                objInfo['path'] = obj.path
                objInfo['type'] = classname
                if hasattr(obj, 'name'):
                    objInfo['name'] = obj.name
                if classname.endswith('TextureRes'):
                    objInfo['format'] = trinity.TRIFORMAT.GetNameFromValue(
                        obj.format)
                    objInfo['width'] = obj.width
                    objInfo['height'] = obj.height
                stats['resources'].append(objInfo)

    with open(yamlFilePath, 'w') as f:
        yaml.dump(stats, f)
    blue.memoryTracker.SummaryReport(str(summaryFilePath))
    blue.memoryTracker.DumpReportAsText(dumpFilePath)
    print 'Wrote report:', dumpFilePath, 'and', yamlFileName