Skip to content

Commit

Permalink
Add a reset graph option to the contextual menus for the CPU, Memory,…
Browse files Browse the repository at this point in the history
… Network, and Disk graphs.
  • Loading branch information
mikepj committed Feb 7, 2020
1 parent d968d31 commit 13a3bbf
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 5 deletions.
1 change: 1 addition & 0 deletions Data Miners/XRGCPUMiner.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
- (NSInteger)calculateCPUUsageForCPUs:(processor_cpu_load_info_t *)lastCPUInfo count:(NSInteger)count;
- (NSInteger)getNumCPUs;
- (CGFloat)getLoadAverage;
- (void)reset;

- (void)setCurrentUptime;
- (void)setDataSize:(NSInteger)newNumSamples;
Expand Down
8 changes: 8 additions & 0 deletions Data Miners/XRGCPUMiner.m
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,14 @@ - (CGFloat)getLoadAverage {
return -1;
}

- (void)reset {
self.userValues = nil;
self.systemValues = nil;
self.niceValues = nil;

[self setDataSize:numSamples];
}

- (void)setCurrentUptime {
time_t currentTime;
time_t uptimeInSeconds = 0;
Expand Down
1 change: 1 addition & 0 deletions Data Miners/XRGMemoryMiner.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@

- (void)getLatestMemoryInfo;
- (void)setDataSize:(int)newNumSamples;
- (void)reset;

// actually kilobytes, not bytes - limited to 4TB with 32bit
- (NSUInteger)freeBytes;
Expand Down
8 changes: 8 additions & 0 deletions Data Miners/XRGMemoryMiner.m
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ - (void)setDataSize:(int)newNumSamples {
numSamples = newNumSamples;
}

- (void)reset {
values1 = nil;
values2 = nil;
values3 = nil;

[self setDataSize:numSamples];
}

- (void)getLatestMemoryInfo {
kern_return_t kr;
vm_statistics_data_t stats;
Expand Down
1 change: 1 addition & 0 deletions Data Miners/XRGNetMiner.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
- (CGFloat)maxBandwidth;
- (CGFloat)currentTX;
- (CGFloat)currentRX;
- (void)reset;

- (NSArray *)networkInterfaces;

Expand Down
8 changes: 8 additions & 0 deletions Data Miners/XRGNetMiner.m
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,14 @@ - (CGFloat)currentRX {
return [self.rxValues currentValue];
}

- (void)reset {
_rxValues = nil;
_txValues = nil;
_totalValues = nil;

[self setDataSize:self.numSamples];
}

- (void)setCurrentBandwidth {
i_net.bytes = i_net.bytes_delta = 0;
o_net.bytes = o_net.bytes_delta = 0;
Expand Down
11 changes: 10 additions & 1 deletion Graph Views/XRGCPUView.m
Original file line number Diff line number Diff line change
Expand Up @@ -379,13 +379,18 @@ - (NSMenu *)menuForEvent:(NSEvent *)theEvent {

[myMenu addItem:[NSMenuItem separatorItem]];

tMI = [[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:@"Open Activity Monitor..." action:@selector(openActivityMonitor:) keyEquivalent:@""];
tMI = [[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:@"Reset Graph" action:@selector(clearData:) keyEquivalent:@""];
[myMenu addItem:tMI];

[myMenu addItem:[NSMenuItem separatorItem]];

tMI = [[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:@"Open Activity Monitor..." action:@selector(openActivityMonitor:) keyEquivalent:@""];
[myMenu addItem:tMI];

tMI = [[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:@"Open XRG CPU Preferences..." action:@selector(openCPUPreferences:) keyEquivalent:@""];
[myMenu addItem:tMI];

[myMenu addItem:[NSMenuItem separatorItem]];

return myMenu;
}
Expand Down Expand Up @@ -417,6 +422,10 @@ - (void)openActivityMonitor:(NSEvent *)theEvent {
];
}

- (void)clearData:(NSEvent *)theEvent {
[CPUMiner reset];
}

- (BOOL) acceptsFirstMouse {
return YES;
}
Expand Down
14 changes: 12 additions & 2 deletions Graph Views/XRGDiskView.m
Original file line number Diff line number Diff line change
Expand Up @@ -424,11 +424,15 @@ - (int)convertHeight:(int) yComponent {

- (NSMenu *)menuForEvent:(NSEvent *)theEvent {
NSMenu *myMenu = [[NSMenu allocWithZone:[NSMenu menuZone]] initWithTitle:@"Disk View"];
NSMenuItem *tMI = [[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:@"Open Disk Utility..." action:@selector(openDiskUtility:) keyEquivalent:@""];

NSMenuItem *tMI = [[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:@"Reset Graph" action:@selector(clearData:) keyEquivalent:@""];
[myMenu addItem:tMI];

[myMenu addItem:[NSMenuItem separatorItem]];

tMI = [[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:@"Open Disk Utility..." action:@selector(openDiskUtility:) keyEquivalent:@""];
[myMenu addItem:tMI];

tMI = [[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:@"Open XRG Disk Preferences..." action:@selector(openDiskPreferences:) keyEquivalent:@""];
[myMenu addItem:tMI];

Expand All @@ -446,6 +450,12 @@ - (void)openDiskPreferences:(NSEvent *)theEvent {
[[parentWindow controller] showPrefsWithPanel:@"Disk"];
}

- (void)clearData:(NSEvent *)theEvent {
int width = numSamples;
[self setWidth:1];
[self setWidth:width];
}

- (BOOL)acceptsFirstMouse:(NSEvent *)theEvent {
return YES;
}
Expand Down
9 changes: 9 additions & 0 deletions Graph Views/XRGMemoryView.m
Original file line number Diff line number Diff line change
Expand Up @@ -285,13 +285,22 @@ - (NSMenu *)menuForEvent:(NSEvent *)theEvent {
}

[myMenu addItem:[NSMenuItem separatorItem]];

tMI = [[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:@"Reset Graph" action:@selector(clearData:) keyEquivalent:@""];
[myMenu addItem:tMI];

[myMenu addItem:[NSMenuItem separatorItem]];

tMI = [[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:@"Open XRG Memory Preferences..." action:@selector(openMemoryPreferences:) keyEquivalent:@""];
[myMenu addItem:tMI];

return myMenu;
}

- (void)clearData:(NSEvent *)theEvent {
[memoryMiner reset];
}

- (void)emptyEvent:(NSEvent *)theEvent {
}

Expand Down
11 changes: 9 additions & 2 deletions Graph Views/XRGNetView.m
Original file line number Diff line number Diff line change
Expand Up @@ -344,14 +344,17 @@ - (NSMenu *)menuForEvent:(NSEvent *)theEvent {

[myMenu addItem:[NSMenuItem separatorItem]];

tMI = [[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:@"Reset Graph" action:@selector(clearData:) keyEquivalent:@""];
[myMenu addItem:tMI];

[myMenu addItem:[NSMenuItem separatorItem]];

tMI = [[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:@"Open Network System Preferences..." action:@selector(openNetworkSystemPreferences:) keyEquivalent:@""];
[myMenu addItem:tMI];

tMI = [[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:@"Open Network Utility..." action:@selector(openNetworkUtility:) keyEquivalent:@""];
[myMenu addItem:tMI];

[myMenu addItem:[NSMenuItem separatorItem]];

tMI = [[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:@"Open XRG Network Preferences..." action:@selector(openNetworkPreferences:) keyEquivalent:@""];
[myMenu addItem:tMI];

Expand Down Expand Up @@ -379,6 +382,10 @@ - (void)openNetworkPreferences:(NSEvent *)theEvent {
[[parentWindow controller] showPrefsWithPanel:@"Network"];
}

- (void)clearData:(NSEvent *)theEvent {
[self.miner reset];
}

- (BOOL)acceptsFirstMouse:(NSEvent *)theEvent {
return YES;
}
Expand Down

0 comments on commit 13a3bbf

Please sign in to comment.