Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix Memory (#240)
* Fix Memory

Cast swapFree to integer to fix typeerror.

Fix total memory to use hw.realmem

Signed-off-by: Matthew Wener <[email protected]>
Signed-off-by: Matthew Wener <[email protected]>

* Prevent float in swapinfo and update tests for hw.realmem

Signed-off-by: Matthew Wener <[email protected]>
Signed-off-by: Matthew Wener <[email protected]>

* Update testGetMemoryNoSwapinfo to hw.realmem

Signed-off-by: Matthew Wener <[email protected]>
(cherry picked from commit 49952d2)
Signed-off-by: Daniel Kesselberg <[email protected]>
  • Loading branch information
Matthew Wener authored and kesselb committed Oct 4, 2020
commit b8bfc265e80b33561901cadbb2eed2b9423da486
4 changes: 2 additions & 2 deletions lib/OperatingSystems/FreeBSD.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ public function getMemory(): Memory {
$result = preg_match_all($pattern, $swapinfo, $matches);
if ($result === 1) {
$data->setSwapTotal((int)($matches['Avail'][0] / 1024));
$data->setSwapFree(($data->getSwapTotal() - (int)($matches['Used'][0]) / 1024));
$data->setSwapFree(($data->getSwapTotal() - (int)($matches['Used'][0] / 1024)));
}

unset($matches, $result);

try {
$meminfo = $this->executeCommand('/sbin/sysctl -n hw.physmem hw.pagesize vm.stats.vm.v_inactive_count vm.stats.vm.v_cache_count vm.stats.vm.v_free_count');
$meminfo = $this->executeCommand('/sbin/sysctl -n hw.realmem hw.pagesize vm.stats.vm.v_inactive_count vm.stats.vm.v_cache_count vm.stats.vm.v_free_count');
} catch (\RuntimeException $e) {
$meminfo = '';
}
Expand Down
4 changes: 2 additions & 2 deletions tests/lib/FreeBSDTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function testGetMemory(): void {
$this->os->method('executeCommand')
->willReturnMap([
['/usr/sbin/swapinfo -k', file_get_contents(__DIR__ . '/../data/freebsd_swapinfo')],
['/sbin/sysctl -n hw.physmem hw.pagesize vm.stats.vm.v_inactive_count vm.stats.vm.v_cache_count vm.stats.vm.v_free_count', file_get_contents(__DIR__ . '/../data/freebsd_meminfo')],
['/sbin/sysctl -n hw.realmem hw.pagesize vm.stats.vm.v_inactive_count vm.stats.vm.v_cache_count vm.stats.vm.v_free_count', file_get_contents(__DIR__ . '/../data/freebsd_meminfo')],
]);

$memory = $this->os->getMemory();
Expand All @@ -72,7 +72,7 @@ public function testGetMemoryNoSwapinfo(): void {
if ($command === '/usr/sbin/swapinfo -k') {
throw new \RuntimeException('No output for command: /usr/sbin/swapinfo');
}
if ($command === '/sbin/sysctl -n hw.physmem hw.pagesize vm.stats.vm.v_inactive_count vm.stats.vm.v_cache_count vm.stats.vm.v_free_count') {
if ($command === '/sbin/sysctl -n hw.realmem hw.pagesize vm.stats.vm.v_inactive_count vm.stats.vm.v_cache_count vm.stats.vm.v_free_count') {
return file_get_contents(__DIR__ . '/../data/freebsd_meminfo');
}
});
Expand Down