Verificare la frequenza delle CPU con le sole risorse di Gambas
Da Gambas-it.org - Wikipedia.
E' possibile verificare con le sole risorse di Gambas la corrente frequenza di ciascuna CPU leggendo costantemente il file di sistema /proc/cpuinfo .
Mostriamo un possibile semplice codice in ambiente grafico:
Private Timer1 As Timer Private tt As New TextBox[] Private cc As New Short[] Public Sub Form_Open() Dim ss As New String[] Dim b As Byte Dim tb As TextBox ss = Split(File.Load("/proc/cpuinfo"), "\n") For b = 0 To ss.Max If ss[b] Begins "processor" Then With tb = New TextBox(Me) .W = 80 .H = 30 .X = 10 .Y = 2 * (b + 1) .Alignment = Align.Right End With tt.Push(tb) Endif Next Me.H = tt[tt.Max].Y + 100 For b = 0 To ss.Max If ss[b] Begins "cpu MHz" Then cc.Push(b) Next With Timer1 = New Timer As "Tempus" .Delay = 60 .Start End With End Public Sub Tempus_Timer() Dim ss As New String[] Dim b As Byte ss = Split(File.Load("/proc/cpuinfo"), "\n") For b = 0 To cc.Max tt[b].Text = Scan(ss[cc[b]], "*:*")[1] Next End
e un possibile semplice codice in applicazione "a riga di comando":
Private Timer1 As Timer Public Sub Main() With Timer1 = New Timer As "Timer1" .Delay = 60 .Start End With End Public Sub Timer1_Timer() Dim b As Byte Dim s As String s = "*MHz*: *\n*" Write "\r \e[31mCPU 1\e[0m " & Scan(File.Load("/proc/cpuinfo"), s)[2] For b = 2 To System.Cores s &= "MHz\x09\x09: *\n*" Write " ║ \e[31mCPU " & b & "\e[0m " & Scan(File.Load("/proc/cpuinfo"), s)[b * 2] Next Flush End