Hi,
Is there any clause to recover the CPU charge during an action in my VP application ?
-
- VIP Member
- Posts: 1466
- Joined: 28 Feb 2000 0:01
I am not sure if I fully understand the question, but eh following can give you CPU usage times.
Code: Select all
Thread = thread::attach(multiThread_native::getCurrentThread()),
Thread:getTimes(CreationTime, ExitTime, KernelTime, UserTime),
Regards Thomas Linder Puls
PDC
PDC
-
- Active Member
- Posts: 40
- Joined: 23 Sep 2002 23:01
Hi Tonton,
I found on the web this sequence that you can enter as a command line :
wmic path Win32_Processor get LoadPercentage /every:1 /format:list
Il gives the load of each processor at regular intervals. You stop it pressing a key.
I suppose it is possible to launch such a command with the shell_native class ? I never used it, but if possible it is may be a way to answer at your question ...
I found on the web this sequence that you can enter as a command line :
wmic path Win32_Processor get LoadPercentage /every:1 /format:list
Il gives the load of each processor at regular intervals. You stop it pressing a key.
I suppose it is possible to launch such a command with the shell_native class ? I never used it, but if possible it is may be a way to answer at your question ...
Regards
Dominique Pannier
Dominique Pannier
-
- VIP Member
- Posts: 204
- Joined: 16 Oct 2001 23:01
-
- VIP Member
- Posts: 204
- Joined: 16 Oct 2001 23:01
Hi,
I try to reproduce this VP5 following code without success :Here is my VP 7 code :
I try to reproduce this VP5 following code without success :
Code: Select all
task_win_eh(_Win,e_Menu(id_test,_ShiftCtlAlt),0):-!,
Fic = "cpu.js",
si_creation(Fic),
existfile(Fic),
system(Fic,0,R),
msg_clear(),
write("Charge CPU = ",R," %"),nl,
!.
si_creation(Fic):-
not(existfile(Fic)),
list_to_string(["var objWMIService = GetObject(\"winmgmts://./root/cimv2\");",
"var colItems = objWMIService.ExecQuery(\"Select * from Win32_Processor\");",
"var objEnum = new Enumerator(colItems);",
"for(;!objEnum.atEnd();objEnum.moveNext())",
"{",
"var obj = objEnum.item();",
"var returnValue = obj.LoadPercentage;",
"}",
"WScript.Quit(returnValue);"],"\n",Contenu),
trap(file_str(Fic,Contenu),_,fail),
!.
si_creation(_).
Code: Select all
clauses
onFileNew(_Source, _MenuTag):-
mainExe::getFileName(Path,_),
Fic = "cpu.js",
Fic_js = fileName::setPath(Fic,Path),
if not(file::existFile(Fic)) then
S = outputStream_file::create(Fic_js,stream::ansi(ansi())),
L = ["var objWMIService = GetObject(\"winmgmts://./root/cimv2\");",
"var colItems = objWMIService.ExecQuery(\"Select * from Win32_Processor\");",
"var objEnum = new Enumerator(colItems);",
"for(;!objEnum.atEnd();objEnum.moveNext())",
"{",
"var obj = objEnum.item();",
"var returnValue = obj.LoadPercentage;",
"}",
"WScript.Quit(returnValue);"],
Contain = string::concatWithDelimiter(L,"\n"),
S:write(Contain),
S:close()
end if,
% platformSupport5x::system(Fic_js,0,R), % this code generate this error (*)
% R = exe_native::shellExecute(getVpiWindow(),"open",Fic_js,"","",0), % always return 42
% R = shell_native::shellExecute(getVpiWindow(),"open",Fic_js,"","",0), % always return 42
% R = shell_native::shellExecute(getVpiWindow(),"",Fic_js,"","",0), % always return 42
Exe = useExe::new(Fic_js),
Exe:setShowWindow(true),
Exe:run(),
appTerminate(Exe,R), % this code generate this error (**)
mf:clear(),
stdio::write("CPU charge = ",R),stdio::nl
.
predicates
appTerminate:(useExe,string Response) procedure(i,o).
clauses
appTerminate(Exe,R):-
programControl::sleep(1000),
if Exe:isActive() then
appTerminate(Exe,R)
else
if Respons = Exe:tryGetExitCode() then
R = toString(Respons)
else
R = "???"
end if
end if
.
(*) Exception: nativeCallException (com/visual-prolog/exception/common_exception)
Internal API function call failed
Predicate name = CreateProcess
userMessage =
API function name = CreateProcess
ErrorCode = 193
ErrorDescription =
raised() 2014/12/26 09:59:52
ThreadId=4400
What's wrong ?(**) Exception: nativeCallException (com/visual-prolog/exception/common_exception)
Internal API function call failed
Predicate name = CreateProcess
userMessage =
API function name = CreateProcess
ErrorCode = 193
ErrorDescription =
file = <<NULL>>
commandLine = d:\1travail\Prolog_7_3\Recup_charge_CPU\Exe\cpu.js
raised() 2014/12/26 10:02:30
ThreadId=2320
ClassInfo: com/visual-prolog/Application/useExe/useExe $JustDate: 2010-03-09 $$Revision: 56 $

-
- VIP Member
- Posts: 204
- Joined: 16 Oct 2001 23:01
Ok, I've found my mistake.
The following code works fine :
The following code works fine :
Code: Select all
Exe = useExe::new(string::concat("cmd /c",Fic_js)),