Beispiel #1
0
        public void TestFromFile()
        {
            string filePath = @"C:\testSnap.xml";

            // Serialize MemorySnapshot to file.
            MemorySnapshot memorySnapshot = MemorySnapshot.FromProcess(notepad.Id);

            memorySnapshot.ToFile(filePath);

            // Generate the oracle for comparison.
            Dictionary <string, long> oracle = GenerateOracle(notepad.Id);

            // Call from file to load data from file.
            MemorySnapshot fileSnapshot = MemorySnapshot.FromFile(filePath);

            // Compare to data in oracle.
            VerifyProperties(fileSnapshot, oracle);
        }
Beispiel #2
0
        public void TestToFile()
        {
            string filePath = @"C:\testSnap.xml";

            // Store call ToFile to log memorySnapshot to file.
            MemorySnapshot memorySnapshot = MemorySnapshot.FromProcess(notepad.Id);

            memorySnapshot.ToFile(filePath);

            // Generate the oracle for comparison.
            Dictionary <string, long> oracle = GenerateOracle(notepad.Id);

            // Go through xml nodes and compare to data in oracle.
            XmlDocument xmlDoc = new XmlDocument();

            using (Stream s = new FileInfo(filePath).OpenRead())
            {
                try
                {
                    xmlDoc.Load(s);
                }
                catch (XmlException)
                {
                    throw new XmlException("MemorySnapshot file \"" + filePath + "\" could not be loaded.");
                }
            }

            // Grab memory stats.
            Assert.Equal(oracle["GdiObjectCount"], DeserializeNode(xmlDoc, "GdiObjectCount"));
            Assert.Equal(oracle["HandleCount"], DeserializeNode(xmlDoc, "HandleCount"));
            Assert.Equal(oracle["PageFileBytes"], DeserializeNode(xmlDoc, "PageFileBytes"));
            Assert.Equal(oracle["PageFilePeakBytes"], DeserializeNode(xmlDoc, "PageFilePeakBytes"));
            Assert.Equal(oracle["PoolNonpagedBytes"], DeserializeNode(xmlDoc, "PoolNonpagedBytes"));
            Assert.Equal(oracle["PoolPagedBytes"], DeserializeNode(xmlDoc, "PoolPagedBytes"));
            Assert.Equal(oracle["ThreadCount"], DeserializeNode(xmlDoc, "ThreadCount"));
            Assert.Equal(oracle["UserObjectCount"], DeserializeNode(xmlDoc, "UserObjectCount"));
            Assert.Equal(oracle["VirtualMemoryBytes"], DeserializeNode(xmlDoc, "VirtualMemoryBytes"));
            Assert.Equal(oracle["VirtualMemoryPrivateBytes"], DeserializeNode(xmlDoc, "VirtualMemoryPrivateBytes"));
            Assert.Equal(oracle["WorkingSetBytes"], DeserializeNode(xmlDoc, "WorkingSetBytes"));
            Assert.Equal(oracle["WorkingSetPeakBytes"], DeserializeNode(xmlDoc, "WorkingSetPeakBytes"));
            Assert.Equal(oracle["WorkingSetPrivateBytes"], DeserializeNode(xmlDoc, "WorkingSetPrivateBytes"));
        }