PerformanceCounterCategory.Create 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
向系統註冊一個自訂的效能計數器類別及一個或多個計數器。
多載
| 名稱 | Description |
|---|---|
| Create(String, String, String, String) |
已淘汰.
已淘汰.
已淘汰.
在本地電腦註冊一個自訂效能計數器類別,該類別包含一個 類型的 |
| Create(String, String, PerformanceCounterCategoryType, String, String) |
登錄本地電腦上包含單一計 NumberOfItems32 數器的自訂效能計數器類別。 |
| Create(String, String, CounterCreationDataCollection) |
已淘汰.
已淘汰.
已淘汰.
登錄本地電腦中包含指定計數器的自訂效能計數器類別。 |
| Create(String, String, PerformanceCounterCategoryType, CounterCreationDataCollection) |
登錄本地電腦中包含指定計數器的自訂效能計數器類別。 |
Create(String, String, String, String)
警告
This overload of PerformanceCounterCategory.Create has been deprecated. Use System.Diagnostics.PerformanceCounterCategory.Create(string categoryName, string categoryHelp, PerformanceCounterCategoryType categoryType, string counterName, string counterHelp) instead.
警告
This method has been deprecated. Please use System.Diagnostics.PerformanceCounterCategory.Create(string categoryName, string categoryHelp, PerformanceCounterCategoryType categoryType, string counterName, string counterHelp) instead. http://go.microsoft.com/fwlink/?linkid=14202
警告
This method has been deprecated. Please use System.Diagnostics.PerformanceCounterCategory.Create(string categoryName, string categoryHelp, PerformanceCounterCategoryType categoryType, string counterName, string counterHelp) instead. https://go.microsoft.com/fwlink/?linkid=14202
在本地電腦註冊一個自訂效能計數器類別,該類別包含一個 類型的 NumberOfItems32 計數器。
public:
static System::Diagnostics::PerformanceCounterCategory ^ Create(System::String ^ categoryName, System::String ^ categoryHelp, System::String ^ counterName, System::String ^ counterHelp);
[System.Obsolete("This overload of PerformanceCounterCategory.Create has been deprecated. Use System.Diagnostics.PerformanceCounterCategory.Create(string categoryName, string categoryHelp, PerformanceCounterCategoryType categoryType, string counterName, string counterHelp) instead.")]
public static System.Diagnostics.PerformanceCounterCategory Create(string categoryName, string categoryHelp, string counterName, string counterHelp);
public static System.Diagnostics.PerformanceCounterCategory Create(string categoryName, string categoryHelp, string counterName, string counterHelp);
[System.Obsolete("This method has been deprecated. Please use System.Diagnostics.PerformanceCounterCategory.Create(string categoryName, string categoryHelp, PerformanceCounterCategoryType categoryType, string counterName, string counterHelp) instead. http://go.microsoft.com/fwlink/?linkid=14202")]
public static System.Diagnostics.PerformanceCounterCategory Create(string categoryName, string categoryHelp, string counterName, string counterHelp);
[System.Obsolete("This method has been deprecated. Please use System.Diagnostics.PerformanceCounterCategory.Create(string categoryName, string categoryHelp, PerformanceCounterCategoryType categoryType, string counterName, string counterHelp) instead. https://go.microsoft.com/fwlink/?linkid=14202")]
public static System.Diagnostics.PerformanceCounterCategory Create(string categoryName, string categoryHelp, string counterName, string counterHelp);
[<System.Obsolete("This overload of PerformanceCounterCategory.Create has been deprecated. Use System.Diagnostics.PerformanceCounterCategory.Create(string categoryName, string categoryHelp, PerformanceCounterCategoryType categoryType, string counterName, string counterHelp) instead.")>]
static member Create : string * string * string * string -> System.Diagnostics.PerformanceCounterCategory
static member Create : string * string * string * string -> System.Diagnostics.PerformanceCounterCategory
[<System.Obsolete("This method has been deprecated. Please use System.Diagnostics.PerformanceCounterCategory.Create(string categoryName, string categoryHelp, PerformanceCounterCategoryType categoryType, string counterName, string counterHelp) instead. http://go.microsoft.com/fwlink/?linkid=14202")>]
static member Create : string * string * string * string -> System.Diagnostics.PerformanceCounterCategory
[<System.Obsolete("This method has been deprecated. Please use System.Diagnostics.PerformanceCounterCategory.Create(string categoryName, string categoryHelp, PerformanceCounterCategoryType categoryType, string counterName, string counterHelp) instead. https://go.microsoft.com/fwlink/?linkid=14202")>]
static member Create : string * string * string * string -> System.Diagnostics.PerformanceCounterCategory
Public Shared Function Create (categoryName As String, categoryHelp As String, counterName As String, counterHelp As String) As PerformanceCounterCategory
參數
- categoryName
- String
自訂效能計數器類別的名稱,用於建立並註冊系統。
- categoryHelp
- String
自訂類別的說明。
- counterName
- String
一個新的計數器名稱,類型為 NumberOfItems32,作為新類別的一部分來創建。
- counterHelp
- String
與新自訂類別相關的計數器描述。
傳回
PerformanceCounterCategory A 與新的系統類別或效能物件相關聯。
- 屬性
例外狀況
counterName 是 null 或是空字串(“”)。
-或-
由 指定的 counterName 計數器已經存在。
-或-
counterName 語法無效。 它可能包含反斜線字元(“\”),或長度超過80個字元。
該類別已存在於本地電腦中。
基礎系統 API 的呼叫失敗。
未取得管理權限執行的程式碼嘗試讀取效能計數器。
備註
Note
要讀取 Windows Vista 及以後版本、Windows XP Professional x64 版或 Windows Server 2003 中非互動式登入會話的效能計數器,您必須是效能監控使用者群組的成員或擁有管理員權限。
若要避免提高許可權以存取 Windows Vista 和更新版本中的性能計數器,請將您自己新增至性能監視器使用者群組。
在 Windows Vista 和更新版本中,用戶帳戶控制 (UAC) 會決定用戶的許可權。 如果你是內建管理員群組的成員,你會被分配兩個執行時存取權杖:一個標準使用者存取權杖和一個管理員存取權杖。 根據預設,您處於標準使用者角色。 要執行存取效能計數器的程式碼,你必須先將權限從標準使用者提升為管理員。 當您以滑鼠右鍵按下應用程式圖示,並指出您想要以系統管理員身分執行,即可啟動應用程式。
另請參閱
適用於
Create(String, String, PerformanceCounterCategoryType, String, String)
登錄本地電腦上包含單一計 NumberOfItems32 數器的自訂效能計數器類別。
public:
static System::Diagnostics::PerformanceCounterCategory ^ Create(System::String ^ categoryName, System::String ^ categoryHelp, System::Diagnostics::PerformanceCounterCategoryType categoryType, System::String ^ counterName, System::String ^ counterHelp);
public static System.Diagnostics.PerformanceCounterCategory Create(string categoryName, string categoryHelp, System.Diagnostics.PerformanceCounterCategoryType categoryType, string counterName, string counterHelp);
static member Create : string * string * System.Diagnostics.PerformanceCounterCategoryType * string * string -> System.Diagnostics.PerformanceCounterCategory
Public Shared Function Create (categoryName As String, categoryHelp As String, categoryType As PerformanceCounterCategoryType, counterName As String, counterHelp As String) As PerformanceCounterCategory
參數
- categoryName
- String
自訂效能計數器類別的名稱,用於建立並註冊系統。
- categoryHelp
- String
自訂類別的說明。
- categoryType
- PerformanceCounterCategoryType
PerformanceCounterCategoryType其中一個值用來指定該類別是 MultiInstance、 、 SingleInstance或 Unknown。
- counterName
- String
新類別中要創建的新計數物名稱。
- counterHelp
- String
與新自訂類別相關的計數器描述。
傳回
PerformanceCounterCategory A 與新的系統類別或效能物件相關聯。
例外狀況
counterName 是 null 或是空字串(“”)。
-或-
由 指定的 counterName 計數器已經存在。
-或-
counterName 語法無效。 它可能包含反斜線字元(“\”),或長度超過80個字元。
該類別已存在於本地電腦中。
基礎系統 API 的呼叫失敗。
未取得管理權限執行的程式碼嘗試讀取效能計數器。
範例
以下程式碼範例展示了該 Create 方法的使用方式。 範例展示了如何建立自訂的單一實例效能計數器類別。
Console.WriteLine("Creating Inventory custom counter");
if (!PerformanceCounterCategory.Exists("Inventory"))
PerformanceCounterCategory.Create("Inventory",
"Truck inventory",
PerformanceCounterCategoryType.SingleInstance,
"Trucks", "Number of trucks on hand");
Console.WriteLine("Creating Inventory custom counter")
If Not PerformanceCounterCategory.Exists("Inventory") Then
PerformanceCounterCategory.Create("Inventory", "Truck inventory", PerformanceCounterCategoryType.SingleInstance, "Trucks", "Number of trucks on hand")
End If
備註
參數 categoryType 指定效能計數器類別是單一實例還是多實例。 預設情況下,類別在建立時為單一實例,新增實例後則為多實例。 類別會在應用程式設定時建立,實例則在執行時加入。 列 PerformanceCounterCategoryType 舉用來表示效能計數器是否可以有多個實例。
安裝於 .NET 的效能計數器類別會使用獨立的共享記憶體,每個效能計數器類別都有自己的記憶體。 你可以在登錄檔鍵 HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\<類別名稱>\效能中建立名為 FileMappingSize 的 DWORD 來指定獨立共享記憶體的大小。 FileMappingSize 值設為該類別的共享記憶體大小。 預設大小為131072小數。 若 FileMappingSize 值不存在,則 fileMappingSize 會使用 Machine.config 檔案中指定的屬性值 performanceCounters ,這會增加組態檔案處理的額外負擔。 你可以透過在登錄檔設定檔案映射大小來實現應用程式啟動效能的提升。
Note
強烈建議在應用程式安裝時建立新的效能計數器類別,而非執行時。 這讓作業系統有時間更新其註冊的效能計數器類別清單。 若清單未被刷新,嘗試使用該類別將失敗。
Note
要讀取 Windows Vista 及以後版本、Windows XP Professional x64 版或 Windows Server 2003 中非互動式登入會話的效能計數器,您必須是效能監控使用者群組的成員或擁有管理員權限。
若要避免提高許可權以存取 Windows Vista 和更新版本中的性能計數器,請將您自己新增至性能監視器使用者群組。
在 Windows Vista 和更新版本中,用戶帳戶控制 (UAC) 會決定用戶的許可權。 如果你是內建管理員群組的成員,你會被分配兩個執行時存取權杖:一個標準使用者存取權杖和一個管理員存取權杖。 根據預設,您處於標準使用者角色。 要執行存取效能計數器的程式碼,你必須先將權限從標準使用者提升為管理員。 當您以滑鼠右鍵按下應用程式圖示,並指出您想要以系統管理員身分執行,即可啟動應用程式。
另請參閱
適用於
Create(String, String, CounterCreationDataCollection)
警告
This overload of PerformanceCounterCategory.Create has been deprecated. Use System.Diagnostics.PerformanceCounterCategory.Create(string categoryName, string categoryHelp, PerformanceCounterCategoryType categoryType, CounterCreationDataCollection counterData) instead.
警告
This method has been deprecated. Please use System.Diagnostics.PerformanceCounterCategory.Create(string categoryName, string categoryHelp, PerformanceCounterCategoryType categoryType, CounterCreationDataCollection counterData) instead. http://go.microsoft.com/fwlink/?linkid=14202
警告
This method has been deprecated. Please use System.Diagnostics.PerformanceCounterCategory.Create(string categoryName, string categoryHelp, PerformanceCounterCategoryType categoryType, CounterCreationDataCollection counterData) instead. https://go.microsoft.com/fwlink/?linkid=14202
登錄本地電腦中包含指定計數器的自訂效能計數器類別。
public:
static System::Diagnostics::PerformanceCounterCategory ^ Create(System::String ^ categoryName, System::String ^ categoryHelp, System::Diagnostics::CounterCreationDataCollection ^ counterData);
[System.Obsolete("This overload of PerformanceCounterCategory.Create has been deprecated. Use System.Diagnostics.PerformanceCounterCategory.Create(string categoryName, string categoryHelp, PerformanceCounterCategoryType categoryType, CounterCreationDataCollection counterData) instead.")]
public static System.Diagnostics.PerformanceCounterCategory Create(string categoryName, string categoryHelp, System.Diagnostics.CounterCreationDataCollection counterData);
public static System.Diagnostics.PerformanceCounterCategory Create(string categoryName, string categoryHelp, System.Diagnostics.CounterCreationDataCollection counterData);
[System.Obsolete("This method has been deprecated. Please use System.Diagnostics.PerformanceCounterCategory.Create(string categoryName, string categoryHelp, PerformanceCounterCategoryType categoryType, CounterCreationDataCollection counterData) instead. http://go.microsoft.com/fwlink/?linkid=14202")]
public static System.Diagnostics.PerformanceCounterCategory Create(string categoryName, string categoryHelp, System.Diagnostics.CounterCreationDataCollection counterData);
[System.Obsolete("This method has been deprecated. Please use System.Diagnostics.PerformanceCounterCategory.Create(string categoryName, string categoryHelp, PerformanceCounterCategoryType categoryType, CounterCreationDataCollection counterData) instead. https://go.microsoft.com/fwlink/?linkid=14202")]
public static System.Diagnostics.PerformanceCounterCategory Create(string categoryName, string categoryHelp, System.Diagnostics.CounterCreationDataCollection counterData);
[<System.Obsolete("This overload of PerformanceCounterCategory.Create has been deprecated. Use System.Diagnostics.PerformanceCounterCategory.Create(string categoryName, string categoryHelp, PerformanceCounterCategoryType categoryType, CounterCreationDataCollection counterData) instead.")>]
static member Create : string * string * System.Diagnostics.CounterCreationDataCollection -> System.Diagnostics.PerformanceCounterCategory
static member Create : string * string * System.Diagnostics.CounterCreationDataCollection -> System.Diagnostics.PerformanceCounterCategory
[<System.Obsolete("This method has been deprecated. Please use System.Diagnostics.PerformanceCounterCategory.Create(string categoryName, string categoryHelp, PerformanceCounterCategoryType categoryType, CounterCreationDataCollection counterData) instead. http://go.microsoft.com/fwlink/?linkid=14202")>]
static member Create : string * string * System.Diagnostics.CounterCreationDataCollection -> System.Diagnostics.PerformanceCounterCategory
[<System.Obsolete("This method has been deprecated. Please use System.Diagnostics.PerformanceCounterCategory.Create(string categoryName, string categoryHelp, PerformanceCounterCategoryType categoryType, CounterCreationDataCollection counterData) instead. https://go.microsoft.com/fwlink/?linkid=14202")>]
static member Create : string * string * System.Diagnostics.CounterCreationDataCollection -> System.Diagnostics.PerformanceCounterCategory
Public Shared Function Create (categoryName As String, categoryHelp As String, counterData As CounterCreationDataCollection) As PerformanceCounterCategory
參數
- categoryName
- String
自訂效能計數器類別的名稱,用於建立並註冊系統。
- categoryHelp
- String
自訂類別的說明。
- counterData
- CounterCreationDataCollection
A CounterCreationDataCollection 指明新類別中要創建的計數器。
傳回
PerformanceCounterCategory A 與新的自訂類別或效能物件相關聯。
- 屬性
例外狀況
參數 categoryName 為 null。
該類別已存在於本地電腦中。
-或-
集合的配置 counterData 對基地棋子來說是不正確的。 一個型AverageCount64別為 、 AverageTimer32、 CounterMultiTimerCounterMultiTimerInverse、 CounterMultiTimer100NsCounterMultiTimer100NsInverseRawFraction或 SampleFractionSampleCounter 的計數器後面必須緊接著其中一個基本計數器類型(AverageBase, MultiBaseRawBase或)。SampleBase
基礎系統 API 的呼叫失敗。
未取得管理權限執行的程式碼嘗試讀取效能計數器。
備註
Note
要讀取 Windows Vista 及以後版本、Windows XP Professional x64 版或 Windows Server 2003 中非互動式登入會話的效能計數器,您必須是效能監控使用者群組的成員或擁有管理員權限。
若要避免提高許可權以存取 Windows Vista 和更新版本中的性能計數器,請將您自己新增至性能監視器使用者群組。
在 Windows Vista 和更新版本中,用戶帳戶控制 (UAC) 會決定用戶的許可權。 如果你是內建管理員群組的成員,你會被分配兩個執行時存取權杖:一個標準使用者存取權杖和一個管理員存取權杖。 根據預設,您處於標準使用者角色。 要執行存取效能計數器的程式碼,你必須先將權限從標準使用者提升為管理員。 當您以滑鼠右鍵按下應用程式圖示,並指出您想要以系統管理員身分執行,即可啟動應用程式。
另請參閱
適用於
Create(String, String, PerformanceCounterCategoryType, CounterCreationDataCollection)
登錄本地電腦中包含指定計數器的自訂效能計數器類別。
public:
static System::Diagnostics::PerformanceCounterCategory ^ Create(System::String ^ categoryName, System::String ^ categoryHelp, System::Diagnostics::PerformanceCounterCategoryType categoryType, System::Diagnostics::CounterCreationDataCollection ^ counterData);
public static System.Diagnostics.PerformanceCounterCategory Create(string categoryName, string categoryHelp, System.Diagnostics.PerformanceCounterCategoryType categoryType, System.Diagnostics.CounterCreationDataCollection counterData);
static member Create : string * string * System.Diagnostics.PerformanceCounterCategoryType * System.Diagnostics.CounterCreationDataCollection -> System.Diagnostics.PerformanceCounterCategory
Public Shared Function Create (categoryName As String, categoryHelp As String, categoryType As PerformanceCounterCategoryType, counterData As CounterCreationDataCollection) As PerformanceCounterCategory
參數
- categoryName
- String
自訂效能計數器類別的名稱,用於建立並註冊系統。
- categoryHelp
- String
自訂類別的說明。
- categoryType
- PerformanceCounterCategoryType
這是其中一項 PerformanceCounterCategoryType 價值。
- counterData
- CounterCreationDataCollection
A CounterCreationDataCollection 指明新類別中要創建的計數器。
傳回
PerformanceCounterCategory A 與新的自訂類別或效能物件相關聯。
例外狀況
categoryType 值不在以下值的範圍內: MultiInstance、、 SingleInstance或 Unknown。
該類別已存在於本地電腦中。
-或-
集合的配置 counterData 對基地棋子來說是不正確的。 一個型別AverageCount64為 、 AverageTimer32、 CounterMultiTimerCounterMultiTimerInverse、 CounterMultiTimer100NsCounterMultiTimer100NsInverseRawFractionSampleFraction或 SampleCounter 的計數器必須緊接著其中一個基本計數器類型(AverageBase, , MultiBaseRawBase, SampleBase, 或)。
基礎系統 API 的呼叫失敗。
未取得管理權限執行的程式碼嘗試讀取效能計數器。
範例
以下程式碼範例展示了該 Create 方法的使用方式。 範例展示了如何建立一個自訂的多實例效能計數器類別,以每秒訂單數為基準。
CounterCreationData data1 = new CounterCreationData("Trucks",
"Number of orders", PerformanceCounterType.NumberOfItems32);
CounterCreationData data2 = new CounterCreationData("Rate of sales",
"Orders/second", PerformanceCounterType.RateOfCountsPerSecond32);
CounterCreationDataCollection ccds = new CounterCreationDataCollection();
ccds.Add(data1);
ccds.Add(data2);
Console.WriteLine("Creating Orders custom counter.");
if (!PerformanceCounterCategory.Exists("Orders"))
PerformanceCounterCategory.Create("Orders",
"Processed orders",
PerformanceCounterCategoryType.MultiInstance,
ccds);
Dim data1 As New CounterCreationData("Trucks", "Number of orders", PerformanceCounterType.NumberOfItems32)
Dim data2 As New CounterCreationData("Rate of sales", "Orders/second", PerformanceCounterType.RateOfCountsPerSecond32)
Dim ccds As New CounterCreationDataCollection()
ccds.Add(data1)
ccds.Add(data2)
Console.WriteLine("Creating Orders custom counter.")
If Not PerformanceCounterCategory.Exists("Orders") Then
PerformanceCounterCategory.Create("Orders", "Processed orders", PerformanceCounterCategoryType.MultiInstance, ccds)
End If
備註
參數 categoryType 指定效能計數器類別是單一實例還是多實例。 預設情況下,類別在建立時為單一實例,新增實例後則為多實例。 類別會在應用程式設定時建立,實例則在執行時加入。 列 PerformanceCounterCategoryType 舉用來表示效能計數器是否可以有多個實例。
安裝於 .NET 的效能計數器類別會使用獨立的共享記憶體,每個效能計數器類別都有自己的記憶體。 你可以在登錄檔鍵 HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\<類別名稱>\效能中建立名為 FileMappingSize 的 DWORD 來指定獨立共享記憶體的大小。 FileMappingSize 值設為該類別的共享記憶體大小。 預設大小為131072小數。 若 FileMappingSize 值不存在,則 fileMappingSize 會使用 Machine.config 檔案中指定的屬性值 performanceCounters ,這會增加組態檔案處理的額外負擔。 你可以透過在登錄檔設定檔案映射大小來實現應用程式啟動效能的提升。
Note
強烈建議在應用程式安裝時建立新的效能計數器類別,而非執行時。 這讓作業系統有時間更新其註冊的效能計數器類別清單。 若清單未被刷新,嘗試使用該類別將失敗。
Note
要讀取 Windows Vista 及以後版本、Windows XP Professional x64 版或 Windows Server 2003 中非互動式登入會話的效能計數器,您必須是效能監控使用者群組的成員或擁有管理員權限。
若要避免提高許可權以存取 Windows Vista 和更新版本中的性能計數器,請將您自己新增至性能監視器使用者群組。
在 Windows Vista 和更新版本中,用戶帳戶控制 (UAC) 會決定用戶的許可權。 如果你是內建管理員群組的成員,你會被分配兩個執行時存取權杖:一個標準使用者存取權杖和一個管理員存取權杖。 根據預設,您處於標準使用者角色。 要執行存取效能計數器的程式碼,你必須先將權限從標準使用者提升為管理員。 當您以滑鼠右鍵按下應用程式圖示,並指出您想要以系統管理員身分執行,即可啟動應用程式。