TestComplete的性能記錄方法(2)

發表于:2014-09-24來源:uml.org.cn作者:陳能技點擊數: 標簽:TestComplet
下面腳本則使用的是slAQtime對象來訪問AQTime: procedure TestAQtime; var p : array[0..2] of OleVariant; i, FileName : OleVariant; begin p[0] := slAQtime.P4_AllocationProfiler; // Allocati

  下面腳本則使用的是slAQtime對象來訪問AQTime:

procedure TestAQtime;
var
p : array[0..2] of OleVariant;
i, FileName : OleVariant;
begin
p[0] := slAQtime.P4_AllocationProfiler; // Allocation Profiler
p[1] := slAQtime.P4_CoverageProfiler; // Coverage Profiler
p[2] := slAQtime.P4_PerformanceProfiler; // Performance Profiler

// Opens your application in AQtime
FileName := 'C:\MyProjects\MyApplication\MyApp_exe.aqt';
slAQtime.SetAQtimeProject(FileName);

for i := 0 to 2 do
begin
try
// Starts profiling in AQtime 4
slAQtime.RunAQtime4(p[i]);
{ To start profiling in other versions of AQtime,
use the following methods --
AQtime 3.x:
slAQtime.RunAQtime3(slAQtime.P3_VCLClassProfiler);
AQtime 2.x:
slAQtime.RunAQtime2(slAQtime.P2_VCLClassProfiler);
AQtime .NET Edition 1.2x:
slAQtime.RunAQtimeNET(slAQtime.PNET_StatisAnalysis); }
except
// Posts an exception message to the test log
Log.Error(ExceptionMessage);
end;

// Your code goes here...

// Wait until the profiling is over
// (we call RunAQtime4 method in a loop)
slAQtime.DoWaitFinish;
end;
end;

  通過調用操作系統的Perfmon對各種性能參數進行監控Perfmon是操作系統自帶的性能監控工具,它能通過添加各種計數器,對各種性能參數進行記錄。在TC中通過調用命令行的方式啟動和停止Perfmon。具體方法如下:

  首先在Perfmon中加名為perf_log的計數器日志,這里需要記錄的是記事本的相關資源使用情況:

  Process(NotePad): % Processor Time、Elapsed Time、Working Set

  然后在TestComplete中調用命令行方式操作Perfmon(注意Perfmon的命令行工具叫logman),通過設定logman的命令行運行參數來啟動(start perf_log)和停止(stop perf_log)Perfmon的計數器日志。

//開始記錄
TestedApps.logman.Params.SimpleParams.CommandLineParameters:='start perf_log';
TestedApps.logman.Run();

//添加你的操作

//結束記錄
TestedApps.logman.Params.SimpleParams.CommandLineParameters:='stop perf_log';
TestedApps.logman.Run();

  通過TC提供的秒表對象記錄時間

  TC的log里面會對每個GUI動作的時間進行記錄,但是記錄的是時刻,要后期計算才能得到每個GUI操作的消耗時間,而且有些非GUI的操作時間無法記錄,因此有必要尋找更精確、更方便的操作時間記錄方式,而TC本身就提供一個叫StopWatch的秒表對象,可以方便地記錄腳本的執行時間。

//Start開始計時
StopWatchObj := HISUtils.StopWatch;
StopWatchObj.Start();

//執行你的操作

// Stop結束計時,通過StopWatch的ToString方法直接獲取到經過的時間
StopWatchObj.Stop();
Log.Message('TimerRoutine finished.');
Log.Message('Execution time: ' + StopWatchObj.ToString());

原文轉自:http://www.uml.org.cn/Test/2007083122.asp

国产97人人超碰caoprom_尤物国产在线一区手机播放_精品国产一区二区三_色天使久久综合给合久久97