MCPcopy Create free account
hub / github.com/OpenNI/OpenNI / xnOSWriteMemoryReport

Function xnOSWriteMemoryReport

Source/OpenNI/XnOSMemoryProfiling.cpp:204–272  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

202}
203
204XN_C_API void xnOSWriteMemoryReport(const XnChar* csFileName)
205{
206 XN_FILE_HANDLE FileHandle;
207 XnStatus nRetVal = xnOSOpenFile(csFileName, XN_OS_FILE_WRITE | XN_OS_FILE_TRUNCATE, &FileHandle);
208 if (nRetVal != XN_STATUS_OK) return;
209
210 const XnUInt32 nReportLineMaxSize = 2048;
211 XnChar csReportLine[nReportLineMaxSize];
212 XnUInt32 nReportLength = 0;
213
214 XnUInt32 nChars;
215
216 XnUInt32 nSum = 0;
217 xnOSStrFormat(csReportLine + nReportLength, nReportLineMaxSize - nReportLength, &nChars, "Allocated memory blocks:\n");
218 nReportLength += nChars;
219 xnOSStrFormat(csReportLine + nReportLength, nReportLineMaxSize - nReportLength, &nChars, "============================================\n");
220 nReportLength += nChars;
221
222 xnOSWriteFile(FileHandle, csReportLine, nReportLength);
223 nReportLength = 0;
224
225 {
226 XnAutoCSLocker lock(g_hCS);
227 for (XnMemBlockDataNode* pNode = g_allocatedMemory.pFirst; pNode != NULL; pNode = pNode->pNext)
228 {
229 xnOSStrFormat(csReportLine + nReportLength, nReportLineMaxSize - nReportLength, &nChars, "%d bytes allocated at 0x%08x using %s", pNode->Data.nBytes, pNode->Data.pMemBlock, XnGetAllocTypeString(pNode->Data.nAllocType));
230 nReportLength += nChars;
231
232 if (pNode->Data.csAdditional != NULL)
233 {
234 xnOSStrFormat(csReportLine + nReportLength, nReportLineMaxSize - nReportLength, &nChars, " (%s)", pNode->Data.csAdditional);
235 nReportLength += nChars;
236 }
237
238 xnOSStrFormat(csReportLine + nReportLength, nReportLineMaxSize - nReportLength, &nChars, " at %s [%s, %d]\n", pNode->Data.csFunction, pNode->Data.csFile, pNode->Data.nLine);
239 nReportLength += nChars;
240
241 if (pNode->Data.nFrames > 0)
242 {
243 xnOSStrFormat(csReportLine + nReportLength, nReportLineMaxSize - nReportLength, &nChars, "Callstack:\n");
244 nReportLength += nChars;
245
246 for (XnUInt i = 0; i < pNode->Data.nFrames; ++i)
247 {
248 xnOSStrFormat(csReportLine + nReportLength, nReportLineMaxSize - nReportLength, &nChars, "\t%s\n", pNode->Data.aFrames[i]);
249 nReportLength += nChars;
250 }
251 }
252
253 xnOSStrFormat(csReportLine + nReportLength, nReportLineMaxSize - nReportLength, &nChars, "\n");
254 nReportLength += nChars;
255
256 xnOSWriteFile(FileHandle, csReportLine, nReportLength);
257 nReportLength = 0;
258
259 nSum += pNode->Data.nBytes;
260 }
261 }

Callers 1

xnContextDestroyFunction · 0.85

Calls 5

xnOSStrFormatFunction · 0.85
XnGetAllocTypeStringFunction · 0.85
xnOSOpenFileFunction · 0.50
xnOSWriteFileFunction · 0.50
xnOSCloseFileFunction · 0.50

Tested by

no test coverage detected