Presentation is loading. Please wait.

Presentation is loading. Please wait.

Matt Young Windows Mobile Joint Development Program (JDP) Microsoft

Similar presentations


Presentation on theme: "Matt Young Windows Mobile Joint Development Program (JDP) Microsoft"— Presentation transcript:

1 Matt Young Windows Mobile Joint Development Program (JDP) Microsoft
Memory Leak Detection Matt Young Windows Mobile Joint Development Program (JDP) Microsoft © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

2 OEM Hardware and Standard Drivers Standard PC Hardware and Drivers
4/17/2017 7:57 PM Hardware/Drivers OEM/IHV Supplied BSP (ARM, SH4, MIPS) OEM Hardware and Standard Drivers Standard PC Hardware and Drivers Windows XP DDK Device Building Tools Platform Builder Windows Embedded Studio Data Lightweight Relational EDB SQL Server 2005 Express Edition SQL Server 2005 Mobile Edition SQL Server 2005 Native Managed Server Side Win32 Programming Model MFC 8.0, ATL 8.0 .NET Compact Framework .NET Framework ASP.NET Mobile Controls ASP.NET Multimedia Windows Media DirectX Location Services MapPoint Development Tools Visual Studio 2005 Internet Security and Acceleration Server Communications & Messaging Exchange Server Live Communications Server Speech Server Device Update Agent Management Tools Image Update Software Update Services Systems Management Server Microsoft Operations Manager © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

3 Agenda Intro LMemDebug Application Verifier CeLog Data
4/17/2017 7:57 PM Agenda Intro LMemDebug Application Verifier CeLog Data © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

4 Memory Leaks… …are deadly … ruin otherwise good devices
4/17/2017 7:57 PM Memory Leaks… …are deadly … ruin otherwise good devices PC model does not apply! Embedded/Mobile devices run constantly Devices are perceived differently Devices have as little memory as possible © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

5 Agenda LMemDebug Application Verifier CeLog Data 4/17/2017 7:57 PM
© 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

6 LMemDebug Monitors heap APIs Provided in Platform Builder
4/17/2017 7:57 PM LMemDebug Monitors heap APIs Provided in Platform Builder Access through ‘Shell’ tool © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

7 Programmatic LMem Applications can control LMemDebug
4/17/2017 7:57 PM Programmatic LMem Applications can control LMemDebug Append extra information to allocs Set flags per allocations Set flags globally Applications can tag memory allocs HeapAllocTrace Easily tag allocs with file and line number © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

8 Using LMemDebug Use Shell to query memory status
4/17/2017 7:57 PM Using LMemDebug Use Shell to query memory status LMem <proc>|* [recent] [hist] [chk] [delta] [info] [<heap>|*] [breaksize <NN>] [breakcnt <NN>] proc : Proc index, name, PID or * (for all processes) recent : Show list of recent allocations hist : Show histogram of alloc size chk : Checkpoint all current allocations delta : Report allocations since checkpoint info : Report any additional info stored with the allocations (stack etc.) heap : Heap index, handle or * for all heaps breaksize <NN> : Break when size is NN breakcnt <NN> : Break when count is NN © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

9 LMem Output Output of one mem alloc
4/17/2017 7:57 PM LMem Output Output of one mem alloc Show alloc call file and line number Stack at time of alloc call Ptr=0x000302C0 Size=32768 Count=15 LineNum=724 File=C:\.. \41MemTest.C Stack=0x03F7A3C2 coredll.dll+0x3A3C2 Stack=0x03F78BB6 coredll.dll+0x38BB6 Stack=0x C 41MemTest.exe+0x1205C Stack=0x MemTest.exe+0x11704 Stack=0x A 41MemTest.exe+0x1133A Stack=0x03F6199C coredll.dll+0x2199C Stack=0x03F61F66 coredll.dll+0x21F66 Stack=0x MemTest.exe+0x11092 Stack=0x10013DC4 41MemTest.exe+0x13DC4 Stack=0x03F6B6A0 coredll.dll+0x2B6A0 © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

10 LMem Output Ptr=0x00030320 Size=212 Count=8 LineNum=3217
4/17/2017 7:57 PM LMem Output Ptr=0x Size=212 Count=8 LineNum=3217 File=d:\jameson\private\winceos\osshell\commctrl\toolbar.cpp Stack=0x03F7A3C2 coredll.dll+0x3A3C2 _HeapAllocTrace Stack=0x03F78BB6 coredll.dll+0x38BB6 _LocalAllocTrace Stack=0x03E52130 commctrl.dll+0x32130 Stack=0x03F647C0 coredll.dll+0x247C0 _xxx_PerformCallBack4 Stack=0x0A06D378 gwes.exe+0x6D378 Stack=0x0A035BB8 gwes.exe+0x35BB8 Stack=0x0A03ECEA gwes.exe+0x3ECEA Stack=0x03F5F5D8 coredll.dll+0x1F5D8 _xxx_CreateWindowExW Stack=0x03E49DD4 commctrl.dll+0x29DD4 _CommandBar_Create Stack=0x100114C6 41MemTest.exe+0x114C6 _DoCreateMain © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

11 Kernel, FileSys,Device,GWES
4/17/2017 7:57 PM How LMem Works Application LocalAlloc HeapSize HeapAlloc LMEMDebug.DLL CoreDLL Int_HeapAlloc Kernel, FileSys,Device,GWES © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

12 Kernel, FileSys,Device,GWES
4/17/2017 7:57 PM How LMem Works Application CoreDLL HeapCreate HeapAlloc HeapAllocTrace HeapReAlloc HeapFree HeapSize HeapDestroy Kernel, FileSys,Device,GWES © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

13 Writing your Own LMem CoreDLL heap API has built in hooks
4/17/2017 7:57 PM Writing your Own LMem CoreDLL heap API has built in hooks At App init, coredll looks for LMemDebug.DLL Loads the following entry points HeapCreate HeapDestroy HeapAlloc HeapAllocTrace HeapReAlloc HeapFree HeapSize © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

14 Writing Your Own LMem Helper functions will do the work
4/17/2017 7:57 PM Writing Your Own LMem Helper functions will do the work Int_HeapCreate Int_HeapDestroy Int_HeapAlloc Int_HeapAllocTrace Int_HeapReAlloc Int_HeapFree Int_HeapSize Only need to export functions you want You get the source to LMemDebug! public\common\oak\drivers\lmemdebug © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

15 LMemDebug Improvements
4/17/2017 7:57 PM LMemDebug Improvements Track fragmentation over time Track Page usage Track buffer overruns Improved UI Real time reporting to Dev PC Graphical histograms © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

16 LMem Summary Advantages Disadvantages Fairly quick
4/17/2017 7:57 PM LMem Summary Advantages Fairly quick Provides call stack info for allocations Heap histogram Disadvantages Uses debug serial port as output Monitors all applications Command line interface © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

17 Agenda LMemDebug Application Verifier CeLog Data 4/17/2017 7:57 PM
© 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

18 Application Verifier Part of the Windows CE Test Kit Monitors
4/17/2017 7:57 PM Application Verifier Part of the Windows CE Test Kit Monitors Heap allocations Handle allocations GDI Resources More… If you knew how to write a shim…(Coming soon!) © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

19 Using the App Verifier Can be used many ways
4/17/2017 7:57 PM Using the App Verifier Can be used many ways Locally on the device Using the Platform Builder Shell tool From a development PC via Ethernet Output is a log file that is placed on the device © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

20 App Verifier from the PC
4/17/2017 7:57 PM App Verifier from the PC © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

21 App Verifier from the PC
4/17/2017 7:57 PM App Verifier from the PC Advantages Easier to control from PC Automatically brings data to PC Disadvantages Needs ActiveSync or Ethernet connection © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

22 App Verifier on the Device
4/17/2017 7:57 PM App Verifier on the Device © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

23 App Verifier on the Device
4/17/2017 7:57 PM App Verifier on the Device Advantages No need for a connection with a PC Disadvantages Requires a device U/I Dialog needs a 800x600 screen © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

24 App Verifier with Shell
4/17/2017 7:57 PM App Verifier with Shell Application verifier can be run as a ‘Shell’ extension At the shell prompt Load the extensions To ready the shim for the application Run the application Windows CE>loadext AppVerifSh.dll Windows CE>loadext shim_heap.dll Windows CE>appverif -m pword.exe -s shim_heap.dll © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

25 App Verifier with Shell
4/17/2017 7:57 PM App Verifier with Shell Advantages No device U/I required Can run from Device PC using Platform Builder PC using a serial port Disadvantages Not a polished as the other methods © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

26 4/17/2017 7:57 PM How It Works Inserts a ‘shim’ between the application and specific APIs exported by the operating system The shim intercepts the heap APIs Captures the stack on every alloc Matches every free with an alloc Reports allocs that don’t have a free © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

27 The Shim Engine Application Shim 1 Shim 2 CoreDLL Kernel Other Dlls
4/17/2017 7:57 PM The Shim Engine Application Shim 1 Shim 2 CoreDLL Other Dlls Kernel Registry © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

28 4/17/2017 7:57 PM The Shim Engine Application Verifier uses the Shim Engine to monitor calls from the application to the operating system The Shim Engine has hooks in the kernel loader When dynamic linking occurs, the shim engine looks in the registry to see if a shim should be linked instead © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

29 App Verifier Summary Advantages Disadvantages
4/17/2017 7:57 PM App Verifier Summary Advantages Monitors on a per process level Uses .map file info for stack trace Flexible user interface Disadvantages Sometime flaky connectivity Not open to developer improvement (Changing soon!) © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

30 Agenda LMemDebug Application Verifier CeLog Data 4/17/2017 7:57 PM
© 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

31 CELog Tool Generates data for the Kernel Tracker
4/17/2017 7:57 PM CELog Tool Generates data for the Kernel Tracker Implemented as a kernel library The raw data is in a known format Other tools use the same data ReadLog Memalyzer © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

32 CELog Zones CELog records information in many areas CELZONE_INTERRUPT
4/17/2017 7:57 PM CELog Zones CELog records information in many areas CELZONE_INTERRUPT Events related to interrupts. CELZONE_RESCHEDULE Events related to the scheduler. CELZONE_MIGRATE Events related to migration of threads between processes. CELZONE_TLB Events related to the translation look-aside buffer (TLB). CELZONE_DEMANDPAGE Events related to paging. CELZONE_THREAD Events related to threads, except for thread switches. CELZONE_PROCESS Events related to processes. CELZONE_PRIORITYINV Events related to priority inversion. CELZONE_CRITSECT Events related to critical sections. CELZONE_SYNCH Events related to synchronization. CELZONE_HEAP Events related to heaps. CELZONE_VIRTMEM Events related to virtual memory. CELZONE_LOADER Events related to the loader. CELZONE_MEMTRACKING Events related to memory tracking. CELZONE_BOOT_TIME Events in the boot process CELZONE_KCALL Events related to KCALLs. © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

33 Zones For Memory Tracking
4/17/2017 7:57 PM Zones For Memory Tracking By default, almost all zones are enabled All but CELZONE_KCALL This generates a huge amount of data For memory tracking Turn off all zones but CELZONE_HEAP, CELZONE_VIRTMEM, CELZONE_MEMTRACKING This dramatically reduces the information being saved and flushed This is still a fair amount of information © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

34 CELog Zone Control Zones are set in the registry Using Shell
4/17/2017 7:57 PM CELog Zone Control Zones are set in the registry On the device On the PC (if attached via KITL) Using Shell memtrack command Programmatically dwZoneCE set the zones discussed void CeLogSetZones (DWORD dwZoneUser, DWORD dwZoneCE, DWORD dwZoneProcess); © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

35 Using CELog For retail device, copy the following files to the device
4/17/2017 7:57 PM Using CELog For retail device, copy the following files to the device CELog.DLL CELogFlush.EXE Start CELogFlush –z 8000 –n <file> Enable memtracking events to <file> Filename shouldn’t have spaces Run app Then copy file.clg to PC © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

36 Memalyzer This tool is provided in Platform Builder but not documented
4/17/2017 7:57 PM Memalyzer This tool is provided in Platform Builder but not documented Takes a CELog file as input Parses out the memory log info Outputs the results to .txt or .htm © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

37 Running Memalyzer 4/17/2017 7:57 PM
USAGE: memalyzer.exe [-pid <process handle>, -name <process name>, -fullscan] [-map <path>] [output_flags] <file name> Choose one way to specify which process(es) to output: -pid <handle> - specify process by handle -name <name> - specify process by name -fullscan output data for all processes (DEFAULT) -map <path> - specify location to read .map files from Output flags are one or more of the following: -v verbose: print full stack frames (cooked output only) -nounload - do not unload modules -out:raw print packets as logged -out:cooked - print packets after processing -out:noerror - suppress errors (such as duplicate loads/allocs) -out:nomods - suppress output of module load/unload data -out:html - output HTML files instead of plaintext © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

38 CELog Summary Advantages Disadvantages Kernel level monitoring
4/17/2017 7:57 PM CELog Summary Advantages Kernel level monitoring Open data collection model Memalyzer understands .map files Disadvantages Logging is globally enabled The log buffer can be quite large Logging is a performance hit Memalyzer isn’t formally supported © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

39 Summary LMemDebug App Verifier CELog / Memalyzer
4/17/2017 7:57 PM Summary LMemDebug Great for heap only analysis Source available App Verifier Memory, handle, GDI leak monitor CELog / Memalyzer Handy for detailed dumps © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

40 Questions myoung @ microsoft.com 4/17/2017 7:57 PM
© 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

41 © 2005 Microsoft Corporation. All rights reserved.
4/17/2017 7:57 PM © 2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary. © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

42 After The Conference… Build Develop Install
4/17/2017 7:57 PM After The Conference… Build Install Build Join Full-featured trial versions of Windows CE and/or Windows XP Embedded Cool stuff & tell us about it: msdn.microsoft.com/embedded/community Windows Embedded Partner Program: Develop Install Enter Join Windows Mobile 5.0 Eval Kit including Visual Studio 2005 Beta 2 Mobile2Market Contest and win up to $25000: mobile2marketcontest.com Microsoft Solutions Partner Program: partner.microsoft.com © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

43 Tools & Resources Build Develop Websites Newsgroups Blogs Tools
4/17/2017 7:57 PM Tools & Resources Build Develop Websites msdn.microsoft.com/ embedded msdn.microsoft.com/ mobility Newsgroups microsoft.public windowsxp.embedded windowsce.platbuilder windowsce.embedded.vc microsoft.public pocketpc.developer smartphone.developer dotnet.framework.compactframework Blogs blogs.msdn.com/ mikehall blogs.msdn.com/ windowsmobile vsdteam netcfteam Tools Windows CE 5.0 Eval Kit Windows XP Embedded Eval Kit Windows Mobile 5.0 Eval Kit © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.


Download ppt "Matt Young Windows Mobile Joint Development Program (JDP) Microsoft"

Similar presentations


Ads by Google