堆日志记录工具(Heaplogger)
文章信息
堆日志记录工具(Heaplogger)
Heaplogger 第一版
这个Lib是一个堆调查工具。设计用来协助跟踪内存泄漏,当你做了一个OS调用时找出它是怎么回事。
它给了你记录所有内存分配和导出堆到日志文件的能力。你也能做注解,这样就能把内存分配和你的代码联系起来。函数描述见头文件:
/**This function will go at the start of your app. It will give a config line line like
* This is the Heap Logger Dump.
* Old heap contains 000000 bytes in 000000 cells.
* If there are any cells already allocated, the old heap should be switched back
* in with User::SwitchHeap() before these cells are freed.
*
* @param aFileName is the name of the log file created
* @return the old RHeap.
*/
IMPORT_C static RHeap* HeapLogger::UseHeapLogger(const TDesC& aFileName);
/**This sets what will actually be logged. Defaults to ELogNothing
* @param aMode is an ored combination of THeapLoggerMode
*/
IMPORT_C static void HeapLogger::SetMode(TInt aMode);
/**When content is logged (on Free or a heap dump) this is the max
* length of the buffer to be logged.
* @param aMaxLen the max length to log.*/
IMPORT_C static void HeapLogger::SetMaxContentLength(TInt aMaxLen);
/**This dumps the current heap into the log file.*/
IMPORT_C static void HeapLogger::DumpHeap();
/**This allows you to put tags in the log file so that you can tie the
* allocations to sections of code.
* @param aLogStr is a tag for your code to annotate the log.
* @param this is the file, normally given by "__FILE__"
* @param this is the lin number in the source file. Given by "__LINE__"*/
IMPORT_C static void HeapLogger::Log(const TDesC8& aLogStr, const char* aFile, TInt aLine);
用法
欲用heaplogger,只需在mmp file包含头文件和静态库文件,然后调用上述函数。可以在下面地址下载一个Hello world例子:
http://homepage.virgin.net/mr.nigel.brown/examples/Lumberjack1.zip.
Lumberjack只是使用这个日志工具记录一些随机的东西。库文件和头文件已包括其中。库文件是针对Series 60 3rd MR编译的,但在其他Symbian OS V.9平台下也应该可以工作。
这个工具可工作在emulator上,但有更好的工具可用,因此实际上这个工具只在目标设备上有用。而且,在记录日志时它使应用程序运行得难以置信的慢,因而长期使用无益,只适于做一次性调查。日志文件也是很大的。
通过在进程中替换堆为自定义的版本一切就能工作了。我已在实际工作中用了几次,不是完全测试过。发布在这里很大程度是为取乐。
我的确碰到过一些有关使用它和carbide中目标设备调试方面的问题,但那已经过去了。 有任何意见,可张贴在这里。


(no comments yet)