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 j As Byte
 Dim tb As TextBox
 
  ss = Split(File.Load("/proc/cpuinfo"), "\n")
  
  For j = 0 To ss.Max
    If ss[j] Begins "processor" Then
      With tb = New TextBox(Me)
        .W = 80
        .H = 30
        .X = 10
        .Y = 2 * (j + 1)
        .Alignment = Align.Right
      End With
      tt.Push(tb)
    Endif
  Next

  Me.H = tt[tt.Max].Y + 100

  For j = 0 To ss.Max
    If ss[j] Begins "cpu MHz" Then cc.Push(j)
  Next
  
  With Timer1 = New Timer As "Tempus"
    .Delay = 60
    .Start
  End With
     
End


Public Sub Tempus_Timer()

 Dim ss As New String[]
 Dim j As Byte
 
  ss = Split(File.Load("/proc/cpuinfo"), "\n")
  
  For j = 0 To cc.Max
    tt[j].Text = Scan(ss[cc[j]], "*:*")[1]
  Next

End