PC SOFT

PROFESSIONAL NEWSGROUPS
WINDEVWEBDEV and WINDEV Mobile

Home → WINDEV 2024 → Informations à récupérer en Windev !!??
Informations à récupérer en Windev !!??
Started by Jean-Michel, Oct., 12 2017 5:42 AM - 11 replies
Registered member
834 messages
Popularité : +13 (13 votes)
Posted on October, 12 2017 - 5:42 AM
Bonjour,

Est il possible et comment récupérer les informations suivantes en Windev ?

Température CPU
% utilisation CPU
% utilisation HD
% utilisation réseau
% des GPU

Merci,
J.Michel

--
Synchronize Systems International LTD
Développement d'outils de gestion

Environnements AS400 – Windows
Langages GAP III – CL – Visual Basic - Visual Adélia - Adélia - Windev
http://www.cashpower.fr/

Bangkok / Pattaya
Registered member
945 messages
Popularité : +102 (110 votes)
Posted on October, 12 2017 - 11:31 AM
bonjour
Pour la température du cpu en °C :
objLocator est un objet automation dynamique //"WbemScripting.SWbemLocator"
objService est un objet automation dynamique
Resultats est un objet automation dynamique
Propriétés est un objet automation dynamique

objLocator = allouer un objet automation "WbemScripting.SWbemLocator"
IF objLocator <> Null THEN
WHEN EXCEPTION IN
objService = objLocator>>ConnectServer(".","root\wmi")
IF objService <> Null THEN
objService>>Security_>>ImpersonationLevel = 3
Resultats = objService>>ExecQuery("SELECT * FROM MSAcpi_ThermalZoneTemperature")
IF Resultats <> Null THEN
IF Resultats>>Count > 0 THEN
POUR x=0 _TO_ Resultats>>Count-1
Propriétés = Resultats>>ItemIndex(x)>>Properties_
IF Propriétés <> Null
//-----see http://wutils.com/wmi/root/wmi/msacpi_thermalzonetemperature/#currenttemperature_properties
Trace((Propriétés>>Item("CurrentTemperature")>>Value/10)-273.15)
END
END
END
END
END
IF Propriétés <> Null THEN Libérer Propriétés
IF Resultats <> Null THEN Libérer Resultats
IF objService <> Null THEN Libérer objService
IF objLocator <> Null THEN Libérer objLocator
DO
Erreur("Erreur WMI", ExceptionInfo())
END
END
Registered member
945 messages
Popularité : +102 (110 votes)
Posted on October, 12 2017 - 1:22 PM
Pour le %CPU total, avec «System.Diagnostics» du .NET
CPU est un PerformanceCounter()
CPU.CategoryName = "Processor"
CPU.CounterName = "% Processor Time"
CPU.InstanceName = "_Total"
FOR i=1 _TO_ 100
Trace(CPU.NextValue())
END
Registered member
945 messages
Popularité : +102 (110 votes)
Posted on October, 12 2017 - 2:24 PM
pour le network avec ce bout de code utilisant .NET, vous devriez y arriver
ipProperties est un IPGlobalProperties dynamique
StatV4 est un IPGlobalStatistics dynamique
//
ipProperties = System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties()
IF ipProperties <> Null THEN
StatV4 = ipProperties.GetIPv4GlobalStatistics()
IF StatV4 <> Null THEN
Trace(StatV4.ReceivedPackets + TAB +...
StatV4.ReceivedPacketsDelivered + TAB +...
StatV4.ReceivedPacketsDiscarded + TAB +...
StatV4.ReceivedPacketsForwarded)
Libérer StatV4
END
Libérer ipProperties
END
Registered member
834 messages
Popularité : +13 (13 votes)
Posted on October, 12 2017 - 3:17 PM
Merci Philippe,
Quel talent !! :merci:

--
Synchronize Systems International LTD
Développement d'outils de gestion

Environnements AS400 – Windows
Langages GAP III – CL – Visual Basic - Visual Adélia - Adélia - Windev
http://www.cashpower.fr/

Bangkok / Pattaya
Registered member
945 messages
Popularité : +102 (110 votes)
Posted on October, 12 2017 - 5:21 PM
Pour %HDD
DiskRead est un PerformanceCounter()
DiskWrite est un PerformanceCounter()

DiskRead.CategoryName = "PhysicalDisk"
DiskRead.CounterName = "Disk Reads/sec"
DiskRead.InstanceName = "_Total"

DiskWrite.CategoryName = "PhysicalDisk"
DiskWrite.CounterName = "Disk Writes/sec"
DiskWrite.InstanceName = "_Total"

FOR i=1 _TO_ 100
Trace("Disk Reads/sec : " + DiskRead.NextValue())
Trace("Disk Writes/sec : " + DiskWrite.NextValue())
END
Registered member
945 messages
Popularité : +102 (110 votes)
Posted on October, 13 2017 - 2:21 PM
Bonjour,
Après quelques recherches il semblerait qu'il n'existe pas de méthode générique pour les GPU.
J'ai trouvé ce code en C++ pour NVIDIA (http://eliang.blogspot.sn/2011/05/getting-nvidia-gpu-usage-in-c.html)
que j'ai traduit tant bien que mal en WLangage...
// Références :
// http://eliang.blogspot.sn/2011/05/getting-nvidia-gpu-usage-in-c.html
// http://docs.nvidia.com/gameworks/content/gameworkslibrary/coresdk/nvapi/group__nvapifunctions.html
// https://github.com/openhardwaremonitor/openhardwaremonitor/blob/master/Hardware/Nvidia/NVAPI.cs
// http://docs.nvidia.com/gameworks/content/gameworkslibrary/coresdk/nvapi/nvapi_8h.html
// https://stackoverflow.com/questions/13291783/how-to-get-the-id-memory-address-of-dll-function/16497265#16497265
//----------

//constant // à faire plus tard
NVAPI_OK est un entier = 0
NVAPI_MAX_PHYSICAL_GPUS est un entier = 64
NVAPI_MAX_USAGES_PER_GPU est un entier = 34
//end

i est un entier
hndDll, resAPI est un entier système
dllName est une chaîne ANSI
NvAPI_GetErrorMessage, NvAPI_GetInterfaceVersionString, NvAPI_Initialize, NvAPI_EnumPhysicalGPUs, NvAPI_GPU_GetUsages est un entier système
gpuHandles est un tableau de NVAPI_MAX_PHYSICAL_GPUS entiers système
gpuUsages est un tableau de NVAPI_MAX_USAGES_PER_GPU entiers sans signe
InterfaceVersionString est une chaîne fixe sur 64
ErrorMessageString est une chaîne
gpuCount est un entier système = 0

//----- Chargement de la DLL nvapi.dll pour 32 bits ou nvapi64.dll pour du 64 bits
dllName = EnMode64bits() ? "nvapi64.dll" ELSE "nvapi.dll"
hndDll = ChargeDLL(dllName)
IF hndDll = 0 THEN
Erreur(chainecontruit("Chargement de la dll : %1, impossible !", dllName))
RETOUR
END

//----- nvapi_QueryInterface est une fonction utilisée pour récupérer l'adresse
//----- d'une fonction non exportée de la dll

//----- Fonction permettant d'obtenir la traduction en chaine d'un code erreur
NvAPI_GetErrorMessage = API(dllName, "nvapi_QueryInterface", 0x6C2D048C)
IF NvAPI_GetErrorMessage = 0 THEN
Erreur("Impossible de localiser la fonction : " + NvAPI_GetErrorMessage)
DéchargeDLL(hndDll)
RETOUR
END

//----- Test la récupération de la version
NvAPI_GetInterfaceVersionString = API(dllName, "nvapi_QueryInterface", 0x01053FA5)
IF NvAPI_GetInterfaceVersionString <> 0 THEN
resAPI = API(NvAPI_GetInterfaceVersionString, &InterfaceVersionString)
IF resAPI = NVAPI_OK THEN
Trace(InterfaceVersionString)
ELSE
AppelDLL32(NvAPI_GetErrorMessage, resAPI, &ErrorMessageString)
Erreur("Erreur : NvAPI_GetInterfaceVersionString", "Code : " + resAPI, ErrorMessageString)
DéchargeDLL(hndDll)
RETOUR
END
END

//----- usage
NvAPI_Initialize = API(dllName, "nvapi_QueryInterface", 0x0150E828)
NvAPI_EnumPhysicalGPUs = API(dllName, "nvapi_QueryInterface", 0xE5AC921F)
NvAPI_GPU_GetUsages = API(dllName, "nvapi_QueryInterface", 0x189A1FDF)
IF NvAPI_Initialize = 0x0 _OR_ NvAPI_EnumPhysicalGPUs = 0x0 _OR_ NvAPI_GPU_GetUsages = 0x0 THEN
Erreur("Erreur de récupération de l'adresse d'une des fonctions !")
DéchargeDLL(hndDll)
RETOUR
END

//----- Initialisation
IF API(NvAPI_Initialize) = NVAPI_OK THEN
resAPI = API(NvAPI_EnumPhysicalGPUs, &gpuHandles, &gpuCount)
//gpuHandle : array of physical GPU handles. Each handle represents a physical GPU present in the system.
//gpuCount : devrait contenir le nombre de GPU
IF resAPI = NVAPI_OK THEN
//-----Boucle pour le premier GPU (mon PC n'en a qu'un seul)
gpuUsages[1] = OUBinaire(NVAPI_MAX_USAGES_PER_GPU * 4, 0x10000)
FOR i=1 _TO_ 1000
resAPI = API(NvAPI_GPU_GetUsages, gpuHandles[1], &gpuUsages)
IF resAPI <> NVAPI_OK THEN
AppelDLL32(NvAPI_GetErrorMessage, resAPI, &ErrorMessageString)
Erreur("Erreur : NvAPI_GPU_GetUsages", "Code : " + resAPI, ErrorMessageString)
DéchargeDLL(hndDll)
RETOUR
END
Trace("Usage : " + gpuUsages[4])
Multitâche(75)
END
ELSE
AppelDLL32(NvAPI_GetErrorMessage, resAPI, &ErrorMessageString)
Erreur("Erreur : NvAPI_EnumPhysicalGPUs", "Code : " + resAPI, ErrorMessageString)
DéchargeDLL(hndDll)
RETOUR
END
END

DéchargeDLL(hndDll)
RETOUR
Registered member
834 messages
Popularité : +13 (13 votes)
Posted on October, 18 2017 - 10:50 AM
Philippe bonjour,
J'espère que vous verrez mon message :
Pour le %HDD, j'ai rajouté l'assemblage System (system.dll) au projet.
Grace à cela, le PerformanceCounter() est reconnu.

Je ne comprends pas la boucle que j'ai modifié pour ne pas afficher des résultats à zéro.
Je l'ai augmenté jusqu'à 1.000 et voici le résultat :




Pas de résultat au read car toujours égal à zéro.
Je ne comprends pas non plus ces chiffres !

J.Michel

--
Synchronize Systems International LTD
Développement d'outils de gestion

Environnements AS400 – Windows
Langages GAP III – CL – Visual Basic - Visual Adélia - Adélia - Windev
http://www.cashpower.fr/

Bangkok / Pattaya
Registered member
834 messages
Popularité : +13 (13 votes)
Posted on October, 18 2017 - 11:00 AM
Concernant le % CPU :




Comment se fait il que j'affiche 100%
Resultat non compris.
Merci pour vos explications.
J.Michel

--
Synchronize Systems International LTD
Développement d'outils de gestion

Environnements AS400 – Windows
Langages GAP III – CL – Visual Basic - Visual Adélia - Adélia - Windev
http://www.cashpower.fr/

Bangkok / Pattaya
Registered member
945 messages
Popularité : +102 (110 votes)
Posted on October, 18 2017 - 12:27 PM
Bonjour,
Voici mon code de test
//https://social.msdn.microsoft.com/Forums/en-US/37b8b63a-da32-4497-b570-3811a2255dee/how-to-get-disk-io-countersdisk-write-time-disk-read-time-using-cnet?forum=csharplanguage

DiskRead est un PerformanceCounter()
DiskWrite est un PerformanceCounter()

DiskRead.CategoryName = "Disque physique"
DiskRead.CounterName = "Lectures disque, octets/s"
DiskRead.InstanceName = "_Total"
ReadValue est un entier

DiskWrite.CategoryName = "Disque physique"
DiskWrite.CounterName = "Écritures disque, octets/s"
DiskWrite.InstanceName = "_Total"
WriteValue est un entier

LOOP
ReadValue = DiskRead.NextValue()
IF ReadValue <> 0 THEN Trace("Lectures disque, octets/s : " + ReadValue)

WriteValue = DiskWrite.NextValue()
IF WriteValue <> 0 THEN Trace("Écritures disque, octets/s : " + WriteValue)

Multitâche(-200)

END


et comme résultat



Registered member
834 messages
Popularité : +13 (13 votes)
Posted on October, 18 2017 - 3:03 PM
Je me suis déconnecté du réseau et du wifi.
Je continue à recevoir des paquets.......................??




;(

--
Synchronize Systems International LTD
Développement d'outils de gestion

Environnements AS400 – Windows
Langages GAP III – CL – Visual Basic - Visual Adélia - Adélia - Windev
http://www.cashpower.fr/

Bangkok / Pattaya
Posted on January, 24 2020 - 1:52 PM
Bonjour,

j'ai utilisé votre code pour l'utilisation du CPU mais je n'obtiens pas le même résultat que le moniteur Windows...
Comment interpréter le retour dans Windev?
Est ce lié au multi-coeurs?

Merci.