Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.6 KiB

  1. // DPLOG.cpp : Defines the entry point for the console application.
  2. //
  3. #include "stdafx.h"
  4. #include "..\common\memlog.h"
  5. int main(int argc, char* argv[])
  6. {
  7. HANDLE hFile=0;
  8. HANDLE hMutex=0;
  9. LPVOID lpMemory=NULL;
  10. UINT timebase=0;
  11. UINT i=0;
  12. PSHARED_LOG_FILE pLogFile =NULL;
  13. PLOG_ENTRY pLog =NULL;
  14. PLOG_ENTRY pReadEntry =NULL;
  15. hFile=CreateFileMappingA(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, DPLOG_SIZE, BASE_LOG_FILENAME);
  16. hMutex=CreateMutexA(NULL, FALSE, BASE_LOG_MUTEXNAME);
  17. lpMemory=MapViewOfFile(hFile, FILE_MAP_ALL_ACCESS, 0, 0, 0);
  18. if(!hFile || !hMutex || !lpMemory){
  19. goto exit;
  20. }
  21. pLogFile=(PSHARED_LOG_FILE)lpMemory;
  22. pLog=(PLOG_ENTRY)(pLogFile+1);
  23. WaitForSingleObject(hMutex,INFINITE);
  24. if(pLogFile->cInUse == pLogFile->nEntries){
  25. // dump last half of buffer
  26. for(i=pLogFile->iWrite; i < pLogFile->nEntries; i++){
  27. pReadEntry=(PLOG_ENTRY)(((CHAR *)pLog)+(i*(pLogFile->cbLine+sizeof(LOG_ENTRY))));
  28. printf("%4d: %8x %6d %2x %s\n",i,pReadEntry->hThread,pReadEntry->tLogged-timebase,pReadEntry->DebugLevel, pReadEntry->str);
  29. timebase=pReadEntry->tLogged;
  30. }
  31. }
  32. // dump firt part of buffer
  33. for(i=0;i<pLogFile->iWrite;i++){
  34. pReadEntry=(PLOG_ENTRY)(((CHAR *)pLog)+(i*(pLogFile->cbLine+sizeof(LOG_ENTRY))));
  35. printf("%4d: %8x %6d %2x %s\n",i,pReadEntry->hThread,pReadEntry->tLogged-timebase,pReadEntry->DebugLevel, pReadEntry->str);
  36. timebase=pReadEntry->tLogged;
  37. }
  38. ReleaseMutex(hMutex);
  39. UnmapViewOfFile(lpMemory);
  40. exit:
  41. if(hFile){
  42. CloseHandle(hFile);
  43. }
  44. if(hMutex){
  45. CloseHandle(hMutex);
  46. }
  47. return 0;
  48. }