From b4aaa767ceb2b86b784027701daf611b38b19f46 Mon Sep 17 00:00:00 2001 From: Mike Piatek-Jimenez Date: Fri, 7 Feb 2020 08:07:51 -0500 Subject: [PATCH] Improved the reset graph code to happen at the XRGDataSet level. --- Data Miners/XRGCPUMiner.h | 6 +++--- Data Miners/XRGCPUMiner.m | 16 +++++++++++----- Data Miners/XRGMemoryMiner.m | 8 +++----- Data Miners/XRGNetMiner.m | 8 +++----- Data Miners/XRGTemperatureMiner.h | 4 ++-- Data Miners/XRGTemperatureMiner.m | 7 +++---- Graph Views/XRGDiskView.m | 8 +++++--- Utility/XRGDataSet.h | 1 + Utility/XRGDataSet.m | 6 ++++++ 9 files changed, 37 insertions(+), 27 deletions(-) diff --git a/Data Miners/XRGCPUMiner.h b/Data Miners/XRGCPUMiner.h index 25b939c..945be89 100644 --- a/Data Miners/XRGCPUMiner.h +++ b/Data Miners/XRGCPUMiner.h @@ -57,9 +57,9 @@ @property CGFloat currentLoadAverage; @property NSInteger *fastValues; -@property NSMutableArray *userValues; -@property NSMutableArray *systemValues; -@property NSMutableArray *niceValues; +@property NSMutableArray *userValues; +@property NSMutableArray *systemValues; +@property NSMutableArray *niceValues; - (void)graphUpdate:(NSTimer *)aTimer; - (void)fastUpdate:(NSTimer *)aTimer; diff --git a/Data Miners/XRGCPUMiner.m b/Data Miners/XRGCPUMiner.m index 2d057b8..e82ad3f 100644 --- a/Data Miners/XRGCPUMiner.m +++ b/Data Miners/XRGCPUMiner.m @@ -226,11 +226,17 @@ - (CGFloat)getLoadAverage { } - (void)reset { - self.userValues = nil; - self.systemValues = nil; - self.niceValues = nil; - - [self setDataSize:numSamples]; + for (XRGDataSet *set in self.userValues) { + [set reset]; + } + + for (XRGDataSet *set in self.systemValues) { + [set reset]; + } + + for (XRGDataSet *set in self.niceValues) { + [set reset]; + } } - (void)setCurrentUptime { diff --git a/Data Miners/XRGMemoryMiner.m b/Data Miners/XRGMemoryMiner.m index a480c17..4742d00 100644 --- a/Data Miners/XRGMemoryMiner.m +++ b/Data Miners/XRGMemoryMiner.m @@ -74,11 +74,9 @@ - (void)setDataSize:(int)newNumSamples { } - (void)reset { - values1 = nil; - values2 = nil; - values3 = nil; - - [self setDataSize:numSamples]; + [values1 reset]; + [values2 reset]; + [values3 reset]; } - (void)getLatestMemoryInfo { diff --git a/Data Miners/XRGNetMiner.m b/Data Miners/XRGNetMiner.m index 178f805..8fb26f6 100644 --- a/Data Miners/XRGNetMiner.m +++ b/Data Miners/XRGNetMiner.m @@ -153,11 +153,9 @@ - (CGFloat)currentRX { } - (void)reset { - _rxValues = nil; - _txValues = nil; - _totalValues = nil; - - [self setDataSize:self.numSamples]; + [self.rxValues reset]; + [self.txValues reset]; + [self.totalValues reset]; } - (void)setCurrentBandwidth { diff --git a/Data Miners/XRGTemperatureMiner.h b/Data Miners/XRGTemperatureMiner.h index 1e8728b..1a69d07 100644 --- a/Data Miners/XRGTemperatureMiner.h +++ b/Data Miners/XRGTemperatureMiner.h @@ -59,9 +59,9 @@ @private int numSamples; // for the XRGDataSets, number of samples to record. - NSMutableArray *locationKeysInOrder; // locations in certain order, returned by locationKeysInOrder, generated by regenerateLocationKeyOrder. + NSMutableArray *locationKeysInOrder; // locations in certain order, returned by locationKeysInOrder, generated by regenerateLocationKeyOrder. - NSMutableDictionary *sensorData; + NSMutableDictionary *sensorData; SMCSensors *smcSensors; } diff --git a/Data Miners/XRGTemperatureMiner.m b/Data Miners/XRGTemperatureMiner.m index 4501383..3a2d02e 100644 --- a/Data Miners/XRGTemperatureMiner.m +++ b/Data Miners/XRGTemperatureMiner.m @@ -59,10 +59,9 @@ - (instancetype)init { } - (void)reset { - int width = numSamples; - - [self setDataSize:0]; - [self setDataSize:width]; + for (NSDictionary *sensorValue in [sensorData allValues]) { + [sensorValue[GSDataSetKey] reset]; + } } - (int)numberOfCPUs { diff --git a/Graph Views/XRGDiskView.m b/Graph Views/XRGDiskView.m index 70a8988..e8d63b1 100644 --- a/Graph Views/XRGDiskView.m +++ b/Graph Views/XRGDiskView.m @@ -451,9 +451,11 @@ - (void)openDiskPreferences:(NSEvent *)theEvent { } - (void)clearData:(NSEvent *)theEvent { - int width = numSamples; - [self setWidth:1]; - [self setWidth:width]; + for (NSInteger i = 0; i < numSamples; i++) { + values[i] = 0; + readValues[i] = 0; + writeValues[i] = 0; + } } - (BOOL)acceptsFirstMouse:(NSEvent *)theEvent { diff --git a/Utility/XRGDataSet.h b/Utility/XRGDataSet.h index 12a0406..59814d7 100644 --- a/Utility/XRGDataSet.h +++ b/Utility/XRGDataSet.h @@ -42,6 +42,7 @@ - (CGFloat) currentValue; - (void) valuesInOrder:(CGFloat *)destinationArray; +- (void) reset; - (void) resize:(size_t)newNumValues; - (void) setNextValue:(CGFloat)nextVal; - (void) setAllValues:(CGFloat)value; diff --git a/Utility/XRGDataSet.m b/Utility/XRGDataSet.m index a14dc39..2300d96 100644 --- a/Utility/XRGDataSet.m +++ b/Utility/XRGDataSet.m @@ -99,6 +99,12 @@ - (void) valuesInOrder:(CGFloat *)destinationArray { } } +- (void) reset { + for (NSInteger i = 0; i < self.numValues; i++) { + _values[i] = 0; + } +} + - (void) resize:(size_t)newNumValues { if (newNumValues == 0) { self.min = 0;