Win32OperatingSystem.st
changeset 10699 8fd653b16649
parent 10696 c9d6ce00235b
child 10701 b8c876510d1d
--- a/Win32OperatingSystem.st	Fri Sep 07 14:54:01 2007 +0200
+++ b/Win32OperatingSystem.st	Fri Sep 07 17:31:07 2007 +0200
@@ -57,29 +57,29 @@
 !
 
 Object subclass:#Abstract
-	instanceVariableNames:''
-	classVariableNames:'LastData LastTimestamp'
+	instanceVariableNames:'lastData lastTimestamp'
+	classVariableNames:''
 	poolDictionaries:''
 	privateIn:Win32OperatingSystem::PerformanceData
 !
 
-Win32OperatingSystem::PerformanceData::Abstract subclass:#ByIndexNumber
+Win32OperatingSystem::PerformanceData::Abstract subclass:#DiskIO
 	instanceVariableNames:''
-	classVariableNames:'AliveTime IndexNumber'
+	classVariableNames:'TheOneAndOnlyInstance'
 	poolDictionaries:''
 	privateIn:Win32OperatingSystem::PerformanceData
 !
 
 Win32OperatingSystem::PerformanceData::Abstract subclass:#Global
 	instanceVariableNames:''
-	classVariableNames:''
+	classVariableNames:'TheOneAndOnlyInstance'
 	poolDictionaries:''
 	privateIn:Win32OperatingSystem::PerformanceData
 !
 
 Win32OperatingSystem::PerformanceData::Abstract subclass:#Processor
 	instanceVariableNames:''
-	classVariableNames:''
+	classVariableNames:'TheOneAndOnlyInstance'
 	poolDictionaries:''
 	privateIn:Win32OperatingSystem::PerformanceData
 !
@@ -10339,16 +10339,16 @@
 
 !Win32OperatingSystem::PerformanceData class methodsFor:'accessing subclasses'!
 
-byIndexNumber
-    ^ ByIndexNumber
+diskIO
+    ^ DiskIO current
 !
 
 global
-    ^ Global
+    ^ Global current
 !
 
 processor
-    ^ Processor
+    ^ Processor current
 ! !
 
 !Win32OperatingSystem::PerformanceData class methodsFor:'documentation'!
@@ -10359,10 +10359,10 @@
         self helpIndexTextDictionary       
         self counterIndexTextDictionary    
 
-        self global data.                  
-        self processor data.        
-        self processor processorTimeFraction.  
-        self byIndexNumber indexNumber:230; data
+        self processor processorUsage.        
+        self processor interruptsPerSecond.  
+        self diskIO diskSpaceFreeInMegaByte.       
+        self diskIO diskTransfersPerSecond.     
     "
 ! !
 
@@ -10666,50 +10666,31 @@
     ^ self
 ! !
 
-!Win32OperatingSystem::PerformanceData::Abstract class methodsFor:'accessing'!
+!Win32OperatingSystem::PerformanceData::Abstract class methodsFor:'constants'!
+
+timedQueryMilliseconds
+    ^ 100
+! !
+
+!Win32OperatingSystem::PerformanceData::Abstract methodsFor:'accessing'!
 
 lastData
-    ^ LastData 
+    ^ lastData 
+!
+
+lastData:something
+    lastData := something.
 !
 
 lastTimestamp
-    ^ LastTimestamp 
-! !
-
-!Win32OperatingSystem::PerformanceData::Abstract class methodsFor:'actions'!
-
-getDataBasic
-    |regEntry|
-
-    regEntry := (Win32OperatingSystem registryEntry key:'HKEY_PERFORMANCE_DATA') valueNamed:self indexedName asString.
-
-    LastTimestamp := Timestamp now asMilliseconds.
-    LastData := Win32OperatingSystem::PerformanceData new fromRawBytes:regEntry.
-
-    ^ LastData
-! !
-
-!Win32OperatingSystem::PerformanceData::Abstract class methodsFor:'puplic'!
-
-data
-
-    self synchronized:[
-        |lastTS|
-
-        lastTS := self lastTimestamp.
-        lastTS isNil ifTrue:[
-            ^ self getDataBasic
-        ] ifFalse:[
-            Timestamp now asMilliseconds - lastTS >= self aliveTime ifTrue:[
-                ^ self getDataBasic
-            ] ifFalse:[
-                ^ self lastData
-            ].
-        ].
-    ].
-! !
-
-!Win32OperatingSystem::PerformanceData::Abstract class methodsFor:'queries'!
+    ^ lastTimestamp 
+!
+
+lastTimestamp:something
+    lastTimestamp := something.
+! !
+
+!Win32OperatingSystem::PerformanceData::Abstract methodsFor:'definitions'!
 
 aliveTime
 
@@ -10725,27 +10706,183 @@
     ^ self subclassResponsibility
 ! !
 
-!Win32OperatingSystem::PerformanceData::ByIndexNumber class methodsFor:'accessing'!
-
-aliveTime:something
-    AliveTime := something.
-!
-
-indexNumber:something
-    IndexNumber := something.
-! !
-
-!Win32OperatingSystem::PerformanceData::ByIndexNumber class methodsFor:'queries'!
+!Win32OperatingSystem::PerformanceData::Abstract methodsFor:'private'!
+
+data
+
+    self synchronized:[
+        |lastTS|
+
+        lastTS := self lastTimestamp.
+        lastTS isNil ifTrue:[
+            ^ self dataBasic
+        ] ifFalse:[
+            Timestamp now asMilliseconds - lastTS >= self aliveTime ifTrue:[
+                ^ self dataBasic
+            ] ifFalse:[
+                ^ self lastData
+            ].
+        ].
+    ].
+!
+
+dataBasic
+    |regEntry|
+
+    regEntry := (Win32OperatingSystem registryEntry key:'HKEY_PERFORMANCE_DATA') valueNamed:self indexedName asString.
+
+    self lastTimestamp:Timestamp now asMilliseconds.
+    self lastData:(Win32OperatingSystem::PerformanceData new fromRawBytes:regEntry).
+
+    ^ self lastData
+! !
+
+!Win32OperatingSystem::PerformanceData::Abstract methodsFor:'queries - timed'!
+
+getPerSecondViaPerforming:string
+    |result1 result2 runTimeInNS runTimeInS values1 values2 globalResult|
+
+    self assert:(self aliveTime < self class timedQueryMilliseconds).
+
+    result1 := self perform:string.
+    Delay waitForMilliseconds:self class timedQueryMilliseconds.
+    result2 := self perform:string.
+
+    runTimeInNS := ((result2 at:#time100nSec) - (result1 at:#time100nSec)) * 100.
+    runTimeInS := runTimeInNS / 1000 / 1000 / 1000.
+
+    values1 := result1 at:#values.
+    values2 := result2 at:#values.
+
+    globalResult := Dictionary new.
+
+    values2 keysDo:[:key|
+        |difference|
+
+        difference := (values2 at:key) - (values1 at:key).
+
+        globalResult at:key put:(difference / runTimeInS) asFloat.
+    ].
+
+    ^ globalResult
+! !
+
+!Win32OperatingSystem::PerformanceData::Abstract methodsFor:'queries - values'!
+
+getValuesByCounter:counterIndex 
+    ^ self getValuesByObject:0 counter:counterIndex timed:false
+!
+
+getValuesByCounter:counterIndex timed:boolean
+    ^ self getValuesByObject:0 counter:counterIndex timed:boolean
+!
+
+getValuesByObject:objectIndex counter:counterIndex 
+    ^ self getValuesByObject:0 counter:counterIndex timed:false
+!
+
+getValuesByObject:objectIndex counter:counterIndex timed:boolean
+    |data object counter values debugBlock|
+
+    debugBlock := [:obj|
+        ^ 'obj:', obj , ' this:', self printString , ' idx:', self indexedName
+    ].
+
+    data := self data.            
+
+    objectIndex == 0 ifTrue:[
+        object := data objectArray at:1 ifAbsent:[debugBlock value:(object at:#ObjectNameTitle)].        
+    ] ifFalse:[
+        object := data objectArray detect:[:el|(el at:#ObjectNameTitleIndex) == objectIndex] ifNone:[debugBlock value:(object at:#ObjectNameTitle)].        
+    ].
+
+    counter := (object at:#Counters) detect:[:aCounter|(aCounter at:#CounterNameTitleIndex) == counterIndex] ifNone:[debugBlock value:(object at:#ObjectNameTitle)].
+
+    values := Dictionary new.
+
+    1 to:(object at:#NumInstances) do:[:idx|
+        |value instanceName|
+
+        value := (counter at:#CounterValueArray) at:idx.
+        instanceName := ((object at:#Instances) at:idx) at:#Name.
+
+        values at:instanceName put:value.
+    ].
+
+    boolean ifTrue:[
+        |return|
+
+        return := IdentityDictionary new.
+        return at:#time put:data perfTime.
+        return at:#frequence put:data perfFreq.
+        return at:#time100nSec put:data perfTime100nSec.
+        return at:#values put:values.
+
+        ^ return
+    ].
+
+    ^ values
+! !
+
+!Win32OperatingSystem::PerformanceData::DiskIO class methodsFor:'accessing'!
+
+current
+
+    TheOneAndOnlyInstance isNil ifTrue:[
+        TheOneAndOnlyInstance := self new.
+    ].
+
+    ^ TheOneAndOnlyInstance
+! !
+
+!Win32OperatingSystem::PerformanceData::DiskIO methodsFor:'definition'!
 
 aliveTime
-    ^ AliveTime ? 100
+    ^ 80
 !
 
 indexedName
-    ^ IndexNumber 
-! !
-
-!Win32OperatingSystem::PerformanceData::Global class methodsFor:'queries'!
+    ^ '234'
+! !
+
+!Win32OperatingSystem::PerformanceData::DiskIO methodsFor:'queries'!
+
+diskSpaceFreeInMegaByte
+    ^ self getValuesByObject:236 counter:408 
+
+    "                             
+        self current diskSpaceFreeInMegaByte    
+    "
+!
+
+diskTransfers
+    ^ self getValuesByObject:236 counter:212 timed:true
+
+    "                             
+        self current diskTransfers                         
+    "
+!
+
+diskTransfersPerSecond
+    ^ self getPerSecondViaPerforming:#diskTransfers
+
+    "                             
+        self current diskTransfersPerSecond                         
+    "
+! !
+
+!Win32OperatingSystem::PerformanceData::Global class methodsFor:'accessing'!
+
+current
+
+    TheOneAndOnlyInstance isNil ifTrue:[
+        TheOneAndOnlyInstance := self new.
+    ].
+
+    ^ TheOneAndOnlyInstance
+! !
+
+!Win32OperatingSystem::PerformanceData::Global methodsFor:'definitions'!
 
 aliveTime
     ^ 200
@@ -10755,95 +10892,18 @@
     ^ 'Global'
 ! !
 
-!Win32OperatingSystem::PerformanceData::Processor class methodsFor:'puplic'!
-
-interruptsPerSecond
-
-    "
-        self interruptsPerSecond   
-    "
-
-    |p1 p2 index counter1 counter2 resultArray deltaTInNs deltaTInS cValueArray1 cValueArray2|
-
-    "alive time must be smaller than the used diff time, otherwise we cant calc sth"
-    self assert:(self aliveTime < 100).
-
-    p1 := self data.
-    Delay waitForMilliseconds:100.
-    p2 := self data.
-
-    index := (p1 objectArray first at:#Counters) findFirst:[:aCounter|(aCounter at:#CounterNameTitleIndex) = 148 "INTERRUPTS_INDEX"].
-    counter1 := (p1 objectArray first at:#Counters) at:index.
-    counter2 := (p2 objectArray first at:#Counters) at:index.
-
-    resultArray := OrderedCollection new.
-    deltaTInNs := (p2 perfTime100nSec - p1 perfTime100nSec) * 100.
-    deltaTInS := deltaTInNs / 1000 / 1000 / 1000.
-
-    cValueArray1 := counter1 at:#CounterValueArray.
-    cValueArray2 := counter2 at:#CounterValueArray.
-
-    1 to:cValueArray1 size do:[:idx|
-        |irqs irqsPerSecond|
-
-        irqs := (cValueArray2 at:idx) - (cValueArray1 at:idx).
-        irqsPerSecond := (irqs / deltaTInS) asFloat.
-
-        resultArray add:irqsPerSecond.
-    ].
-
-    ^ resultArray
-!
-
-processorTimeFraction
-
-    "
-        self processorTimeFraction
-    "
-
-    |p1 p2 index counter1 counter2 resultArray deltaTIn100Ns cValueArray1 cValueArray2|
-
-    "alive time must be smaller than the used diff time, otherwise we cant calc sth"
-    self assert:(self aliveTime < 100).
-
-    p1 := self data.
-    Delay waitForMilliseconds:100.
-    p2 := self data.
-
-    index := (p1 objectArray first at:#Counters) findFirst:[:aCounter|(aCounter at:#CounterNameTitleIndex) = 6].
-    counter1 := (p1 objectArray first at:#Counters) at:index.
-    counter2 := (p2 objectArray first at:#Counters) at:index.
-
-    resultArray := OrderedCollection new.
-    deltaTIn100Ns := (p2 perfTime100nSec - p1 perfTime100nSec).
-
-    cValueArray1 := counter1 at:#CounterValueArray.
-    cValueArray2 := counter2 at:#CounterValueArray.
-
-    1 to:cValueArray1 size do:[:idx|
-        |diff dPerSecond load1024|
-
-        diff := (cValueArray2 at:idx) - (cValueArray1 at:idx).
-        diff := diff bitShift:10.  
-
-        dPerSecond := (diff / deltaTIn100Ns) asFloat.
-        load1024 := 1024 - dPerSecond.
-
-        resultArray add:(load1024 / 1024 * 100).
-    ].
-
-    resultArray := resultArray collect:[:el|
-        |tmp|
-
-        tmp := el.
-        tmp < 0 ifTrue:[tmp := 0].
-        tmp
-    ].
-
-    ^ resultArray
-! !
-
-!Win32OperatingSystem::PerformanceData::Processor class methodsFor:'queries'!
+!Win32OperatingSystem::PerformanceData::Processor class methodsFor:'accessing'!
+
+current
+
+    TheOneAndOnlyInstance isNil ifTrue:[
+        TheOneAndOnlyInstance := self new.
+    ].
+
+    ^ TheOneAndOnlyInstance
+! !
+
+!Win32OperatingSystem::PerformanceData::Processor methodsFor:'definitions'!
 
 aliveTime
     ^ 80
@@ -10853,6 +10913,71 @@
     ^ '238'
 ! !
 
+!Win32OperatingSystem::PerformanceData::Processor methodsFor:'queries'!
+
+interrupts
+    ^ self getValuesByCounter:148 timed:true    
+
+    "
+        self current interrupts  
+    "
+!
+
+interruptsPerSecond
+    ^ self getPerSecondViaPerforming:#interrupts
+
+    "
+        self current interruptsPerSecond 
+    "
+!
+
+processorTime
+    ^ self getValuesByCounter:6 timed:true    
+
+    "
+        self current processorTime             
+    "
+!
+
+processorUsage
+
+    "
+        self current processorUsage                         
+    "
+
+    |result1 result2 deltaTIn100Ns value1 value2 globalResult|
+
+    self assert:(self aliveTime < self class timedQueryMilliseconds).
+
+    result1 := self processorTime.
+    Delay waitForMilliseconds:self class timedQueryMilliseconds.
+    result2 := self processorTime.
+
+    globalResult := Dictionary new.
+
+    deltaTIn100Ns := (result2 at:#time100nSec) - (result1 at:#time100nSec).
+
+    value1 := result1 at:#values.
+    value2 := result2 at:#values.
+
+    value1 keysDo:[:key|
+        |diff dPerSecond load1024 res|
+
+        diff := (value2 at:key) - (value1 at:key).
+        diff := diff bitShift:10.  
+
+        dPerSecond := (diff / deltaTIn100Ns) asFloat.
+        load1024 := 1024 - dPerSecond.
+
+        res := (load1024 / 1024 * 100) asFloat.
+        res < 0 ifTrue:[res := 0].
+
+        globalResult at:key put:res.
+    ].
+
+    ^ globalResult
+! !
+
 !Win32OperatingSystem::PrinterInfo2Structure methodsFor:'accessing'!
 
 defaultPriority
@@ -13684,7 +13809,7 @@
 !Win32OperatingSystem class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Win32OperatingSystem.st,v 1.296 2007-09-07 10:55:22 sr Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Win32OperatingSystem.st,v 1.297 2007-09-07 15:31:07 sr Exp $'
 ! !
 
 Win32OperatingSystem initialize!