系統管理員可能需要監視 Integration Service 套件執行大量資料複雜轉換的效能。 Microsoft .NET Framework 的 System.Diagnostics 命名空間提供的類別,可讓您使用現有的效能計數器以及建立專屬的效能計數器。
效能計數器會儲存應用程式效能資訊,可用以分析某段時間的軟體效能。 透過使用 [效能監視器] 工具,就可以在本機或是遠端監視效能計數器。 您可以將效能計數器值儲存在變數中,以供之後在封裝中的控制流程分支使用。
除了使用性能計數器,您也可以透過 FireProgress 對象的屬性Events引發 Dts 事件。
FireProgress 事件會將增加的進度與完成百分比資訊傳回 Integration Service 執行階段。
注意
如果您想要建立可更輕鬆地在多個封裝之間重複使用的工作,請考慮使用此指令碼工作範例中的程式碼做為自訂工作的起點。 如需詳細資訊,請參閱 開發自訂工作。
描述
下列範例會建立自訂效能計數器並遞增計數器。 首先,範例會判斷效能計數器是否已經存在。 如果尚未建立性能計數器,腳本會呼叫 Create 物件的 方法 PerformanceCounterCategory 來建立它。 在建立效能計數器之後,指令碼會遞增計數器。 最後,此範例會遵循不再需要時,在性能計數器上呼叫 Close 方法的最佳做法。
注意
建立新的效能計數器類別以及效能計數器需要系統管理權限。 另外,在建立新的類別與計數器之後,會保存在電腦上。
設定此指令碼工作範例
-
Imports在您的程式代碼中使用語句匯入 System.Diagnostics 命名空間。
範例程式碼
Public Sub Main()
Dim myCounter As PerformanceCounter
Try
'Create the performance counter if it does not already exist.
If Not _
PerformanceCounterCategory.Exists("TaskExample") Then
PerformanceCounterCategory.Create("TaskExample", _
"Task Performance Counter Example", "Iterations", _
"Number of times this task has been called.")
End If
'Initialize the performance counter.
myCounter = New PerformanceCounter("TaskExample", _
"Iterations", String.Empty, False)
'Increment the performance counter.
myCounter.Increment()
myCounter.Close()
Dts.TaskResult = ScriptResults.Success
Catch ex As Exception
Dts.Events.FireError(0, _
"Task Performance Counter Example", _
ex.Message & ControlChars.CrLf & ex.StackTrace, _
String.Empty, 0)
Dts.TaskResult = ScriptResults.Failure
End Try
End Sub
public class ScriptMain
{
public void Main()
{
PerformanceCounter myCounter;
try
{
//Create the performance counter if it does not already exist.
if (!PerformanceCounterCategory.Exists("TaskExample"))
{
PerformanceCounterCategory.Create("TaskExample", "Task Performance Counter Example", "Iterations", "Number of times this task has been called.");
}
//Initialize the performance counter.
myCounter = new PerformanceCounter("TaskExample", "Iterations", String.Empty, false);
//Increment the performance counter.
myCounter.Increment();
myCounter.Close();
Dts.TaskResult = (int)ScriptResults.Success;
}
catch (Exception ex)
{
Dts.Events.FireError(0, "Task Performance Counter Example", ex.Message + "\r" + ex.StackTrace, String.Empty, 0);
Dts.TaskResult = (int)ScriptResults.Failure;
}
Dts.TaskResult = (int)ScriptResults.Success;
}
使用 Integration Services 保持最新狀態
如需來自Microsoft的最新下載、文章、範例和影片,以及來自社群的所選解決方案,請流覽 MSDN 上的 Integration Services 頁面:
流覽 MSDN 上的 Integration Services 頁面
如需這些更新的自動通知,請訂閱頁面上可用的 RSS 摘要。