[Gelöst][Autoit] CPU Cycles von Prozess ermitteln

War-10-ck

střelec
Teammitglied
Registriert
14 Juli 2013
Beiträge
5.689
Ort
Schießstand
Hallo,

jemand eine Idee wie man an den Wert kommt? Autoit wär prima, wenns irgendwie geht, dass ich den Wert anders bekomme und alles aus meinem Autoit Skript steuern kann is auch gut.

Genau den Wert (hier mal aus Process Explorer) ->
Neue Bitmap (2).jpg
 
Zuletzt bearbeitet:
  • Thread Starter Thread Starter
  • #3
Re: [Autoit] CPU Cycles von Prozess ermitteln

Das sollte schon gehen. Ich schätze mal . Ich steig nur gerade nicht ganz durch den Link durch den du mir geschickt hast, war da vorher auch schonmal drauf. Könntest du mir ein Beispielaufruf in Pseudocode geben? Wo muss ich da angeben von welchem Prozess ich die Cycles messen will?

Edit: Ah ich glaub so langsam steig ich durch wie das funktioniert.. Ich experimentier noch mal ein bissle.

--- Automatisch zusammengeführter Beitrag ---

Okay mein Aufruf schaut jetzt so aus:

PHP:
Expand Collapse Copy
Func _CalculateCPUCycle()
	Local $hWnd = ""
	Local $iPID = ProcessExists("notepad.exe")
	Local $aWinList = WinList()
	Local $nCycles

	For $i = 1 To $aWinList[0][0]
		If WinGetProcess($aWinList[$i][0]) = $iPID Then
			$hWnd = $aWinList[$i][1]
			ExitLoop
		EndIf
	Next

	If $hWnd <> "" Then
		$nCycles = DllCall("Kernel32.dll", "UINT64", "QueryProcessCycleTime", "HWND", $hWnd)
		MsgBox(1,"hhh", @error)
		ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $nCycles = ' & $nCycles & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console
	Else
		MsgBox(64,"Not Found", "No matching process found.")
	EndIf
EndFunc

Nach dem DLL-Aufruf bricht das Skript jedoch ab.
Folgende Errorausgabe:

Code:
Expand Collapse Copy
>Error code: 0
!>16:05:17 AutoIt3.exe ended.rc:-1073741819
>Exit code: -1073741819    Time: 5.323

Wo liegt der Fehler?

--- Automatisch zusammengeführter Beitrag ---

Okay, hat nun geklappt wenn auch nicht über Autoit selber. Ich hab ein kleines C# CommandLine-Tool geschrieben, das wird dann eben aus dem Autoit-Skript aufgerufen...
Wens noch interessiert heir der Code:

PHP:
Expand Collapse Copy
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace CPUCycles
{
    class Program
    {
        [DllImport("kernel32.dll")]
        [return: MarshalAs(UnmanagedType.Bool)]
        static extern bool QueryProcessCycleTime(IntPtr ProcessHandle, out ulong CycleTime);

        static void Main(string[] args)
        {
            IntPtr hwnd = ProcessExists("notepad");
            ulong cycles = 0;

            QueryProcessCycleTime(hwnd, out cycles);
            Console.WriteLine(cycles);
            Console.ReadLine();
        }

        public static IntPtr ProcessExists(string process)
        {
            IntPtr hwnd = new IntPtr(0);
           
            if (process.Contains(".exe"))
            {
                process = process.Replace(".exe", "");
            }

            Process[] processlist = Process.GetProcesses();
            foreach (Process theprocess in processlist)
            {
                if (theprocess.ProcessName.Contains(process))
                {
                    hwnd = theprocess.Handle;
                    return hwnd;
                }
            }
            return hwnd;
        }
    }
}

@drfuture: Danke für den Hinweis auf die DLL-Funktion! :)
 
Zuletzt bearbeitet:
Zurück
Oben