FreeNOS
SysInfo.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2015 Niek Linnenbank
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include <FreeNOS/User.h>
19#include <Timer.h>
20#include <CoreClient.h>
21#include <stdio.h>
22#include <stdlib.h>
23#include <fcntl.h>
24#include <sys/time.h>
25#include "SysInfo.h"
26
27SysInfo::SysInfo(int argc, char **argv)
28 : POSIXApplication(argc, argv)
29{
30 parser().setDescription("Print global system information");
31}
32
36
38{
39 const CoreClient coreClient;
40 Size numCores = 1U;
41 Timer::Info timer;
42 struct timeval tv;
43 struct timezone tz;
44
45 // Retrieve number of cores from the CoreServer
46 const Core::Result result = coreClient.getCoreCount(numCores);
47 if (result != Core::Success)
48 {
49 printf("failed to retrieve core count from CoreServer: %d\n",
50 (int) result);
51 return IOError;
52 }
53
54 // Retrieve scheduler timer info from the kernel
55 ProcessCtl(SELF, InfoTimer, (Address) &timer);
56 gettimeofday(&tv, &tz);
57
58 // Retrieve system information
59 const SystemInformation info;
60
61 // Print all information to standard output
62 printf("Memory Total: %u KB\r\n"
63 "Memory Available: %u KB\r\n"
64 "Processor Cores: %u\r\n"
65 "Timer: %l ticks (%u hertz)\r\n"
66 "Uptime: %l.%us\r\n",
67 info.memorySize / 1024,
68 info.memoryAvail / 1024,
69 numCores,
70 (u32) timer.ticks,
71 timer.frequency,
72 (u32) tv.tv_sec, tv.tv_usec);
73
74 // Done
75 return Success;
76}
Result
Result codes.
Definition Application.h:54
ArgumentParser & parser()
Get program arguments parser.
void setDescription(const String &desc)
Set program description.
CoreClient provides a simple interface to a CoreServer.
Definition CoreClient.h:41
Core::Result getCoreCount(Size &numCores) const
Get number of processor cores in the system.
POSIX-compatible application.
virtual Result exec()
Execute the application.
Definition SysInfo.cpp:37
virtual ~SysInfo()
Destructor.
Definition SysInfo.cpp:33
SysInfo(int argc, char **argv)
Constructor.
Definition SysInfo.cpp:27
#define SELF
Definition ProcessID.h:35
API::Result ProcessCtl(const ProcessID proc, const ProcessOperation op, const Address addr=0, const Address output=0)
Prototype for user applications.
Definition ProcessCtl.h:93
@ InfoTimer
Definition ProcessCtl.h:49
C int printf(const char *format,...)
Output a formatted string to standard output.
Definition printf.cpp:22
C int gettimeofday(struct timeval *tv, struct timezone *tz)
Get current time of day.
unsigned int u32
Unsigned 32-bit number.
Definition Types.h:53
unsigned long Address
A memory address.
Definition Types.h:131
unsigned int Size
Any sane size indicator cannot go negative.
Definition Types.h:128
Result
Result code for Actions.
Definition Core.h:48
@ Success
Definition Core.h:49
System information structure.
Definition SystemInfo.h:80
Size memorySize
Total and available memory in bytes.
Definition SystemInfo.h:102
Timer information structure.
Definition Timer.h:43
u32 ticks
Definition Timer.h:44
Size frequency
Definition Timer.h:45
Time value information.
Definition time.h:36
uint tv_usec
Microseconds.
Definition time.h:41
time_t tv_sec
Seconds.
Definition time.h:38
Time zone information.
Definition time.h:48