[BlueLeaf1336]> PROBLEMS> 探求其之壱>
| history | TOP |
2006/03/03:作成
| GetProcessTimes | TOP |
PlatformSDK でスレッドの情報を取得する API を見ていて、GetThreadTimes というものを見つけました。
function GetThreadTimes(
hThread: THandle; // Handle to the thread
var lpCreationTime, // the creation time of the thread
lpExitTime, // the exit time of the thread
lpKernelTime, // the amount of time ... in kernel mode
lpUserTime: TFileTime // the amount of time ... in user mode
): BOOL; stdcall;
Windows.pas の宣言と、Platform SDK の説明を合体させるとこんな感じでした。
ひょっとして!! GetProcessTimes ってあるんじゃ? ... ありました。
function GetProcessTimes(
hProcess: THandle; // Handle to the process
var lpCreationTime, // the creation time of the process
lpExitTime, // the exit time of the process
lpKernelTime, // the amount of time ... in kernel mode
lpUserTime: TFileTime // the amount of time ... in user mode
): BOOL; stdcall;
これ、タスクマネージャの「CPU時間」のことではないのか、と思って試してみると、まさにそのとおりのような感じでした。「これ」っていうのは、lpKernelTime でもなく、lpUserTime でもなく、lpKernelTime + lpUserTime ですが。
| ソースコード(擬似) | TOP |
var
ftCreation: TFileTime;
ftExitTime: TFileTime;
ftKernelTime: TFileTime;
ftUserTime: TFileTime;
//stCreation: TSystemTime;
//stExitTime: TSystemTime;
stKernelTime: TSystemTime;
stUserTime: TSystemTime;
//dtCreation: TDateTime;
//dtExitTime: TDateTime;
dtKernelTime: TDateTime;
dtUserTime: TDateTime;
begin
// CPU時間
dtKernelTime := 0;
dtUserTime := 0;
// hProcess = 調べたいプロセスのハンドル
GetProcessTimes(hProcess, ftCreation, ftExitTime, ftKernelTime, ftUserTime);
// システム日時に変換
//FileTimeToSystemTime(ftCreation, stCreation);
//FileTimeToSystemTime(ftExitTime, stExitTime);
FileTimeToSystemTime(ftKernelTime, stKernelTime);
FileTimeToSystemTime(ftUserTime, stUserTime);
// 日付型に変換
//dtCreation := SystemTimeToDateTime(stCreation);
//dtExitTime := SystemTimeToDateTime(stExitTime);
dtKernelTime := SystemTimeToDateTime(stKernelTime);
dtUserTime := SystemTimeToDateTime(stUserTime);
// -109205 は 多分時間の最小値(1601年ごろ)
DateUtils.SecondsBetween(dtKernelTime + dtUserTime, -109205 * 2)));
end;
| 進捗状況 | TOP |
20060303TaskMan.zip(214,650Bytes) ソースコードと実行ファイルです。
いまさらですが、こんな風に左のような画像を出してると、これが実行画面のように見えますが、実際はふにゃふにゃな画面です。念のため。
だんだんと速度が落ちてきました。今回なんざ解決したのは1つだけです。ゼロよりははるかにましですが。
| EOF | TOP |