mirror of
https://git.rtems.org/rtems-libbsd/
synced 2025-05-13 15:59:52 +08:00
VMSTAT(8): Port to RTEMS
This commit is contained in:
parent
dba2dfc663
commit
c4e89a9125
@ -41,6 +41,12 @@ static char sccsid[] = "@(#)vmstat.c 8.1 (Berkeley) 6/6/93";
|
||||
#endif /* not lint */
|
||||
#endif
|
||||
|
||||
#ifdef __rtems__
|
||||
#define __need_getopt_newlib
|
||||
#include <getopt.h>
|
||||
#include <machine/rtems-bsd-program.h>
|
||||
#include <machine/rtems-bsd-commands.h>
|
||||
#endif /* __rtems__ */
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
@ -82,6 +88,7 @@ __FBSDID("$FreeBSD$");
|
||||
|
||||
#define VMSTAT_XO_VERSION "1"
|
||||
|
||||
#ifndef __rtems__
|
||||
static char da[] = "da";
|
||||
|
||||
static struct nlist namelist[] = {
|
||||
@ -141,6 +148,9 @@ static int Pflag;
|
||||
static int hflag;
|
||||
|
||||
static kvm_t *kd;
|
||||
#else /* __rtems__ */
|
||||
#define kd ((kvm_t *)0)
|
||||
#endif /* __rtems__ */
|
||||
|
||||
#define FORKSTAT 0x01
|
||||
#define INTRSTAT 0x02
|
||||
@ -151,6 +161,7 @@ static kvm_t *kd;
|
||||
#define ZMEMSTAT 0x40
|
||||
#define OBJSTAT 0x80
|
||||
|
||||
#ifndef __rtems__
|
||||
static void cpustats(void);
|
||||
static void pcpustats(int, u_long, int);
|
||||
static void devstats(void);
|
||||
@ -160,7 +171,9 @@ static void doobjstat(void);
|
||||
static void dosum(void);
|
||||
static void dovmstat(unsigned int, int);
|
||||
static void domemstat_malloc(void);
|
||||
#endif /* __rtems__ */
|
||||
static void domemstat_zone(void);
|
||||
#ifndef __rtems__
|
||||
static void kread(int, void *, size_t);
|
||||
static void kreado(int, void *, size_t, size_t);
|
||||
static char *kgetstr(const char *);
|
||||
@ -168,13 +181,30 @@ static void needhdr(int);
|
||||
static void needresize(int);
|
||||
static void doresize(void);
|
||||
static void printhdr(int, u_long);
|
||||
#endif /* __rtems__ */
|
||||
static void usage(void);
|
||||
|
||||
#ifndef __rtems__
|
||||
static long pct(long, long);
|
||||
static long long getuptime(void);
|
||||
|
||||
static char **getdrivedata(char **);
|
||||
#endif /* __rtems__ */
|
||||
|
||||
#ifdef __rtems__
|
||||
static int main(int , char *argv[]);
|
||||
|
||||
int
|
||||
rtems_bsd_command_vmstat(int argc, char *argv[])
|
||||
{
|
||||
int exit_code;
|
||||
|
||||
rtems_bsd_program_lock();
|
||||
exit_code = rtems_bsd_program_call_main("ping", main, argc, argv);
|
||||
rtems_bsd_program_unlock();
|
||||
return (exit_code);
|
||||
}
|
||||
#endif /* __rtems__ */
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
@ -182,13 +212,28 @@ main(int argc, char *argv[])
|
||||
unsigned int interval;
|
||||
float f;
|
||||
int reps;
|
||||
#ifndef __rtems__
|
||||
char *memf, *nlistf;
|
||||
char errbuf[_POSIX2_LINE_MAX];
|
||||
#endif /* __rtems__ */
|
||||
#ifdef __rtems__
|
||||
struct getopt_data getopt_data;
|
||||
memset(&getopt_data, 0, sizeof(getopt_data));
|
||||
#define optind getopt_data.optind
|
||||
#define optarg getopt_data.optarg
|
||||
#define opterr getopt_data.opterr
|
||||
#define optopt getopt_data.optopt
|
||||
#define getopt(argc, argv, opt) getopt_r(argc, argv, "+" opt, &getopt_data)
|
||||
#endif /* __rtems__ */
|
||||
|
||||
#ifndef __rtems__
|
||||
memf = nlistf = NULL;
|
||||
#endif /* __rtems__ */
|
||||
interval = reps = todo = 0;
|
||||
#ifndef __rtems__
|
||||
maxshowdevs = 2;
|
||||
hflag = isatty(1);
|
||||
#endif /* __rtems__ */
|
||||
|
||||
argc = xo_parse_args(argc, argv);
|
||||
if (argc < 0)
|
||||
@ -196,6 +241,7 @@ main(int argc, char *argv[])
|
||||
|
||||
while ((c = getopt(argc, argv, "ac:fhHiM:mN:n:oPp:stw:z")) != -1) {
|
||||
switch (c) {
|
||||
#ifndef __rtems__
|
||||
case 'a':
|
||||
aflag++;
|
||||
break;
|
||||
@ -255,6 +301,7 @@ main(int argc, char *argv[])
|
||||
f = atof(optarg);
|
||||
interval = f * 1000;
|
||||
break;
|
||||
#endif /* __rtems__ */
|
||||
case 'z':
|
||||
todo |= ZMEMSTAT;
|
||||
break;
|
||||
@ -270,6 +317,7 @@ main(int argc, char *argv[])
|
||||
if (todo == 0)
|
||||
todo = VMSTAT;
|
||||
|
||||
#ifndef __rtems__
|
||||
if (memf != NULL) {
|
||||
kd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY, errbuf);
|
||||
if (kd == NULL)
|
||||
@ -331,6 +379,7 @@ retry_nlist:
|
||||
|
||||
argv = getdrivedata(argv);
|
||||
}
|
||||
#endif /* __rtems__ */
|
||||
|
||||
if (*argv) {
|
||||
f = atof(*argv);
|
||||
@ -345,12 +394,15 @@ retry_nlist:
|
||||
} else if (reps)
|
||||
interval = 1 * 1000;
|
||||
|
||||
#ifndef __rtems__
|
||||
if (todo & FORKSTAT)
|
||||
doforkst();
|
||||
if (todo & MEMSTAT)
|
||||
domemstat_malloc();
|
||||
#endif /* __rtems__ */
|
||||
if (todo & ZMEMSTAT)
|
||||
domemstat_zone();
|
||||
#ifndef __rtems__
|
||||
if (todo & SUMSTAT)
|
||||
dosum();
|
||||
if (todo & OBJSTAT)
|
||||
@ -363,10 +415,12 @@ retry_nlist:
|
||||
dointr(interval, reps);
|
||||
if (todo & VMSTAT)
|
||||
dovmstat(interval, reps);
|
||||
#endif /* __rtems__ */
|
||||
xo_finish();
|
||||
exit(0);
|
||||
}
|
||||
|
||||
#ifndef __rtems__
|
||||
static int
|
||||
mysysctl(const char *name, void *oldp, size_t *oldlenp,
|
||||
void *newp, size_t newlen)
|
||||
@ -1487,6 +1541,7 @@ domemstat_malloc(void)
|
||||
xo_close_container("malloc-statistics");
|
||||
memstat_mtl_free(mtlp);
|
||||
}
|
||||
#endif /* __rtems__ */
|
||||
|
||||
static void
|
||||
domemstat_zone(void)
|
||||
@ -1494,7 +1549,9 @@ domemstat_zone(void)
|
||||
struct memory_type_list *mtlp;
|
||||
struct memory_type *mtp;
|
||||
char name[MEMTYPE_MAXNAME + 1];
|
||||
#ifndef __rtems__
|
||||
int error;
|
||||
#endif /* __rtems__ */
|
||||
|
||||
mtlp = memstat_mtl_alloc();
|
||||
if (mtlp == NULL) {
|
||||
@ -1508,6 +1565,7 @@ domemstat_zone(void)
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
#ifndef __rtems__
|
||||
if (memstat_kvm_uma(mtlp, kd) < 0) {
|
||||
error = memstat_mtl_geterror(mtlp);
|
||||
if (error == MEMSTAT_ERROR_KVM)
|
||||
@ -1517,6 +1575,10 @@ domemstat_zone(void)
|
||||
xo_warnx("memstat_kvm_uma: %s",
|
||||
memstat_strerror(error));
|
||||
}
|
||||
#else /* __rtems__ */
|
||||
xo_warn("memstat_kvm_uma");
|
||||
return;
|
||||
#endif /* __rtems__ */
|
||||
}
|
||||
xo_open_container("memory-zone-statistics");
|
||||
xo_emit("{T:/%-20s} {T:/%6s} {T:/%6s} {T:/%8s} {T:/%8s} {T:/%8s} "
|
||||
@ -1545,6 +1607,7 @@ domemstat_zone(void)
|
||||
xo_emit("\n");
|
||||
}
|
||||
|
||||
#ifndef __rtems__
|
||||
static void
|
||||
display_object(struct kinfo_vmobject *kvo)
|
||||
{
|
||||
@ -1719,6 +1782,7 @@ kgetstr(const char *strp)
|
||||
} while (ret[n++] != '\0');
|
||||
return (ret);
|
||||
}
|
||||
#endif /* __rtems__ */
|
||||
|
||||
static void
|
||||
usage(void)
|
||||
|
@ -77,6 +77,7 @@ def rtems(mm):
|
||||
'rtems/rtems-bsd-shell-route.c',
|
||||
'rtems/rtems-bsd-shell-sysctl.c',
|
||||
'rtems/rtems-bsd-shell-tcpdump.c',
|
||||
'rtems/rtems-bsd-shell-vmstat.c',
|
||||
'rtems/rtems-bsd-syscall-api.c',
|
||||
'rtems/rtems-kernel-assert.c',
|
||||
'rtems/rtems-kernel-autoconf.c',
|
||||
@ -2216,6 +2217,7 @@ def user_space(mm):
|
||||
'usr.bin/netstat/pfkey.c',
|
||||
'usr.bin/netstat/sctp.c',
|
||||
'usr.bin/netstat/unix.c',
|
||||
'usr.bin/vmstat/vmstat.c',
|
||||
],
|
||||
mm.generator['source'](['-DINET6', '-DINET'])
|
||||
)
|
||||
|
@ -446,7 +446,8 @@ def build(bld):
|
||||
'freebsd/usr.bin/netstat/pfkey.c',
|
||||
'freebsd/usr.bin/netstat/route.c',
|
||||
'freebsd/usr.bin/netstat/sctp.c',
|
||||
'freebsd/usr.bin/netstat/unix.c']
|
||||
'freebsd/usr.bin/netstat/unix.c',
|
||||
'freebsd/usr.bin/vmstat/vmstat.c']
|
||||
bld.objects(target = "objs01",
|
||||
features = "c",
|
||||
cflags = cflags,
|
||||
@ -1105,6 +1106,7 @@ def build(bld):
|
||||
'rtemsbsd/rtems/rtems-bsd-shell-route.c',
|
||||
'rtemsbsd/rtems/rtems-bsd-shell-sysctl.c',
|
||||
'rtemsbsd/rtems/rtems-bsd-shell-tcpdump.c',
|
||||
'rtemsbsd/rtems/rtems-bsd-shell-vmstat.c',
|
||||
'rtemsbsd/rtems/rtems-bsd-shell.c',
|
||||
'rtemsbsd/rtems/rtems-bsd-syscall-api.c',
|
||||
'rtemsbsd/rtems/rtems-kernel-assert.c',
|
||||
|
0
rtemsbsd/include/devstat.h
Normal file
0
rtemsbsd/include/devstat.h
Normal file
@ -7,7 +7,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2013-2014 embedded brains GmbH. All rights reserved.
|
||||
* Copyright (c) 2013, 2016 embedded brains GmbH. All rights reserved.
|
||||
*
|
||||
* embedded brains GmbH
|
||||
* Dornierstr. 4
|
||||
@ -64,6 +64,8 @@ int rtems_bsd_command_tcpdump(int argc, char **argv);
|
||||
|
||||
int rtems_bsd_command_sysctl(int argc, char **argv);
|
||||
|
||||
int rtems_bsd_command_vmstat(int argc, char **argv);
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif /* _RTEMS_BSD_MACHINE_RTEMS_BSD_COMMANDS_H_ */
|
||||
|
@ -41,6 +41,8 @@ extern rtems_shell_cmd_t rtems_shell_TCPDUMP_Command;
|
||||
|
||||
extern rtems_shell_cmd_t rtems_shell_SYSCTL_Command;
|
||||
|
||||
extern rtems_shell_cmd_t rtems_shell_VMSTAT_Command;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
40
rtemsbsd/rtems/rtems-bsd-shell-vmstat.c
Normal file
40
rtemsbsd/rtems/rtems-bsd-shell-vmstat.c
Normal file
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (c) 2016 embedded brains GmbH. All rights reserved.
|
||||
*
|
||||
* embedded brains GmbH
|
||||
* Dornierstr. 4
|
||||
* 82178 Puchheim
|
||||
* Germany
|
||||
* <rtems@embedded-brains.de>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <rtems/netcmds-config.h>
|
||||
#include <machine/rtems-bsd-commands.h>
|
||||
|
||||
rtems_shell_cmd_t rtems_shell_VMSTAT_Command = {
|
||||
.name = "vmstat",
|
||||
.usage = "vmstat [args]",
|
||||
.topic = "net",
|
||||
.command = rtems_bsd_command_vmstat
|
||||
};
|
@ -364,7 +364,8 @@ Init(rtems_task_argument arg)
|
||||
&rtems_shell_NETSTAT_Command, \
|
||||
&rtems_shell_IFCONFIG_Command, \
|
||||
&rtems_shell_TCPDUMP_Command, \
|
||||
&rtems_shell_SYSCTL_Command
|
||||
&rtems_shell_SYSCTL_Command, \
|
||||
&rtems_shell_VMSTAT_Command
|
||||
|
||||
#define CONFIGURE_SHELL_COMMAND_CPUUSE
|
||||
#define CONFIGURE_SHELL_COMMAND_PERIODUSE
|
||||
|
@ -205,7 +205,8 @@ early_initialization(void)
|
||||
&rtems_shell_ROUTE_Command, \
|
||||
&rtems_shell_NETSTAT_Command, \
|
||||
&rtems_shell_SYSCTL_Command, \
|
||||
&rtems_shell_IFCONFIG_Command
|
||||
&rtems_shell_IFCONFIG_Command, \
|
||||
&rtems_shell_VMSTAT_Command
|
||||
|
||||
#define CONFIGURE_SHELL_COMMAND_CPUUSE
|
||||
#define CONFIGURE_SHELL_COMMAND_PERIODUSE
|
||||
|
@ -15,7 +15,8 @@
|
||||
&rtems_shell_PING_Command, \
|
||||
&rtems_shell_ROUTE_Command, \
|
||||
&rtems_shell_NETSTAT_Command, \
|
||||
&rtems_shell_IFCONFIG_Command
|
||||
&rtems_shell_IFCONFIG_Command, \
|
||||
&rtems_shell_VMSTAT_Command
|
||||
|
||||
#include <rtems/shellconfig.h>
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user