Compare commits

..

4 Commits
v0.98 ... feat

Author SHA1 Message Date
Dr-Noob
2c4a2a0253 [v0.97] Automatically adjust text to the width of the terminal, as suggested by #65 2021-04-10 15:41:44 +02:00
Dr-Noob
61cd0783ac [v0.97] Make loop option work on ARM too 2021-04-10 14:33:45 +02:00
Dr-Noob
5242adf4ac [v0.97] Fix compilation in macOS 2021-04-10 13:34:28 +02:00
Dr-Noob
3a2b04de1e [v0.97] Add loop option as suggested by #75 2021-04-10 13:22:45 +02:00
15 changed files with 232 additions and 208 deletions

View File

@@ -1,51 +0,0 @@
# cpufetch contributing guidelines
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
- [Creating a pull request](#creating-a-pull-request)
- [Case 1: I found a bug in cpufetch](#case-1-i-found-a-bug-in-cpufetch)
- [Case 2: I have an idea for a new feature in cpufetch / I want to suggest a change in cpufetch](#case-2-i-have-an-idea-for-a-new-feature-in-cpufetch--i-want-to-suggest-a-change-in-cpufetch)
- [Case 3: I want to make changes to the Makefile](#case-3-i-want-to-make-changes-to-the-makefile)
- [Creating an issue](#creating-an-issue)
- [cpufetch fails / crashes with a segmentation fault / ends without any output](#cpufetch-fails--crashes-with-a-segmentation-fault--ends-without-any-output)
- [Option 1 (best)](#option-1-best)
- [Option 2 (use this option if you can't work with option 1)](#option-2-use-this-option-if-you-cant-work-with-option-1)
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
## Creating a pull request
Thanks for your interest in contributing to cpufetch!
What kind of contribution are you going to propose?
### Case 1: I found a bug in cpufetch
If you found a bug, please don't open a pull request; open an issue instead, even if you know the solution. I appreciate people finding bugs, but I generally prefer to fix them myself.
### Case 2: I have an idea for a new feature in cpufetch / I want to suggest a change in cpufetch
Great! Make a PR and make sure to explain how did you implement your new feature on the github conversation page.
### Case 3: I want to make changes to the Makefile
Don't open a pull request; open an issue instead and suggest your changes in the Makefile there. Except for extraordinary cases, I will not accept changes in the Makefile.
## Creating an issue
If you are going to report a bug or problem, always report the CPU model and OS. If possible, also paste the output of `cpufetch` and `cpufetch --debug`.
### cpufetch fails / crashes with a segmentation fault / ends without any output
You need to provide additional information in the github issue:
#### Option 1 (best)
1. Build cpufetch with debug symbols (`make clean; make debug`).
2. Install valgrind (if it is not already installed)
3. Run cpufetch with valgrind (`valgrind ./cpufetch`)
4. Paste the complete output (preferably on a platform like pastebin)
#### Option 2 (use this option if you can't work with option 1)
1. Build cpufetch with debug symbols (`make clean; make debug`).
2. Install gdb (if it is not already installed)
3. Debug cpufetch with gdb (`gdb cpufetch`)
3. Run cpufetch (just r inside gdb console)
4. Paste the complete output (preferably on a platform like pastebin)

View File

@@ -1,6 +1,6 @@
CC ?= gcc CC=gcc
CFLAGS+=-Wall -Wextra -pedantic -fstack-protector-all -pedantic -std=c99 CFLAGS=-Wall -Wextra -Werror -pedantic -fstack-protector-all -pedantic -std=c99
SANITY_FLAGS=-Wfloat-equal -Wshadow -Wpointer-arith SANITY_FLAGS=-Wfloat-equal -Wshadow -Wpointer-arith
PREFIX ?= /usr PREFIX ?= /usr
@@ -35,14 +35,13 @@ else
OUTPUT=cpufetch.exe OUTPUT=cpufetch.exe
endif endif
all: CFLAGS += -O3
all: $(OUTPUT) all: $(OUTPUT)
debug: CFLAGS += -g -O0 debug: CFLAGS += -g -O0
debug: $(OUTPUT) debug: $(OUTPUT)
static: CFLAGS += -static -O3 release: CFLAGS += -static -O3
static: $(OUTPUT) release: $(OUTPUT)
$(OUTPUT): Makefile $(SOURCE) $(HEADERS) $(OUTPUT): Makefile $(SOURCE) $(HEADERS)
$(CC) $(CFLAGS) $(SANITY_FLAGS) $(SOURCE) -o $(OUTPUT) $(CC) $(CFLAGS) $(SANITY_FLAGS) $(SOURCE) -o $(OUTPUT)
@@ -51,14 +50,14 @@ run: $(OUTPUT)
./$(OUTPUT) ./$(OUTPUT)
clean: clean:
@rm -f $(OUTPUT) @rm $(OUTPUT)
install: $(OUTPUT) install: $(OUTPUT)
install -Dm755 "cpufetch" "$(DESTDIR)$(PREFIX)/bin/cpufetch" install -Dm755 "cpufetch" "$(PREFIX)/bin/cpufetch"
install -Dm644 "LICENSE" "$(DESTDIR)$(PREFIX)/share/licenses/cpufetch-git/LICENSE" install -Dm644 "LICENSE" "$(PREFIX)/share/licenses/cpufetch-git/LICENSE"
install -Dm644 "cpufetch.1" "$(DESTDIR)$(PREFIX)/share/man/man1/cpufetch.1.gz" install -Dm644 "cpufetch.8" "$(PREFIX)/share/man/man8/cpufetch.8.gz"
uninstall: uninstall:
rm -f "$(DESTDIR)$(PREFIX)/bin/cpufetch" rm -f "$(PREFIX)/bin/cpufetch"
rm -f "$(DESTDIR)$(PREFIX)/share/licenses/cpufetch-git/LICENSE" rm -f "$(PREFIX)/share/licenses/cpufetch-git/LICENSE"
rm -f "$(DESTDIR)$(PREFIX)/share/man/man1/cpufetch.1.gz" rm -f "$(PREFIX)/share/man/man8/cpufetch.8.gz"

View File

@@ -3,10 +3,10 @@
<div align="center"> <div align="center">
![GitHub tag (latest by date)](https://img.shields.io/github/v/tag/Dr-Noob/cpufetch?label=cpufetch) ![GitHub tag (latest by date)](https://img.shields.io/github/v/tag/Dr-Noob/cpufetch?label=cpufetch)
[![GitHub Repo stars](https://img.shields.io/github/stars/Dr-Noob/cpufetch?color=4CC61F)](https://github.com/Dr-Noob/cpufetch/stargazers) ![GitHub Repo stars](https://img.shields.io/github/stars/Dr-Noob/cpufetch?color=4CC61F)
[![GitHub issues](https://img.shields.io/github/issues/Dr-Noob/cpufetch)](https://github.com/Dr-Noob/cpufetch/issues) ![GitHub issues](https://img.shields.io/github/issues/Dr-Noob/cpufetch)
[![Packaging status](https://repology.org/badge/tiny-repos/cpufetch.svg)](https://repology.org/project/cpufetch/versions) ![Contributions welcome](https://img.shields.io/badge/contributions-welcome-orange.svg)
[![License](https://img.shields.io/github/license/Dr-Noob/cpufetch?color=orange)](https://github.com/Dr-Noob/cpufetch/blob/master/LICENSE) [![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT)
<h4 align="center">Simple yet fancy CPU architecture fetching tool</h4> <h4 align="center">Simple yet fancy CPU architecture fetching tool</h4>
&nbsp; &nbsp;
@@ -23,9 +23,11 @@
- [1. Support](#1-support) - [1. Support](#1-support)
- [2. Installation](#2-installation) - [2. Installation](#2-installation)
- [2.1 Available packages](#21-available-packages) - [2.1 Building from source](#21-building-from-source)
- [2.2 Building from source (Linux/Windows/macOS)](#22-building-from-source-linuxwindowsmacos) - [2.2 Linux](#22-linux)
- [2.3 Android](#23-android) - [2.2 Windows](#22-windows)
- [2.3 macOS](#23-macos)
- [2.4 Android](#24-android)
- [3. Examples](#3-examples) - [3. Examples](#3-examples)
- [3.1 x86_64 CPUs](#31-x86_64-cpus) - [3.1 x86_64 CPUs](#31-x86_64-cpus)
- [3.2 ARM CPUs](#32-arm-cpus) - [3.2 ARM CPUs](#32-arm-cpus)
@@ -46,14 +48,7 @@ cpufetch supports x86, x86_64 (Intel and AMD) and ARM.
| macOS | :heavy_check_mark: | :x: | Some information may be missing. <br> Apple M1 support may be added <br> in the future (see [#47](https://github.com/Dr-Noob/cpufetch/issues/47))| | macOS | :heavy_check_mark: | :x: | Some information may be missing. <br> Apple M1 support may be added <br> in the future (see [#47](https://github.com/Dr-Noob/cpufetch/issues/47))|
# 2. Installation # 2. Installation
## 2.1 Installing from a package ## 2.1 Building from source
Choose the right package for your operating system:
[![Packaging status](https://repology.org/badge/vertical-allrepos/cpufetch.svg)](https://repology.org/project/cpufetch/versions)
If there is no available package for your OS, you can download the cpufetch binary from [the releases page](https://github.com/Dr-Noob/cpufetch/releases), or [build cpufetch from source](#22-building-from-source-linuxwindowsmacos) (see below).
## 2.2 Building from source (Linux/Windows/macOS)
Just clone the repo and use `make` to compile it Just clone the repo and use `make` to compile it
``` ```
@@ -65,7 +60,16 @@ make
The Makefile is designed to work on Linux, Windows and macOS. The Makefile is designed to work on Linux, Windows and macOS.
## 2.3 Android ## 2.2 Linux
There is a cpufetch package available in Arch Linux ([cpufetch-git](https://aur.archlinux.org/packages/cpufetch-git)). If you are in another distribution, you can build `cpufetch` from source.
## 2.2 Windows
In the [releases](https://github.com/Dr-Noob/cpufetch/releases) section you will find some cpufetch executables compiled for Windows. Just download and run it from Windows CMD. You can also build `cpufetch` from source.
## 2.3 macOS
You need to build `cpufetch` from source.
## 2.4 Android
1. Install `termux` app (terminal emulator) 1. Install `termux` app (terminal emulator)
2. Run `pkg install -y git make clang` inside termux. 2. Run `pkg install -y git make clang` inside termux.
3. Build from source normally: 3. Build from source normally:

View File

@@ -1,12 +1,12 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.48.2. .\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.48.2.
.TH CPUFETCH "1" "June 2021" "cpufetch v0.97 (x86_64 build)" "User Commands" .TH CPUFETCH "1" "March 2021" "cpufetch v0.97 (x86_64 build)" "User Commands"
.SH NAME .SH NAME
cpufetch \- Simple yet fancy CPU architecture fetching tool cpufetch \- manual page for cpufetch v0.97 (x86_64 build)
.SH SYNOPSIS .SH SYNOPSIS
.B cpufetch .B cpufetch
[\fI\,OPTION\/\fR]... [\fI\,OPTION\/\fR]...
.SH DESCRIPTION .SH DESCRIPTION
Print detailed information about the CPU architecture. cpufetch displays information like the number of cores, microarchitecture, frequency, cache and peak performance. The program supports x86, x86_64 and ARM architectures and runs on GNU/Linux, Windows, Android and macOS (see https://github.com/Dr-Noob/cpufetch#1-support for more information) Simple yet fancy CPU architecture fetching tool
.SH OPTIONS .SH OPTIONS
.TP .TP
\fB\-c\fR, \fB\-\-color\fR \fB\-c\fR, \fB\-\-color\fR
@@ -55,16 +55,13 @@ Old cpufetch style
Fallback style for terminals that do not support colors Fallback style for terminals that do not support colors
.SH "EXAMPLES:" .SH "EXAMPLES:"
Run cpufetch with Intel color scheme: Run cpufetch with Intel color scheme:
.PP
\&./cpufetch \fB\-\-color\fR intel \&./cpufetch \fB\-\-color\fR intel
.PP
Run cpufetch with a custom color scheme: Run cpufetch with a custom color scheme:
.PP
\&./cpufetch \fB\-\-color\fR 239,90,45:210,200,200:100,200,45:0,200,200 \&./cpufetch \fB\-\-color\fR 239,90,45:210,200,200:100,200,45:0,200,200
.SH "BUGS:" .SH "BUGS:"
Report bugs to https://github.com/Dr\-Noob/cpufetch/issues Report bugs to https://github.com/Dr\-Noob/cpufetch/issues
.SH "NOTE:" .SH "NOTE:"
Peak performance information is NOT accurate. cpufetch computes peak performance using the max frequency. However, to properly compute peak performance, you need to know the frequency of the CPU running AVX code, which is not be fetched by cpufetch since it depends on each specific CPU. For peak performance measurement see peakperf (https://github.com/Dr\-Noob/peakperf) Peak performance information is NOT accurate. cpufetch computes peak performance using the max frequency. However, to properly compute peak performance, you need to know the frequency of the CPU running AVX code, which is not be fetched by cpufetch since it depends on each specific CPU. For peak performance measurement see: https://github.com/Dr\-Noob/peakperf
.SH "AUTHOR:" .SH "AUTHOR:"
Dr-Noob (https://github.com/Dr-Noob) Dr-Noob (https://github.com/Dr-Noob)

View File

@@ -24,10 +24,6 @@ struct uarch {
}; };
enum { enum {
ISA_ARMv6,
ISA_ARMv6_T2,
ISA_ARMv6_KZ,
ISA_ARMv6_K,
ISA_ARMv7_A, ISA_ARMv7_A,
ISA_ARMv8_A, ISA_ARMv8_A,
ISA_ARMv8_A_AArch32, ISA_ARMv8_A_AArch32,
@@ -41,10 +37,7 @@ enum {
// ARM // ARM
UARCH_ARM7, UARCH_ARM7,
UARCH_ARM9, UARCH_ARM9,
UARCH_ARM1136, UARCH_ARM11, // ARM 1136, ARM 1156, ARM 1176, or ARM 11MPCore.
UARCH_ARM1156,
UARCH_ARM1176,
UARCH_ARM11MPCORE,
UARCH_CORTEX_A5, UARCH_CORTEX_A5,
UARCH_CORTEX_A7, UARCH_CORTEX_A7,
UARCH_CORTEX_A8, UARCH_CORTEX_A8,
@@ -105,10 +98,6 @@ enum {
}; };
static const ISA isas_uarch[] = { static const ISA isas_uarch[] = {
[UARCH_ARM1136] = ISA_ARMv6,
[UARCH_ARM1156] = ISA_ARMv6_T2,
[UARCH_ARM1176] = ISA_ARMv6_KZ,
[UARCH_ARM11MPCORE] = ISA_ARMv6_K,
[UARCH_CORTEX_A5] = ISA_ARMv7_A, [UARCH_CORTEX_A5] = ISA_ARMv7_A,
[UARCH_CORTEX_A7] = ISA_ARMv7_A, [UARCH_CORTEX_A7] = ISA_ARMv7_A,
[UARCH_CORTEX_A8] = ISA_ARMv7_A, [UARCH_CORTEX_A8] = ISA_ARMv7_A,
@@ -154,10 +143,6 @@ static const ISA isas_uarch[] = {
}; };
static char* isas_string[] = { static char* isas_string[] = {
[ISA_ARMv6] = "ARMv6",
[ISA_ARMv6_T2] = "ARMv6T2",
[ISA_ARMv6_KZ] = "ARMv6KZ",
[ISA_ARMv6_K] = "ARMv6K",
[ISA_ARMv7_A] = "ARMv7", [ISA_ARMv7_A] = "ARMv7",
[ISA_ARMv8_A] = "ARMv8", [ISA_ARMv8_A] = "ARMv8",
[ISA_ARMv8_A_AArch32] = "ARMv8 AArch32", [ISA_ARMv8_A_AArch32] = "ARMv8 AArch32",
@@ -205,10 +190,6 @@ struct uarch* get_uarch_from_midr(uint32_t midr, struct cpuInfo* cpu) {
// ----------------------------------------------------------------------- // // ----------------------------------------------------------------------- //
// IM P V R // // IM P V R //
UARCH_START UARCH_START
CHECK_UARCH(arch, cpu, 'A', 0xB36, NA, NA, "ARM1136", UARCH_ARM1136, CPU_VENDOR_ARM)
CHECK_UARCH(arch, cpu, 'A', 0xB56, NA, NA, "ARM1156", UARCH_ARM1156, CPU_VENDOR_ARM)
CHECK_UARCH(arch, cpu, 'A', 0xB76, NA, NA, "ARM1176", UARCH_ARM1176, CPU_VENDOR_ARM)
CHECK_UARCH(arch, cpu, 'A', 0xB02, NA, NA, "ARM11 MPCore", UARCH_ARM11MPCORE, CPU_VENDOR_ARM)
CHECK_UARCH(arch, cpu, 'A', 0xC05, NA, NA, "Cortex-A5", UARCH_CORTEX_A5, CPU_VENDOR_ARM) CHECK_UARCH(arch, cpu, 'A', 0xC05, NA, NA, "Cortex-A5", UARCH_CORTEX_A5, CPU_VENDOR_ARM)
CHECK_UARCH(arch, cpu, 'A', 0xC07, NA, NA, "Cortex-A7", UARCH_CORTEX_A7, CPU_VENDOR_ARM) CHECK_UARCH(arch, cpu, 'A', 0xC07, NA, NA, "Cortex-A7", UARCH_CORTEX_A7, CPU_VENDOR_ARM)
CHECK_UARCH(arch, cpu, 'A', 0xC08, NA, NA, "Cortex-A8", UARCH_CORTEX_A8, CPU_VENDOR_ARM) CHECK_UARCH(arch, cpu, 'A', 0xC08, NA, NA, "Cortex-A8", UARCH_CORTEX_A8, CPU_VENDOR_ARM)

View File

@@ -18,9 +18,8 @@
int get_ncores_from_cpuinfo() { int get_ncores_from_cpuinfo() {
// Examples: // Examples:
// 0-271 // 0-271
// 0-5
// 0-7 // 0-7
// 0
int filelen; int filelen;
char* buf; char* buf;
if((buf = read_file(_PATH_CPUS_PRESENT, &filelen)) == NULL) { if((buf = read_file(_PATH_CPUS_PRESENT, &filelen)) == NULL) {
@@ -28,16 +27,8 @@ int get_ncores_from_cpuinfo() {
return UNKNOWN; return UNKNOWN;
} }
int ncores; int ncores = 0;
char* tmp1; char* tmp1 = strstr(buf, "-") + 1;
if((tmp1 = strstr(buf, "-")) == NULL) {
// file contains no - character, we assume that it contains 0,
// which means that the CPU contains only one core
return 1;
}
else {
tmp1++;
}
char* tmp2 = strstr(buf, "\n"); char* tmp2 = strstr(buf, "\n");
char ncores_str[filelen]; char ncores_str[filelen];
memset(ncores_str, 0, sizeof(char) * filelen); memset(ncores_str, 0, sizeof(char) * filelen);

View File

@@ -20,6 +20,7 @@ static const char *SYTLES_STR_LIST[] = {
struct args_struct { struct args_struct {
bool debug_flag; bool debug_flag;
bool help_flag; bool help_flag;
bool loop_flag;
bool raw_flag; bool raw_flag;
bool verbose_flag; bool verbose_flag;
bool version_flag; bool version_flag;
@@ -30,6 +31,7 @@ struct args_struct {
const char args_chr[] = { const char args_chr[] = {
/* [ARG_CHAR_STYLE] = */ 's', /* [ARG_CHAR_STYLE] = */ 's',
/* [ARG_CHAR_COLOR] = */ 'c', /* [ARG_CHAR_COLOR] = */ 'c',
/* [ARG_CHAR_LOPP] = */ 'l',
/* [ARG_CHAR_HELP] = */ 'h', /* [ARG_CHAR_HELP] = */ 'h',
/* [ARG_CHAR_RAW] = */ 'r', /* [ARG_CHAR_RAW] = */ 'r',
/* [ARG_CHAR_DEBUG] = */ 'd', /* [ARG_CHAR_DEBUG] = */ 'd',
@@ -40,6 +42,7 @@ const char args_chr[] = {
const char *args_str[] = { const char *args_str[] = {
/* [ARG_CHAR_STYLE] = */ "style", /* [ARG_CHAR_STYLE] = */ "style",
/* [ARG_CHAR_COLOR] = */ "color", /* [ARG_CHAR_COLOR] = */ "color",
/* [ARG_CHAR_LOOP] = */ "loop",
/* [ARG_CHAR_HELP] = */ "help", /* [ARG_CHAR_HELP] = */ "help",
/* [ARG_CHAR_RAW] = */ "raw", /* [ARG_CHAR_RAW] = */ "raw",
/* [ARG_CHAR_DEBUG] = */ "debug", /* [ARG_CHAR_DEBUG] = */ "debug",
@@ -65,6 +68,10 @@ bool show_version() {
return args.version_flag; return args.version_flag;
} }
bool loop_mode() {
return args.loop_flag;
}
bool show_debug() { bool show_debug() {
return args.debug_flag; return args.debug_flag;
} }
@@ -190,13 +197,13 @@ char* build_short_options() {
memset(str, 0, sizeof(char) * (len*2 + 1)); memset(str, 0, sizeof(char) * (len*2 + 1));
#ifdef ARCH_X86 #ifdef ARCH_X86
sprintf(str, "%c:%c:%c%c%c%c%c", sprintf(str, "%c:%c:%c%c%c%c%c%c",
c[ARG_STYLE], c[ARG_COLOR], c[ARG_HELP], c[ARG_RAW], c[ARG_STYLE], c[ARG_COLOR], c[ARG_HELP], c[ARG_RAW],
c[ARG_DEBUG], c[ARG_VERBOSE], c[ARG_VERSION]); c[ARG_DEBUG], c[ARG_VERBOSE], c[ARG_VERSION], c[ARG_LOOP]);
#else #else
sprintf(str, "%c:%c:%c%c%c%c", sprintf(str, "%c:%c:%c%c%c%c%c",
c[ARG_STYLE], c[ARG_COLOR], c[ARG_HELP], c[ARG_STYLE], c[ARG_COLOR], c[ARG_HELP],
c[ARG_DEBUG], c[ARG_VERBOSE], c[ARG_VERSION]); c[ARG_DEBUG], c[ARG_VERBOSE], c[ARG_VERSION], c[ARG_LOOP]);
#endif #endif
return str; return str;
@@ -210,6 +217,7 @@ bool parse_args(int argc, char* argv[]) {
bool color_flag = false; bool color_flag = false;
args.debug_flag = false; args.debug_flag = false;
args.raw_flag = false; args.raw_flag = false;
args.loop_flag = false;
args.verbose_flag = false; args.verbose_flag = false;
args.help_flag = false; args.help_flag = false;
args.style = STYLE_EMPTY; args.style = STYLE_EMPTY;
@@ -223,6 +231,7 @@ bool parse_args(int argc, char* argv[]) {
{args_str[ARG_RAW], no_argument, 0, args_chr[ARG_RAW] }, {args_str[ARG_RAW], no_argument, 0, args_chr[ARG_RAW] },
#endif #endif
{args_str[ARG_DEBUG], no_argument, 0, args_chr[ARG_DEBUG] }, {args_str[ARG_DEBUG], no_argument, 0, args_chr[ARG_DEBUG] },
{args_str[ARG_LOOP], no_argument, 0, args_chr[ARG_LOOP] },
{args_str[ARG_VERBOSE], no_argument, 0, args_chr[ARG_VERBOSE] }, {args_str[ARG_VERBOSE], no_argument, 0, args_chr[ARG_VERBOSE] },
{args_str[ARG_VERSION], no_argument, 0, args_chr[ARG_VERSION] }, {args_str[ARG_VERSION], no_argument, 0, args_chr[ARG_VERSION] },
{0, 0, 0, 0} {0, 0, 0, 0}
@@ -255,6 +264,9 @@ bool parse_args(int argc, char* argv[]) {
} }
break; break;
} }
else if(opt == args_chr[ARG_LOOP]) {
args.loop_flag = true;
}
else if(opt == args_chr[ARG_HELP]) { else if(opt == args_chr[ARG_HELP]) {
args.help_flag = true; args.help_flag = true;
} }

View File

@@ -29,6 +29,7 @@ enum {
enum { enum {
ARG_STYLE, ARG_STYLE,
ARG_COLOR, ARG_COLOR,
ARG_LOOP,
ARG_HELP, ARG_HELP,
ARG_RAW, ARG_RAW,
ARG_DEBUG, ARG_DEBUG,
@@ -44,6 +45,7 @@ extern const char *args_str[];
int max_arg_str_length(); int max_arg_str_length();
bool parse_args(int argc, char* argv[]); bool parse_args(int argc, char* argv[]);
bool show_help(); bool show_help();
bool loop_mode();
bool show_raw(); bool show_raw();
bool show_debug(); bool show_debug();
bool show_version(); bool show_version();

0
src/common/cpu.c Normal file → Executable file
View File

View File

@@ -68,3 +68,7 @@ void set_log_level(bool verbose) {
int max(int a, int b) { int max(int a, int b) {
return a > b ? a : b; return a > b ? a : b;
} }
int min(int a, int b) {
return a < b ? a : b;
}

View File

@@ -8,5 +8,6 @@ void printWarn(const char *fmt, ...);
void printErr(const char *fmt, ...); void printErr(const char *fmt, ...);
void printBug(const char *fmt, ...); void printBug(const char *fmt, ...);
int max(int a, int b); int max(int a, int b);
int min(int a, int b);
#endif #endif

View File

@@ -14,21 +14,7 @@
#include "../arm/midr.h" #include "../arm/midr.h"
#endif #endif
#ifdef __linux__ static const char* VERSION = "0.97";
#ifdef __ANDROID__
static const char* OS_STR = "Android";
#else
static const char* OS_STR = "Linux";
#endif
#elif _WIN32
static const char* OS_STR = "Windows";
#elif defined __APPLE__ || __MACH__
static const char* OS_STR = "macOS";
#else
static const char* OS_STR = "Unknown OS";
#endif
static const char* VERSION = "0.98";
void print_help(char *argv[]) { void print_help(char *argv[]) {
const char **t = args_str; const char **t = args_str;
@@ -41,6 +27,7 @@ void print_help(char *argv[]) {
printf("Options: \n"); printf("Options: \n");
printf(" -%c, --%s %*s Set the color scheme (by default, cpufetch uses the system color scheme)\n", c[ARG_COLOR], t[ARG_COLOR], (int) (max_len-strlen(t[ARG_COLOR])), ""); printf(" -%c, --%s %*s Set the color scheme (by default, cpufetch uses the system color scheme)\n", c[ARG_COLOR], t[ARG_COLOR], (int) (max_len-strlen(t[ARG_COLOR])), "");
printf(" -%c, --%s %*s Set the style of CPU art\n", c[ARG_STYLE], t[ARG_STYLE], (int) (max_len-strlen(t[ARG_STYLE])), ""); printf(" -%c, --%s %*s Set the style of CPU art\n", c[ARG_STYLE], t[ARG_STYLE], (int) (max_len-strlen(t[ARG_STYLE])), "");
printf(" -%c, --%s %*s Runs cpufetch in a loop\n", c[ARG_LOOP], t[ARG_LOOP], (int) (max_len-strlen(t[ARG_LOOP])), "");
#ifdef ARCH_X86 #ifdef ARCH_X86
printf(" -%c, --%s %*s Prints CPU model and cpuid levels (debug purposes)\n", c[ARG_DEBUG], t[ARG_DEBUG], (int) (max_len-strlen(t[ARG_DEBUG])), ""); printf(" -%c, --%s %*s Prints CPU model and cpuid levels (debug purposes)\n", c[ARG_DEBUG], t[ARG_DEBUG], (int) (max_len-strlen(t[ARG_DEBUG])), "");
#elif ARCH_ARM #elif ARCH_ARM
@@ -83,7 +70,7 @@ void print_help(char *argv[]) {
} }
void print_version() { void print_version() {
printf("cpufetch v%s (%s %s)\n",VERSION, OS_STR, ARCH_STR); printf("cpufetch v%s (%s)\n",VERSION, ARCH_STR);
} }
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {

View File

@@ -1,3 +1,15 @@
#ifdef _WIN32
#define NOMINMAX
#include <Windows.h>
#else
#ifdef __linux__
#define _POSIX_C_SOURCE 199309L
#endif
#include <sys/ioctl.h>
#include <unistd.h>
#endif
#include <signal.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
@@ -17,11 +29,6 @@
#include "../arm/soc.h" #include "../arm/soc.h"
#endif #endif
#ifdef _WIN32
#define NOMINMAX
#include <Windows.h>
#endif
#define max(a,b) (((a)>(b))?(a):(b)) #define max(a,b) (((a)>(b))?(a):(b))
#define MAX_ATTRIBUTES 100 #define MAX_ATTRIBUTES 100
@@ -118,6 +125,29 @@ struct ascii {
STYLE style; STYLE style;
}; };
struct terminal {
int w;
int h;
};
volatile sig_atomic_t loop = 1;
#ifdef _WIN32
BOOL WINAPI loop_mode_handler(DWORD signum) {
if (signum == CTRL_C_EVENT) {
loop = 0;
}
return TRUE;
}
#else
void loop_mode_handler(int signum) {
if(signum == SIGINT) {
loop = 0;
}
}
#endif
void setAttribute(struct ascii* art, int type, char* value) { void setAttribute(struct ascii* art, int type, char* value) {
art->attributes[art->n_attributes_set]->value = value; art->attributes[art->n_attributes_set]->value = value;
art->attributes[art->n_attributes_set]->type = type; art->attributes[art->n_attributes_set]->type = type;
@@ -227,11 +257,6 @@ struct ascii* set_ascii(VENDOR vendor, STYLE style, struct colors* cs) {
art->ascii_chars[1] = '#'; art->ascii_chars[1] = '#';
#ifdef _WIN32 #ifdef _WIN32
// Old Windows do not define the flag
#ifndef ENABLE_VIRTUAL_TERMINAL_PROCESSING
#define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x0004
#endif
HANDLE std_handle = GetStdHandle(STD_OUTPUT_HANDLE); HANDLE std_handle = GetStdHandle(STD_OUTPUT_HANDLE);
DWORD console_mode; DWORD console_mode;
@@ -350,6 +375,33 @@ uint32_t longest_attribute_length(struct ascii* art) {
return max; return max;
} }
bool run_loop_mode() {
#ifdef _WIN32
if (!SetConsoleCtrlHandler(loop_mode_handler, TRUE)) {
printErr("SetConsoleCtrlHandler failed");
return false;
}
#else
struct sigaction act;
memset(&act, 0, sizeof(struct sigaction));
act.sa_handler = loop_mode_handler;
if(sigaction(SIGINT, &act, NULL) == -1) {
perror("sigaction");
return false;
}
#endif
while (loop) {
#ifdef _WIN32
Sleep(1000);
#else
sleep(1);
#endif
}
return true;
}
#ifdef ARCH_X86 #ifdef ARCH_X86
void print_algorithm_intel(struct ascii* art, int n, bool* flag) { void print_algorithm_intel(struct ascii* art, int n, bool* flag) {
for(int i=0; i < LINE_SIZE; i++) { for(int i=0; i < LINE_SIZE; i++) {
@@ -387,46 +439,59 @@ void print_algorithm_amd(struct ascii* art, int n, bool* flag) {
} }
} }
void print_ascii_x86(struct ascii* art, uint32_t la, void (*callback_print_algorithm)(struct ascii* art, int i, bool* flag)) { void print_ascii_x86(struct ascii* art, struct terminal* term, uint32_t la, void (*callback_print_algorithm)(struct ascii* art, int i, bool* flag)) {
int attr_to_print = 0; int attr_to_print = 0;
int attr_type; int attr_type;
char* attr_value; char* attr_value;
int attr_print_len;
uint32_t attr_space_left;
uint32_t space_right; uint32_t space_right;
uint32_t space_up = (NUMBER_OF_LINES - art->n_attributes_set)/2; uint32_t space_up = (NUMBER_OF_LINES - art->n_attributes_set)/2;
uint32_t space_down = NUMBER_OF_LINES - art->n_attributes_set - space_up; uint32_t space_down = NUMBER_OF_LINES - art->n_attributes_set - space_up;
bool flag = false; bool flag = false;
bool print_ascii_art;
if(term->w - LINE_SIZE - 1 - (int) la > 0) {
print_ascii_art = true;
attr_space_left = term->w - LINE_SIZE - 1 - la;
}
else {
print_ascii_art = false;
attr_space_left = term->w - 1 - la;
}
printf("\n"); printf("\n");
for(uint32_t n=0;n<NUMBER_OF_LINES;n++) { for(uint32_t n=0;n<NUMBER_OF_LINES;n++) {
callback_print_algorithm(art, n, &flag); if(print_ascii_art) callback_print_algorithm(art, n, &flag);
if(n > space_up-1 && n < NUMBER_OF_LINES-space_down) { if(n > space_up-1 && n < NUMBER_OF_LINES-space_down) {
attr_type = art->attributes[attr_to_print]->type; attr_type = art->attributes[attr_to_print]->type;
attr_value = art->attributes[attr_to_print]->value; attr_value = art->attributes[attr_to_print]->value;
attr_to_print++; attr_to_print++;
attr_print_len = min(strlen(attr_value), attr_space_left);
attr_print_len = max(attr_print_len, 0);
space_right = 1 + (la - strlen(ATTRIBUTE_FIELDS[attr_type])); space_right = 1 + (la - strlen(ATTRIBUTE_FIELDS[attr_type]));
printf("%s%s%s%*s%s%s%s\n", art->color1_text, ATTRIBUTE_FIELDS[attr_type], art->reset, space_right, "", art->color2_text, attr_value, art->reset); printf("%s%s%s%*s%s%.*s%s\n", art->color1_text, ATTRIBUTE_FIELDS[attr_type], art->reset, space_right, "", art->color2_text, attr_print_len, attr_value, art->reset);
} }
else printf("\n"); else printf("\n");
} }
printf("\n"); printf("\n");
} }
void print_ascii(struct ascii* art) { void print_ascii(struct ascii* art, struct terminal* term) {
uint32_t longest_attribute = longest_attribute_length(art); uint32_t longest_attribute = longest_attribute_length(art);
if(art->vendor == CPU_VENDOR_INTEL) if(art->vendor == CPU_VENDOR_INTEL)
print_ascii_x86(art, longest_attribute, &print_algorithm_intel); print_ascii_x86(art, term, longest_attribute, &print_algorithm_intel);
else if(art->vendor == CPU_VENDOR_AMD) else if(art->vendor == CPU_VENDOR_AMD)
print_ascii_x86(art, longest_attribute, &print_algorithm_amd); print_ascii_x86(art, term, longest_attribute, &print_algorithm_amd);
else { else {
printBug("Invalid CPU vendor: %d\n", art->vendor); printBug("Invalid CPU vendor: %d\n", art->vendor);
} }
} }
bool print_cpufetch_x86(struct cpuInfo* cpu, STYLE s, struct colors* cs) { bool print_cpufetch_x86(struct cpuInfo* cpu, STYLE s, struct colors* cs, struct terminal* term) {
struct ascii* art = set_ascii(get_cpu_vendor(cpu), s, cs); struct ascii* art = set_ascii(get_cpu_vendor(cpu), s, cs);
if(art == NULL) if(art == NULL)
return false; return false;
@@ -441,7 +506,6 @@ bool print_cpufetch_x86(struct cpuInfo* cpu, STYLE s, struct colors* cs) {
char* avx = get_str_avx(cpu); char* avx = get_str_avx(cpu);
char* fma = get_str_fma(cpu); char* fma = get_str_fma(cpu);
char* l1i = get_str_l1i(cpu->cach); char* l1i = get_str_l1i(cpu->cach);
char* l1d = get_str_l1d(cpu->cach); char* l1d = get_str_l1d(cpu->cach);
char* l2 = get_str_l2(cpu->cach); char* l2 = get_str_l2(cpu->cach);
@@ -479,7 +543,11 @@ bool print_cpufetch_x86(struct cpuInfo* cpu, STYLE s, struct colors* cs) {
return false; return false;
} }
print_ascii(art); print_ascii(art, term);
if(loop_mode()) {
return run_loop_mode();
}
free(manufacturing_process); free(manufacturing_process);
free(max_frequency); free(max_frequency);
@@ -547,7 +615,7 @@ void print_algorithm_arm(struct ascii* art, int n) {
} }
} }
void print_ascii_arm(struct ascii* art, uint32_t la, void (*callback_print_algorithm)(struct ascii* art, int n)) { void print_ascii_arm(struct ascii* art, struct terminal* term, uint32_t la, void (*callback_print_algorithm)(struct ascii* art, int n)) {
int attr_to_print = 0; int attr_to_print = 0;
int attr_type; int attr_type;
char* attr_value; char* attr_value;
@@ -606,18 +674,18 @@ void print_ascii(struct ascii* art) {
uint32_t longest_attribute = longest_attribute_length(art); uint32_t longest_attribute = longest_attribute_length(art);
if(art->vendor == SOC_VENDOR_SNAPDRAGON || art->vendor == SOC_VENDOR_MEDIATEK || art->vendor == SOC_VENDOR_KIRIN || art->vendor == SOC_VENDOR_BROADCOM) if(art->vendor == SOC_VENDOR_SNAPDRAGON || art->vendor == SOC_VENDOR_MEDIATEK || art->vendor == SOC_VENDOR_KIRIN || art->vendor == SOC_VENDOR_BROADCOM)
print_ascii_arm(art, longest_attribute, &print_algorithm_snapd_mtk); print_ascii_arm(art, term, longest_attribute, &print_algorithm_snapd_mtk);
else if(art->vendor == SOC_VENDOR_EXYNOS) else if(art->vendor == SOC_VENDOR_EXYNOS)
print_ascii_arm(art, longest_attribute, &print_algorithm_samsung); print_ascii_arm(art, term, longest_attribute, &print_algorithm_samsung);
else { else {
if(art->vendor != SOC_VENDOR_UNKNOWN) if(art->vendor != SOC_VENDOR_UNKNOWN)
printWarn("Invalid SOC vendor: %d\n", art->vendor); printWarn("Invalid SOC vendor: %d\n", art->vendor);
print_ascii_arm(art, longest_attribute, &print_algorithm_arm); print_ascii_arm(art, term, longest_attribute, &print_algorithm_arm);
} }
} }
bool print_cpufetch_arm(struct cpuInfo* cpu, STYLE s, struct colors* cs) { bool print_cpufetch_arm(struct cpuInfo* cpu, STYLE s, struct colors* cs, struct terminal* term) {
struct ascii* art = set_ascii(get_soc_vendor(cpu->soc), s, cs); struct ascii* art = set_ascii(get_soc_vendor(cpu->soc), s, cs);
if(art == NULL) if(art == NULL)
return false; return false;
@@ -685,7 +753,11 @@ bool print_cpufetch_arm(struct cpuInfo* cpu, STYLE s, struct colors* cs) {
if(cpu->hv->present) if(cpu->hv->present)
setAttribute(art, ATTRIBUTE_HYPERVISOR, cpu->hv->hv_name); setAttribute(art, ATTRIBUTE_HYPERVISOR, cpu->hv->hv_name);
print_ascii(art); print_ascii(art, term);
if(loop_mode()) {
return run_loop_mode();
}
free(manufacturing_process); free(manufacturing_process);
free(pp); free(pp);
@@ -702,6 +774,31 @@ bool print_cpufetch_arm(struct cpuInfo* cpu, STYLE s, struct colors* cs) {
} }
#endif #endif
struct terminal* get_terminal_size() {
struct terminal* term = malloc(sizeof(struct terminal));
memset(term, 0, sizeof(struct terminal));
#ifdef _WIN32
CONSOLE_SCREEN_BUFFER_INFO csbi;
if(GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi) == 0) {
printWarn("GetConsoleScreenBufferInfo failed");
return term;
}
term->w = csbi.srWindow.Right - csbi.srWindow.Left + 1;
term->h = csbi.srWindow.Bottom - csbi.srWindow.Top + 1;
#else
struct winsize w;
if(ioctl(STDOUT_FILENO, TIOCGWINSZ, &w) == -1) {
perror("ioctl");
return term;
}
term->h = w.ws_row;
term->w = w.ws_col;
#endif
return term;
}
bool print_cpufetch(struct cpuInfo* cpu, STYLE s, struct colors* cs) { bool print_cpufetch(struct cpuInfo* cpu, STYLE s, struct colors* cs) {
// Sanity check of ASCII arts // Sanity check of ASCII arts
int len = sizeof(ASCII_ARRAY) / sizeof(ASCII_ARRAY[0]); int len = sizeof(ASCII_ARRAY) / sizeof(ASCII_ARRAY[0]);
@@ -713,9 +810,11 @@ bool print_cpufetch(struct cpuInfo* cpu, STYLE s, struct colors* cs) {
} }
} }
struct terminal* term = get_terminal_size();
#ifdef ARCH_X86 #ifdef ARCH_X86
return print_cpufetch_x86(cpu, s, cs); return print_cpufetch_x86(cpu, s, cs, term);
#elif ARCH_ARM #elif ARCH_ARM
return print_cpufetch_arm(cpu, s, cs); return print_cpufetch_arm(cpu, s, cs, term);
#endif #endif
} }

27
src/x86/cpuid.c Normal file → Executable file
View File

@@ -581,7 +581,6 @@ struct cache* get_cache_info_general(struct cache* cach, uint32_t level) {
} }
else { else {
printWarn("Found unknown unified cache at level %d (size is %d bytes)", cache_level, cache_total_size); printWarn("Found unknown unified cache at level %d (size is %d bytes)", cache_level, cache_total_size);
cach->max_cache_level--;
} }
break; break;
@@ -650,7 +649,12 @@ struct frequency* get_frequency_info(struct cpuInfo* cpu) {
freq->max = get_max_freq_from_file(0, cpu->hv->present); freq->max = get_max_freq_from_file(0, cpu->hv->present);
if(freq->max == 0) { if(freq->max == 0) {
printWarn("Read max CPU frequency from udev and got 0 MHz"); if(cpu->hv->present) {
printWarn("Read max CPU frequency and got 0 MHz");
}
else {
printBug("Read max CPU frequency and got 0 MHz");
}
freq->max = UNKNOWN_FREQ; freq->max = UNKNOWN_FREQ;
} }
#endif #endif
@@ -667,17 +671,22 @@ struct frequency* get_frequency_info(struct cpuInfo* cpu) {
freq->max = ebx; freq->max = ebx;
if(freq->base == 0) { if(freq->base == 0) {
printWarn("Read base CPU frequency from CPUID and got 0 MHz"); if(cpu->hv->present) {
printWarn("Read base CPU frequency and got 0 MHz");
}
else {
printBug("Read base CPU frequency and got 0 MHz");
}
freq->base = UNKNOWN_FREQ; freq->base = UNKNOWN_FREQ;
} }
if(freq->max == 0) { if(freq->max == 0) {
printWarn("Read max CPU frequency from CPUID and got 0 MHz. Using udev"); if(cpu->hv->present) {
freq->max = get_max_freq_from_file(0, cpu->hv->present); printWarn("Read max CPU frequency and got 0 MHz");
if(freq->max == 0) {
printWarn("Read max CPU frequency from udev and got 0 MHz");
freq->max = UNKNOWN_FREQ;
} }
else {
printBug("Read max CPU frequency and got 0 MHz");
}
freq->max = UNKNOWN_FREQ;
} }
} }

View File

@@ -38,8 +38,6 @@
typedef uint32_t MICROARCH; typedef uint32_t MICROARCH;
#define STRING_UNKNOWN "Unknown"
// Data not available // Data not available
#define NA -1 #define NA -1
@@ -404,22 +402,13 @@ char* get_str_uarch(struct cpuInfo* cpu) {
} }
char* get_str_process(struct cpuInfo* cpu) { char* get_str_process(struct cpuInfo* cpu) {
char* str = malloc(sizeof(char) * (strlen(STRING_UNKNOWN)+1)); char* str = malloc(sizeof(char) * (4+2+1));
int32_t process = cpu->arch->process; uint32_t process = cpu->arch->process;
if(process == UNK) { if(process > 100)
snprintf(str, strlen(STRING_UNKNOWN)+1, STRING_UNKNOWN);
}
else if(process > 100) {
sprintf(str, "%.2fum", (double)process/100); sprintf(str, "%.2fum", (double)process/100);
} else
else if(process > 0){
sprintf(str, "%dnm", process); sprintf(str, "%dnm", process);
}
else {
snprintf(str, strlen(STRING_UNKNOWN)+1, STRING_UNKNOWN);
printBug("Found invalid process: '%d'", process);
}
return str; return str;
} }