CPU
Posted: 19 Dec 2014 13:51
Hi,
Is there any clause to recover the CPU charge during an action in my VP application ?
Is there any clause to recover the CPU charge during an action in my VP application ?
Code: Select all
Thread = thread::attach(multiThread_native::getCurrentThread()),
Thread:getTimes(CreationTime, ExitTime, KernelTime, UserTime),
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 $
Code: Select all
Exe = useExe::new(string::concat("cmd /c",Fic_js)),