musage
This commit is contained in:
parent
9df293e371
commit
10eb77656b
3
Makefile
3
Makefile
|
@ -102,7 +102,8 @@ KernSources = kernel/ke/cpuid.c kernel/mm/paging.c \
|
|||
kernel/init/info.c kernel/init/ssp.c \
|
||||
kernel/ke/rtc.c kernel/io/keyb.c \
|
||||
kernel/io/spkr.c kernel/po/shtdwn.c \
|
||||
kernel/sh/shell.c kernel/sh/shcmds.c
|
||||
kernel/sh/shell.c kernel/sh/shcmds.c \
|
||||
kernel/sh/musage.c
|
||||
|
||||
KernObj=$(patsubst %.c,$(KOBJDIR)/%.o,$(KernSources))
|
||||
KernDep=$(patsubst %.c,$(KOBJDIR)/%.d,$(KernSources))
|
||||
|
|
|
@ -0,0 +1,138 @@
|
|||
//----------------------------------------------------------------------------//
|
||||
// GNU GPL OS/K //
|
||||
// //
|
||||
// Desc: Kernel shell //
|
||||
// //
|
||||
// //
|
||||
// Copyright © 2018-2019 The OS/K Team //
|
||||
// //
|
||||
// This file is part of OS/K. //
|
||||
// //
|
||||
// OS/K is free software: you can redistribute it and/or modify //
|
||||
// it under the terms of the GNU General Public License as published by //
|
||||
// the Free Software Foundation, either version 3 of the License, or //
|
||||
// any later version. //
|
||||
// //
|
||||
// OS/K is distributed in the hope that it will be useful, //
|
||||
// but WITHOUT ANY WARRANTY//without even the implied warranty of //
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||
// GNU General Public License for more details. //
|
||||
// //
|
||||
// You should have received a copy of the GNU General Public License //
|
||||
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
#include "shell.h"
|
||||
|
||||
error_t CmdMemUsage(int argc, char **argv, char *cmdline)
|
||||
{
|
||||
char var;
|
||||
(void)var;
|
||||
|
||||
size_t stack_cur;
|
||||
size_t img_diff, stack_diff;
|
||||
size_t heap_start, heap_end;
|
||||
size_t heap_diff, heap_max;
|
||||
|
||||
ulong flags = KePauseIRQs();
|
||||
|
||||
heap_start = (size_t)_heap_start;
|
||||
heap_end = (size_t)_heap_end;
|
||||
heap_max = _heap_max;
|
||||
|
||||
KeRestoreIRQs(flags);
|
||||
|
||||
img_diff = (size_t)BtLoaderInfo.kernelEndAddr
|
||||
- (size_t)BtLoaderInfo.kernelAddr;
|
||||
|
||||
stack_diff = (size_t)BtLoaderInfo.stackEndAddr
|
||||
- ((size_t)BtLoaderInfo.kernelEndAddr + 16);
|
||||
|
||||
heap_diff = (size_t)heap_end - (size_t)heap_start;
|
||||
|
||||
stack_cur = (size_t)BtLoaderInfo.stackEndAddr - (size_t)&var;
|
||||
|
||||
KernLog("Kernel image\n");
|
||||
|
||||
KernLog("\tstarts at:\t\t%p (%4luMB + %4luKB + %4luB)\n",
|
||||
BtLoaderInfo.kernelAddr,
|
||||
_ADDR_TO_MB((size_t)BtLoaderInfo.kernelAddr),
|
||||
_ADDR_TO_KB((size_t)BtLoaderInfo.kernelAddr),
|
||||
_ADDR_TO_B((size_t)BtLoaderInfo.kernelAddr));
|
||||
|
||||
KernLog("\tends at:\t\t%p (%4luMB + %4luKB + %4luB)\n",
|
||||
(size_t)BtLoaderInfo.kernelEndAddr,
|
||||
_ADDR_TO_MB((size_t)BtLoaderInfo.kernelEndAddr),
|
||||
_ADDR_TO_KB((size_t)BtLoaderInfo.kernelEndAddr),
|
||||
_ADDR_TO_B((size_t)BtLoaderInfo.kernelEndAddr));
|
||||
|
||||
KernLog("\tsize:\t\t\t%4luMB + %4luKB + %4luB (%p)\n",
|
||||
_ADDR_TO_MB(img_diff),
|
||||
_ADDR_TO_KB(img_diff),
|
||||
_ADDR_TO_B(img_diff),
|
||||
img_diff);
|
||||
|
||||
KernLog("Kernel stack\n");
|
||||
|
||||
KernLog("\tstarts at:\t\t%p (%4luMB + %4luKB + %4luB)\n",
|
||||
BtLoaderInfo.stackEndAddr,
|
||||
_ADDR_TO_MB((size_t)BtLoaderInfo.stackEndAddr),
|
||||
_ADDR_TO_KB((size_t)BtLoaderInfo.stackEndAddr),
|
||||
_ADDR_TO_B((size_t)BtLoaderInfo.stackEndAddr));
|
||||
|
||||
KernLog("\tcurrently at:\t%p (%4luMB + %4luKB + %4luB)\n",
|
||||
(size_t)&var,
|
||||
_ADDR_TO_MB((size_t)&var),
|
||||
_ADDR_TO_KB((size_t)&var),
|
||||
_ADDR_TO_B((size_t)&var));
|
||||
|
||||
KernLog("\tmin address:\t%p (%4luMB + %4luKB + %4luB)\n",
|
||||
(size_t)BtLoaderInfo.kernelEndAddr+16,
|
||||
_ADDR_TO_MB((size_t)BtLoaderInfo.kernelEndAddr+16),
|
||||
_ADDR_TO_KB((size_t)BtLoaderInfo.kernelEndAddr+16),
|
||||
_ADDR_TO_B((size_t)BtLoaderInfo.kernelEndAddr+16));
|
||||
|
||||
KernLog("\tsize (cur):\t\t%4luMB + %4luKB + %4luB (%p)\n",
|
||||
_ADDR_TO_MB(stack_cur),
|
||||
_ADDR_TO_KB(stack_cur),
|
||||
_ADDR_TO_B(stack_cur),
|
||||
stack_cur);
|
||||
|
||||
KernLog("\tsize (max):\t\t%4luMB + %4luKB + %4luB (%p)\n",
|
||||
_ADDR_TO_MB(stack_diff),
|
||||
_ADDR_TO_KB(stack_diff),
|
||||
_ADDR_TO_B(stack_diff),
|
||||
stack_diff);
|
||||
|
||||
KernLog("Kernel heap\n");
|
||||
|
||||
KernLog("\tstarts at:\t\t%p (%4luMB + %4luKB + %4luB)\n",
|
||||
heap_start, _ADDR_TO_MB(heap_start),
|
||||
_ADDR_TO_KB(heap_start),
|
||||
_ADDR_TO_B(heap_start));
|
||||
|
||||
KernLog("\tends at:\t\t%p (%4luMB + %4luKB + %4luB)\n",
|
||||
heap_end, _ADDR_TO_MB(heap_end),
|
||||
_ADDR_TO_KB(heap_end),
|
||||
_ADDR_TO_B(heap_end));
|
||||
|
||||
KernLog("\tmax addr:\t\t%p (%4luMB + %4luKB + %4luB)\n",
|
||||
heap_start + heap_max,
|
||||
_ADDR_TO_MB(heap_start + heap_max),
|
||||
_ADDR_TO_KB(heap_start + heap_max),
|
||||
_ADDR_TO_B(heap_start + heap_max));
|
||||
|
||||
KernLog("\tsize (cur):\t\t%4luMB + %4luKB + %4luB (%p)\n",
|
||||
_ADDR_TO_MB(heap_diff),
|
||||
_ADDR_TO_KB(heap_diff),
|
||||
_ADDR_TO_B(heap_diff),
|
||||
heap_diff);
|
||||
|
||||
KernLog("\tsize (max):\t\t%4luMB + %4luKB + %4luB (%p)\n",
|
||||
_ADDR_TO_MB(heap_max),
|
||||
_ADDR_TO_KB(heap_max),
|
||||
_ADDR_TO_B(heap_max),
|
||||
heap_max);
|
||||
|
||||
return EOK;
|
||||
}
|
|
@ -93,119 +93,6 @@ error_t CmdMemMap(int argc, char **argv, char *cmdline)
|
|||
return EOK;
|
||||
}
|
||||
|
||||
error_t CmdMemUsage(int argc, char **argv, char *cmdline)
|
||||
{
|
||||
char var;
|
||||
(void)var;
|
||||
|
||||
size_t stack_cur;
|
||||
size_t img_diff, stack_diff;
|
||||
size_t heap_start, heap_end;
|
||||
size_t heap_diff, heap_max;
|
||||
|
||||
ulong flags = KePauseIRQs();
|
||||
|
||||
heap_start = (size_t)_heap_start;
|
||||
heap_end = (size_t)_heap_end;
|
||||
heap_max = _heap_max;
|
||||
|
||||
KeRestoreIRQs(flags);
|
||||
|
||||
img_diff = (size_t)BtLoaderInfo.kernelEndAddr
|
||||
- (size_t)BtLoaderInfo.kernelAddr;
|
||||
|
||||
stack_diff = (size_t)BtLoaderInfo.stackEndAddr
|
||||
- ((size_t)BtLoaderInfo.kernelEndAddr + 16);
|
||||
|
||||
heap_diff = (size_t)heap_end - (size_t)heap_start;
|
||||
|
||||
stack_cur = (size_t)BtLoaderInfo.stackEndAddr - (size_t)&var;
|
||||
|
||||
KernLog("Kernel image\n");
|
||||
|
||||
KernLog("\tstarts at:\t\t%p (%4luMB + %4luKB + %4luB)\n",
|
||||
BtLoaderInfo.kernelAddr,
|
||||
_ADDR_TO_MB((size_t)BtLoaderInfo.kernelAddr),
|
||||
_ADDR_TO_KB((size_t)BtLoaderInfo.kernelAddr),
|
||||
_ADDR_TO_B((size_t)BtLoaderInfo.kernelAddr));
|
||||
|
||||
KernLog("\tends at:\t\t%p (%4luMB + %4luKB + %4luB)\n",
|
||||
(size_t)BtLoaderInfo.kernelEndAddr,
|
||||
_ADDR_TO_MB((size_t)BtLoaderInfo.kernelEndAddr),
|
||||
_ADDR_TO_KB((size_t)BtLoaderInfo.kernelEndAddr),
|
||||
_ADDR_TO_B((size_t)BtLoaderInfo.kernelEndAddr));
|
||||
|
||||
KernLog("\tsize:\t\t\t%4luMB + %4luKB + %4luB (%p)\n",
|
||||
_ADDR_TO_MB(img_diff),
|
||||
_ADDR_TO_KB(img_diff),
|
||||
_ADDR_TO_B(img_diff),
|
||||
img_diff);
|
||||
|
||||
KernLog("Kernel stack\n");
|
||||
|
||||
KernLog("\tstarts at:\t\t%p (%4luMB + %4luKB + %4luB)\n",
|
||||
BtLoaderInfo.stackEndAddr,
|
||||
_ADDR_TO_MB((size_t)BtLoaderInfo.stackEndAddr),
|
||||
_ADDR_TO_KB((size_t)BtLoaderInfo.stackEndAddr),
|
||||
_ADDR_TO_B((size_t)BtLoaderInfo.stackEndAddr));
|
||||
|
||||
KernLog("\tcurrently at:\t%p (%4luMB + %4luKB + %4luB)\n",
|
||||
(size_t)&var,
|
||||
_ADDR_TO_MB((size_t)&var),
|
||||
_ADDR_TO_KB((size_t)&var),
|
||||
_ADDR_TO_B((size_t)&var));
|
||||
|
||||
KernLog("\tmin address:\t%p (%4luMB + %4luKB + %4luB)\n",
|
||||
(size_t)BtLoaderInfo.kernelEndAddr+16,
|
||||
_ADDR_TO_MB((size_t)BtLoaderInfo.kernelEndAddr+16),
|
||||
_ADDR_TO_KB((size_t)BtLoaderInfo.kernelEndAddr+16),
|
||||
_ADDR_TO_B((size_t)BtLoaderInfo.kernelEndAddr+16));
|
||||
|
||||
KernLog("\tsize (cur):\t\t%4luMB + %4luKB + %4luB (%p)\n",
|
||||
_ADDR_TO_MB(stack_cur),
|
||||
_ADDR_TO_KB(stack_cur),
|
||||
_ADDR_TO_B(stack_cur),
|
||||
stack_cur);
|
||||
|
||||
KernLog("\tsize (max):\t\t%4luMB + %4luKB + %4luB (%p)\n",
|
||||
_ADDR_TO_MB(stack_diff),
|
||||
_ADDR_TO_KB(stack_diff),
|
||||
_ADDR_TO_B(stack_diff),
|
||||
stack_diff);
|
||||
|
||||
KernLog("Kernel heap\n");
|
||||
|
||||
KernLog("\tstarts at:\t\t%p (%4luMB + %4luKB + %4luB)\n",
|
||||
heap_start, _ADDR_TO_MB(heap_start),
|
||||
_ADDR_TO_KB(heap_start),
|
||||
_ADDR_TO_B(heap_start));
|
||||
|
||||
KernLog("\tends at:\t\t%p (%4luMB + %4luKB + %4luB)\n",
|
||||
heap_end, _ADDR_TO_MB(heap_end),
|
||||
_ADDR_TO_KB(heap_end),
|
||||
_ADDR_TO_B(heap_end));
|
||||
|
||||
KernLog("\tmax addr:\t\t%p (%4luMB + %4luKB + %4luB)\n",
|
||||
heap_start + heap_max,
|
||||
_ADDR_TO_MB(heap_start + heap_max),
|
||||
_ADDR_TO_KB(heap_start + heap_max),
|
||||
_ADDR_TO_B(heap_start + heap_max));
|
||||
|
||||
KernLog("\tsize (cur):\t\t%4luMB + %4luKB + %4luB (%p)\n",
|
||||
_ADDR_TO_MB(heap_diff),
|
||||
_ADDR_TO_KB(heap_diff),
|
||||
_ADDR_TO_B(heap_diff),
|
||||
heap_diff);
|
||||
|
||||
KernLog("\tsize (max):\t\t%4luMB + %4luKB + %4luB (%p)\n",
|
||||
_ADDR_TO_MB(heap_max),
|
||||
_ADDR_TO_KB(heap_max),
|
||||
_ADDR_TO_B(heap_max),
|
||||
heap_max);
|
||||
|
||||
return EOK;
|
||||
}
|
||||
|
||||
extern void pstest(void);
|
||||
|
||||
error_t CmdPsTest(int argc, char **argv, char *cmdline)
|
||||
|
@ -316,6 +203,8 @@ error_t CmdStackOverflow(int argc, char **argv, char *cmdline)
|
|||
return EOK;
|
||||
}
|
||||
|
||||
error_t CmdMemUsage(int argc, char **argv, char *cmdline);
|
||||
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
Command_t cmdtable[] =
|
||||
|
|
Loading…
Reference in New Issue