Source code of Windows XP (NT5)
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.

220 lines
5.5 KiB

  1. /*===================================================================
  2. Microsoft Denali
  3. Microsoft Confidential.
  4. Copyright 1996 Microsoft Corporation. All Rights Reserved.
  5. Component: Main
  6. File: perfdata.cpp
  7. Owner: DmitryR
  8. PERFMON related data in asp.dll -- source file
  9. ===================================================================*/
  10. #include "denpre.h"
  11. #pragma hdrstop
  12. #include "perfdata.h"
  13. #include "memchk.h"
  14. // to access metabase
  15. #include <iiscnfg.h>
  16. #include <iwamreg.h>
  17. #ifndef PERF_DISABLE
  18. BOOL g_fPerfInited = FALSE;
  19. CPerfMainBlock g_PerfMain;
  20. CPerfData g_PerfData;
  21. /*===================================================================
  22. GetCurrentClsId
  23. Static function to find the current WAM CLSID in the metabase
  24. Parameters
  25. pIReq to retrieve WAM CLSID from the metabase
  26. pClsId [out] CLSID
  27. Returns:
  28. HRESULT
  29. ===================================================================*/
  30. static HRESULT GetCurrentClsId
  31. (
  32. CIsapiReqInfo *pIReq,
  33. CLSID *pClsId
  34. )
  35. {
  36. HRESULT hr = S_OK;
  37. Assert(pClsId);
  38. TCHAR *szMDPath = pIReq->QueryPszApplnMDPath();
  39. if (!szMDPath)
  40. {
  41. *pClsId = CLSID_NULL;
  42. return E_FAIL;
  43. }
  44. CLSID ClsId = CLSID_NULL;
  45. // Bracket ISA thread
  46. if (SUCCEEDED(StartISAThreadBracket(pIReq)))
  47. {
  48. WCHAR wszClsBuffer[80];
  49. DWORD dwRequiredLen, dwAppMode;
  50. // Find the application mode, inproc, out-of-proc, or pooled OOP
  51. hr = pIReq->GetAspMDData(szMDPath,
  52. MD_APP_ISOLATED,
  53. METADATA_INHERIT,
  54. IIS_MD_UT_WAM,
  55. DWORD_METADATA,
  56. sizeof(DWORD),
  57. 0,
  58. (unsigned char*) &dwAppMode,
  59. &dwRequiredLen);
  60. if (SUCCEEDED(hr))
  61. {
  62. switch (dwAppMode)
  63. {
  64. case eAppRunInProc:
  65. // preconfigured WAM CLSID for all inproc apps
  66. wcscpy(wszClsBuffer,
  67. L"{99169CB0-A707-11d0-989D-00C04FD919C1}");
  68. break;
  69. case eAppRunOutProcIsolated:
  70. // custom WAM CLSID for non-pooled OOP apps
  71. hr = pIReq->GetAspMDData(szMDPath,
  72. MD_APP_WAM_CLSID,
  73. METADATA_INHERIT,
  74. IIS_MD_UT_WAM,
  75. STRING_METADATA,
  76. sizeof(wszClsBuffer) / sizeof(WCHAR),
  77. 0,
  78. (unsigned char *)wszClsBuffer,
  79. &dwRequiredLen);
  80. break;
  81. case eAppRunOutProcInDefaultPool:
  82. // preconfigured WAM CLSID for the pooled OOP apps
  83. wcscpy(wszClsBuffer,
  84. L"{3D14228D-FBE1-11d0-995D-00C04FD919C1}");
  85. break;
  86. default:
  87. Assert(!"unknown AppMode");
  88. hr = E_FAIL;
  89. break;
  90. }
  91. }
  92. if (SUCCEEDED(hr))
  93. {
  94. // Convert string to CLSID
  95. hr = CLSIDFromString(wszClsBuffer, &ClsId);
  96. }
  97. EndISAThreadBracket(pIReq);
  98. }
  99. else
  100. {
  101. hr = E_FAIL;
  102. }
  103. if (SUCCEEDED(hr) && g_fOOP) // always CLSID_NULL if inproc
  104. *pClsId = ClsId;
  105. else
  106. *pClsId = CLSID_NULL;
  107. return hr;
  108. }
  109. /*===================================================================
  110. PreInitPerfData
  111. Initialize from DllInit
  112. Creates critical sections
  113. Parameters
  114. Returns:
  115. HRESULT
  116. ===================================================================*/
  117. HRESULT PreInitPerfData()
  118. {
  119. HRESULT hr = S_OK;
  120. hr = g_PerfData.InitCriticalSections();
  121. return hr;
  122. }
  123. /*===================================================================
  124. InitPerfDataOnFirstRequest
  125. Initialize PERFMON related ASP data from first request
  126. Parameters
  127. pIReq to retrieve WAM CLSID from the metabase
  128. Returns:
  129. HRESULT
  130. ===================================================================*/
  131. HRESULT InitPerfDataOnFirstRequest
  132. (
  133. CIsapiReqInfo *pIReq
  134. )
  135. {
  136. // Get CLSID from metabase
  137. CLSID ClsId;
  138. HRESULT hr = GetCurrentClsId(pIReq, &ClsId);
  139. // Check HRESULT from GetCurrentClsId
  140. if (FAILED(hr))
  141. return hr;
  142. // access main shared memory
  143. if (SUCCEEDED(hr))
  144. hr = g_PerfMain.Init();
  145. // access shared memory of this process
  146. if (SUCCEEDED(hr))
  147. hr = g_PerfData.Init(ClsId);
  148. // add this process data to main shared memory
  149. if (SUCCEEDED(hr))
  150. hr = g_PerfMain.AddProcess(ClsId);
  151. if (FAILED(hr))
  152. {
  153. g_PerfData.UnInit();
  154. g_PerfMain.UnInit();
  155. }
  156. return hr;
  157. }
  158. /*===================================================================
  159. UnInitPerfData
  160. UnInitialize PERFMON related ASP data
  161. Returns:
  162. HRESULT
  163. ===================================================================*/
  164. HRESULT UnInitPerfData()
  165. {
  166. // remove this process data from main shared memory
  167. if (g_PerfData.FValid())
  168. g_PerfMain.RemoveProcess(g_PerfData.ClsId());
  169. // stop accessing process shared memory
  170. g_PerfData.UnInit();
  171. // stop accessing main shared memory
  172. g_PerfMain.UnInit();
  173. return S_OK;
  174. }
  175. #endif // PERF_DISABLE