Discussions related to Visual Prolog
User avatar
Tonton Luc
VIP Member
Posts: 204
Joined: 16 Oct 2001 23:01

CPU

Unread post by Tonton Luc »

Hi,

Is there any clause to recover the CPU charge during an action in my VP application ?
User avatar
Thomas Linder Puls
VIP Member
Posts: 1398
Joined: 28 Feb 2000 0:01

Unread post by Thomas Linder Puls »

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
dominique f pannier
Active Member
Posts: 40
Joined: 23 Sep 2002 23:01

Unread post by dominique f pannier »

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 ...
Regards
Dominique Pannier
User avatar
Tonton Luc
VIP Member
Posts: 204
Joined: 16 Oct 2001 23:01

Unread post by Tonton Luc »

Hi Dominique,

Exactly what I need.
Many thanks for your help.

For Thomas => now you understand better what I'm looking. Many thanks too.
User avatar
Tonton Luc
VIP Member
Posts: 204
Joined: 16 Oct 2001 23:01

Unread post by Tonton Luc »

Hi,

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(_).
Here is my VP 7 code :

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
(**) 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 $
What's wrong ? :shock:
User avatar
Tonton Luc
VIP Member
Posts: 204
Joined: 16 Oct 2001 23:01

Unread post by Tonton Luc »

Ok, I've found my mistake.
The following code works fine :

Code: Select all

Exe = useExe::new(string::concat("cmd /c",Fic_js)),
Post Reply