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 
27 SysInfo::SysInfo(int argc, char **argv)
28  : POSIXApplication(argc, argv)
29 {
30  parser().setDescription("Print global system information");
31 }
32 
34 {
35 }
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 }
CoreClient
CoreClient provides a simple interface to a CoreServer.
Definition: CoreClient.h:40
timezone
Time zone information.
Definition: time.h:47
SysInfo::SysInfo
SysInfo(int argc, char **argv)
Constructor.
Definition: SysInfo.cpp:27
fcntl.h
CoreClient.h
timeval::tv_usec
uint tv_usec
Microseconds.
Definition: time.h:41
POSIXApplication
POSIX-compatible application.
Definition: POSIXApplication.h:35
Address
unsigned long Address
A memory address.
Definition: Types.h:131
Application::Success
@ Success
Definition: Application.h:55
ArgumentParser::setDescription
void setDescription(const String &desc)
Set program description.
Definition: ArgumentParser.cpp:95
ProcessCtl
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
Timer::Info
Timer information structure.
Definition: Timer.h:42
time.h
Application::IOError
@ IOError
Definition: Application.h:57
SELF
#define SELF
Definition: ProcessID.h:35
InfoTimer
@ InfoTimer
Definition: ProcessCtl.h:49
SysInfo::exec
virtual Result exec()
Execute the application.
Definition: SysInfo.cpp:37
CoreClient::getCoreCount
Core::Result getCoreCount(Size &numCores) const
Get number of processor cores in the system.
Definition: CoreClient.cpp:39
gettimeofday
int gettimeofday(struct timeval *tv, struct timezone *tz)
Get current time of day.
Definition: gettimeofday.cpp:22
Timer.h
printf
int printf(const char *format,...)
Output a formatted string to standard output.
Definition: printf.cpp:22
SysInfo::~SysInfo
virtual ~SysInfo()
Destructor.
Definition: SysInfo.cpp:33
stdio.h
u32
unsigned int u32
Unsigned 32-bit number.
Definition: Types.h:53
Size
unsigned int Size
Any sane size indicator cannot go negative.
Definition: Types.h:128
Application::Result
Result
Result codes.
Definition: Application.h:53
SysInfo.h
timeval::tv_sec
time_t tv_sec
Seconds.
Definition: time.h:38
Core::Result
Result
Result code for Actions.
Definition: Core.h:47
timeval
Time value information.
Definition: time.h:35
Application::parser
ArgumentParser & parser()
Get program arguments parser.
Definition: Application.cpp:102
SystemInformation
System information structure.
Definition: SystemInfo.h:79
SystemInformation::memorySize
Size memorySize
Total and available memory in bytes.
Definition: SystemInfo.h:102
Core::Success
@ Success
Definition: Core.h:49
stdlib.h
SystemInformation::memoryAvail
Size memoryAvail
Definition: SystemInfo.h:102