Friday, April 25, 2014

PerfView tool for memory analysis


Steps to perform memory analysis:

PerfView is very usefull tool to from Microsoft to analyze, memory and performance issues. In this section we will see how to use PerfView tool to perform memory leak analysis.

1. Collect the full memory dump file for the exe to be investigated.
Use Task manager->Select the process -> Right click Create Dump File. to save the dump. Else use ProcDump.exe with "-ma" option (Available in SysInternals website) to create full memory dump.

2. Open the dump file using PerfView.exe




3. "Dump GC Heap" button shall walk through the heap and start dumping them into .GCHeap File. 

4. If we are debugging Live process then ForceGC, Freeze would options make sense. Anyway now we are checking already collected dump file.

5. Double click on "GCHeap" dump file to view the stack table.



6. Stack table contains various Filter options.

7. Options like Inc, IncCount shall help you to find which object occupies the heap. most of the Array or String used to be on Top of all the  memory allocated. 

8. We could use options like Fold, Drill Into, F10 to see who is really referring this objects.

9. As soon as we know the major reference holding live objects, we should be able to find the root cause.

10. Apart from great table view, PerfView also provide Diff option if we collected the heap snap shots on difference time interval of the same process to find the leaking objects and the root holding the objects.


Sunday, April 6, 2014

Debugging using WinDBG, Root cause finding using WER.

Finding the root cause from WER:

From wer file info, I got 34a5.
               
                                6.1
                                7601 Service Pack 1
                                (0x7): Windows Server 2008 R2 Standard
                                ServerStandard
                                7601.17944.amd64fre.win7sp1_gdr.120830-0333
                                1130
                                Multiprocessor Free
                                X64
                                1033
               
               
                                640
                                C:\Windows\System32\services.exe
                                C:\Windows\system32\services.exe
               
               
                                CLR20r3
                                loggersvc.exe
                                1.0.4668.23049
                                5077f573
                                mscorlib
                                2.0.0.0
                                4ef6c131
                                34a5
                                b2
                                System.IO.IOException
               
               
                                6.1.7601.2.1.0.272.7
                                1033
               
               
                                62F68A02-4CCC-4EFA-B6D6-446950477748
                                Dell Inc.
                                PowerEdge T610
                                2.2.10
               

1.       !token2ee mscorlib_ni 060034a5 – bcoz “06xxxxxx” is standard. – mscorlib is the guy who failed.


O/P:

!token2ee mscorlib 060034a5
0:012> !token2ee mscorlib_ni 060034a5
Module: 000007fef8e91000 (mscorlib.dll)
Token: 0x00000000060034a5
MethodDesc: 000007fef8f0fd00
Name: System.IO.__Error.WinIOError(Int32, System.String)
JITTED Code Address: 000007fef9163fa0


2.       !dumpil 000007fef8f0fd00 – Go to method and also go to b2 since this is the offset


O/P:

ilAddr = 000007fef96dba58
IL_0000: ldarg.0
IL_0001: ldc.i4.s 123
IL_0003: beq.s IL_000f
IL_0005: ldarg.0
IL_0006: ldc.i4 161
IL_000b: ceq
IL_000d: br.s IL_0010
IL_000f: ldc.i4.1
IL_0010: stloc.0
IL_0011: ldarg.1
IL_0012: ldloc.0
IL_0013: call System.IO.__Error::GetDisplayablePath
IL_0018: stloc.1
IL_0019: ldarg.0
IL_001a: stloc.2
IL_001b: ldloc.2
IL_001c: ldc.i4.s 80
IL_001e: bgt.s IL_005f
IL_0020: ldloc.2
IL_0021: ldc.i4.s 15
IL_0023: bgt.s IL_004a
IL_0025: ldloc.2
IL_0026: ldc.i4.2
IL_0027: sub
IL_0028: switch (IL_009a, IL_00d9, IL_025b, IL_011a)
IL_003d: ldloc.2
IL_003e: ldc.i4.s 15
IL_0040: beq IL_019c
IL_0045: br IL_025b
IL_004a: ldloc.2
IL_004b: ldc.i4.s 32
IL_004d: beq IL_01d8
IL_0052: ldloc.2
IL_0053: ldc.i4.s 80
IL_0055: beq IL_021d
IL_005a: br IL_025b
IL_005f: ldloc.2
IL_0060: ldc.i4 183
IL_0065: bgt.s IL_007f
IL_0067: ldloc.2
IL_0068: ldc.i4.s 87
IL_006a: beq IL_01c5
IL_006f: ldloc.2
IL_0070: ldc.i4 183
IL_0075: beq IL_015b
IL_007a: br IL_025b
IL_007f: ldloc.2
IL_0080: ldc.i4 206
IL_0085: beq IL_018c
IL_008a: ldloc.2
IL_008b: ldc.i4 995
IL_0090: beq IL_0255
IL_0095: br IL_025b
IL_009a: ldloc.1
IL_009b: callvirt System.String::get_Length
IL_00a0: brtrue.s IL_00b2
IL_00a2: ldstr "IO.FileNotFound"
IL_00a7: call System.Environment::GetResourceString
IL_00ac: newobj System.IO.FileNotFoundException::.ctor
IL_00b1: throw
IL_00b2: call System.Globalization.CultureInfo::get_CurrentCulture
IL_00b7: ldstr "IO.FileNotFound_FileName"
IL_00bc: call System.Environment::GetResourceString
IL_00c1: ldc.i4.1
IL_00c2: newarr System.Object
IL_00c7: stloc.3
IL_00c8: ldloc.3
IL_00c9: ldc.i4.0
IL_00ca: ldloc.1
IL_00cb: stelem.ref
IL_00cc: ldloc.3
IL_00cd: call System.String::Format
IL_00d2: ldloc.1
IL_00d3: newobj System.IO.FileNotFoundException::.ctor
IL_00d8: throw
IL_00d9: ldloc.1
IL_00da: callvirt System.String::get_Length
IL_00df: brtrue.s IL_00f1
IL_00e1: ldstr "IO.PathNotFound_NoPathName"
IL_00e6: call System.Environment::GetResourceString
IL_00eb: newobj System.IO.DirectoryNotFoundException::.ctor
IL_00f0: throw
IL_00f1: call System.Globalization.CultureInfo::get_CurrentCulture
IL_00f6: ldstr "IO.PathNotFound_Path"
IL_00fb: call System.Environment::GetResourceString
IL_0100: ldc.i4.1
IL_0101: newarr System.Object
IL_0106: stloc.s VAR OR ARG 4
IL_0108: ldloc.s VAR OR ARG 4
IL_010a: ldc.i4.0
IL_010b: ldloc.1
IL_010c: stelem.ref
IL_010d: ldloc.s VAR OR ARG 4
IL_010f: call System.String::Format
IL_0114: newobj System.IO.DirectoryNotFoundException::.ctor
IL_0119: throw
IL_011a: ldloc.1
IL_011b: callvirt System.String::get_Length
IL_0120: brtrue.s IL_0132
IL_0122: ldstr "UnauthorizedAccess_IODenied_NoPathName"
IL_0127: call System.Environment::GetResourceString
IL_012c: newobj System.UnauthorizedAccessException::.ctor
IL_0131: throw
IL_0132: call System.Globalization.CultureInfo::get_CurrentCulture
IL_0137: ldstr "UnauthorizedAccess_IODenied_Path"
IL_013c: call System.Environment::GetResourceString
IL_0141: ldc.i4.1
IL_0142: newarr System.Object
IL_0147: stloc.s VAR OR ARG 5
IL_0149: ldloc.s VAR OR ARG 5
IL_014b: ldc.i4.0
IL_014c: ldloc.1
IL_014d: stelem.ref
IL_014e: ldloc.s VAR OR ARG 5
IL_0150: call System.String::Format
IL_0155: newobj System.UnauthorizedAccessException::.ctor
IL_015a: throw
IL_015b: ldloc.1
IL_015c: callvirt System.String::get_Length
IL_0161: brfalse IL_025b
IL_0166: ldstr "IO.IO_AlreadyExists_Name"
IL_016b: ldc.i4.1
IL_016c: newarr System.Object
IL_0171: stloc.s VAR OR ARG 6
IL_0173: ldloc.s VAR OR ARG 6
IL_0175: ldc.i4.0
IL_0176: ldloc.1
IL_0177: stelem.ref
IL_0178: ldloc.s VAR OR ARG 6
IL_017a: call System.Environment::GetResourceString
IL_017f: ldarg.0
IL_0180: call Microsoft.Win32.Win32Native::MakeHRFromErrorCode
IL_0185: ldarg.1
IL_0186: newobj System.IO.IOException::.ctor
IL_018b: throw
IL_018c: ldstr "IO.PathTooLong"
IL_0191: call System.Environment::GetResourceString
IL_0196: newobj System.IO.PathTooLongException::.ctor
IL_019b: throw
IL_019c: call System.Globalization.CultureInfo::get_CurrentCulture
IL_01a1: ldstr "IO.DriveNotFound_Drive"
IL_01a6: call System.Environment::GetResourceString
IL_01ab: ldc.i4.1
IL_01ac: newarr System.Object
IL_01b1: stloc.s VAR OR ARG 7
IL_01b3: ldloc.s VAR OR ARG 7
IL_01b5: ldc.i4.0
IL_01b6: ldloc.1
IL_01b7: stelem.ref
IL_01b8: ldloc.s VAR OR ARG 7
IL_01ba: call System.String::Format
IL_01bf: newobj System.IO.DriveNotFoundException::.ctor
IL_01c4: throw
IL_01c5: ldarg.0
IL_01c6: call Microsoft.Win32.Win32Native::GetMessage
IL_01cb: ldarg.0
IL_01cc: call Microsoft.Win32.Win32Native::MakeHRFromErrorCode
IL_01d1: ldarg.1
IL_01d2: newobj System.IO.IOException::.ctor
IL_01d7: throw
IL_01d8: ldloc.1
IL_01d9: callvirt System.String::get_Length
IL_01de: brtrue.s IL_01f7
IL_01e0: ldstr "IO.IO_SharingViolation_NoFileName"
IL_01e5: call System.Environment::GetResourceString
IL_01ea: ldarg.0
IL_01eb: call Microsoft.Win32.Win32Native::MakeHRFromErrorCode
IL_01f0: ldarg.1
IL_01f1: newobj System.IO.IOException::.ctor
IL_01f6: throw
IL_01f7: ldstr "IO.IO_SharingViolation_File"
IL_01fc: ldc.i4.1
IL_01fd: newarr System.Object
IL_0202: stloc.s VAR OR ARG 8
IL_0204: ldloc.s VAR OR ARG 8
IL_0206: ldc.i4.0
IL_0207: ldloc.1
IL_0208: stelem.ref
IL_0209: ldloc.s VAR OR ARG 8
IL_020b: call System.Environment::GetResourceString
IL_0210: ldarg.0
IL_0211: call Microsoft.Win32.Win32Native::MakeHRFromErrorCode
IL_0216: ldarg.1
IL_0217: newobj System.IO.IOException::.ctor
IL_021c: throw
IL_021d: ldloc.1
IL_021e: callvirt System.String::get_Length
IL_0223: brfalse.s IL_025b
IL_0225: call System.Globalization.CultureInfo::get_CurrentCulture
IL_022a: ldstr "IO.IO_FileExists_Name"
IL_022f: call System.Environment::GetResourceString
IL_0234: ldc.i4.1
IL_0235: newarr System.Object
IL_023a: stloc.s VAR OR ARG 9
IL_023c: ldloc.s VAR OR ARG 9
IL_023e: ldc.i4.0
IL_023f: ldloc.1
IL_0240: stelem.ref
IL_0241: ldloc.s VAR OR ARG 9
IL_0243: call System.String::Format
IL_0248: ldarg.0
IL_0249: call Microsoft.Win32.Win32Native::MakeHRFromErrorCode
IL_024e: ldarg.1
IL_024f: newobj System.IO.IOException::.ctor
IL_0254: throw
IL_0255: newobj System.OperationCanceledException::.ctor
IL_025a: throw
IL_025b: ldarg.0
IL_025c: call Microsoft.Win32.Win32Native::GetMessage
IL_0261: ldarg.0
IL_0262: call Microsoft.Win32.Win32Native::MakeHRFromErrorCode
IL_0267: ldarg.1
IL_0268: newobj System.IO.IOException::.ctor
IL_026d: throw


I used the below links to find this out.


Debugging .Net applications crash using WinDbg

Commands:

1. .loadby sos clr

This command needed to load the SOS.dll and show you the CLR types and .net call stacks during debugging.

2. !threads
Displays all the threads information.

3. ~ s
Sets the particular thread.

4. !clrstack
Displays the .net callstack.

5.!dumpstack
Displays both native and .net call stack together.

6. ~* e !clrstack
Displays all threads call stack.

7. !pe
prints the exception if any present in the current threads
!pe -nested shall display nested exceptions if present.

8. !dumpheap -stat
Displays the heap status.

9. !dso 
Dumps the stack objects for current threads.

10. !dumpheap -type [Data Type you want to investigate]
Dumps the specified data type from the heap.




Setup for Programming cloud using Google App Engine


How to setup the machine for Cloud programming using Google app engine.

In this section we will see how to setup the machine programming Google app engine for windows using Python 2.7.

1. You need down load and install Python 2.7 version.
Google app engine works with Python2.7 version not Python2.5 version.
You can down the Python from Python.org. Direct download for Win7/8 from python-2.7.6.amd64.msi

2. You need log-in to google devwlopers site and  https://developers.google.com/appengine/downloads.
Down load the MSI and install.

Now you are ready to create the application locally in your machine.