XINU
Functions | Variables
xsh_memstat.c File Reference
#include <xinu.h>
#include <stdio.h>
#include <string.h>
Include dependency graph for xsh_memstat.c:

Go to the source code of this file.

Functions

static void printFreeList (void)
 
static void printMemUse (void)
 
void start (void)
 
shellcmd xsh_memstat (int nargs, char *args[])
 

Variables

void * _end
 

Function Documentation

◆ printFreeList()

static void printFreeList ( void  )
static

Definition at line 50 of file xsh_memstat.c.

References _end, memlist, memblk::mlength, memblk::mnext, NULL, printf(), and start().

Referenced by xsh_memstat().

51 {
52  struct memblk *block;
53 
54  /* Output a heading for the free list */
55 
56  printf("Free List:\n");
57  printf("Block address Length (dec) Length (hex)\n");
58  printf("------------- ------------ ------------\n");
59 
60  for (block = memlist.mnext; block != NULL; block = block->mnext) {
61  printf(" 0x%08x %9d 0x%08x\n", block,
62  block->mlength, block->mlength);
63  }
64  printf("\n");
65 }
#define NULL
連結リスト用のNULLポインタ
Definition: kernel.h:68
メモリブロックを管理するための構造体。
Definition: memory.h:53
struct memblk * mnext
次のフリーメモリブロックへのポインタ
Definition: memory.h:56
int32 printf(const char *,...)
Definition: printf.c:13
struct memblk memlist
フリーメモリリストの先頭
Definition: initialize.c:27
uint32 mlength
memblk構造体のサイズを含むブロックサイズ
Definition: memory.h:58
Here is the call graph for this function:
Here is the caller graph for this function:

◆ printMemUse()

static void printMemUse ( void  )
static

Definition at line 74 of file xsh_memstat.c.

References _end, memlist, memblk::mlength, memblk::mnext, NPROC, NULL, PR_FREE, printf(), proctab, and start().

Referenced by xsh_memstat().

75 {
76  int i; /* Index into process table */
77  uint32 code = 0; /* Total Xinu code memory */
78  uint32 stack = 0; /* Total used stack memory */
79  uint32 kheap = 0; /* Free kernel heap memory */
80  uint32 kfree = 0; /* Total free memory */
81  struct memblk *block; /* Ptr to memory block */
82 
83  /* Calculate amount of text memory */
84 
85  code = (uint32)&_end - (uint32)start;
86 
87  /* Calculate amount of allocated stack memory */
88  /* Skip the NULL process since it has a private stack */
89 
90  for (i = 1; i < NPROC; i++) {
91  if (proctab[i].prstate != PR_FREE) {
92  stack += (uint32)proctab[i].prstklen;
93  }
94  }
95 
96  /* Calculate the amount of memory on the free list */
97 
98  for (block = memlist.mnext; block != NULL; block = block->mnext) {
99  kfree += block->mlength;
100  }
101 
102  /* Calculate the amount of free kernel heap memory */
103 
104  kheap = kfree - stack;
105 
106  /* Output statistics on current memory use */
107 
108  printf("Current system memory statistics:\n");
109  printf("---------------------------------\n");
110  printf("%10d bytes (0x%08x) of Xinu code\n", code, code);
111  printf("%10d bytes (0x%08x) of allocated stack space\n", stack, stack);
112  printf("%10d bytes (0x%08x) of available kernel heap space\n\n", kheap, kheap);
113 }
#define NULL
連結リスト用のNULLポインタ
Definition: kernel.h:68
メモリブロックを管理するための構造体。
Definition: memory.h:53
struct memblk * mnext
次のフリーメモリブロックへのポインタ
Definition: memory.h:56
int32 printf(const char *,...)
Definition: printf.c:13
struct memblk memlist
フリーメモリリストの先頭
Definition: initialize.c:27
#define NPROC
Definition: conf.h:79
void * _end
void start(void)
#define PR_FREE
プロセステーブルエントリが使用されていない状態。
Definition: process.h:35
uint32 mlength
memblk構造体のサイズを含むブロックサイズ
Definition: memory.h:58
struct procent proctab[]
プロセステーブル。
Definition: initialize.c:23
unsigned int uint32
符号なし32ビット整数(unsigned int)
Definition: kernel.h:15
Here is the call graph for this function:
Here is the caller graph for this function:

◆ start()

void start ( void  )

Referenced by printFreeList(), and printMemUse().

Here is the caller graph for this function:

◆ xsh_memstat()

shellcmd xsh_memstat ( int  nargs,
char *  args[] 
)

Definition at line 14 of file xsh_memstat.c.

References fprintf(), printf(), printFreeList(), printMemUse(), stderr, and strncmp().

15 {
16 
17  /* For argument '--help', emit help about the 'memstat' command */
18 
19  if (nargs == 2 && strncmp(args[1], "--help", 7) == 0) {
20  printf("use: %s \n\n", args[0]);
21  printf("Description:\n");
22  printf("\tDisplays the current memory use and prints the\n");
23  printf("\tfree list.\n");
24  printf("Options:\n");
25  printf("\t--help\t\tdisplay this help and exit\n");
26  return 0;
27  }
28 
29  /* Check for valid number of arguments */
30 
31  if (nargs > 1) {
32  fprintf(stderr, "%s: too many arguments\n", args[0]);
33  fprintf(stderr, "Try '%s --help' for more information\n",
34  args[0]);
35  return 1;
36  }
37 
38  printMemUse();
39  printFreeList();
40 
41  return 0;
42 }
int32 strncmp(const char *, const char *, int32)
static void printMemUse(void)
Definition: xsh_memstat.c:74
static void printFreeList(void)
Definition: xsh_memstat.c:50
#define stderr
Definition: stdio.h:17
int32 printf(const char *,...)
Definition: printf.c:13
int32 fprintf(int, char *,...)
Definition: fprintf.c:14
Here is the call graph for this function:

Variable Documentation

◆ _end

void* _end

Referenced by printFreeList(), and printMemUse().