PatchworkOS  28a9544
A non-POSIX operating system.
Loading...
Searching...
No Matches
main.c File Reference
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/io.h>
#include <sys/proc.h>
#include <threads.h>
#include <time.h>

Go to the source code of this file.

Data Structures

struct  cpu_perfs_t
 
struct  mem_perfs_t
 
struct  proc_perfs_t
 
struct  perfs_t
 

Macros

#define SAMPLE_INTERVAL   (CLOCKS_PER_SEC)
 

Enumerations

enum  sort_mode_t {
  SORT_PID ,
  SORT_MEMORY ,
  SORT_CPU
}
 

Functions

static void terminal_size_get (void)
 
static uint64_t cpu_perf_count_cpus (void)
 
static uint64_t cpu_perf_read (cpu_perfs_t *cpuPerfs)
 
static uint64_t mem_perf_read (mem_perfs_t *memPerfs)
 
static proc_perfs_tproc_perfs_read (uint64_t *procAmount)
 
static void calculate_cpu_percentages (perfs_t *perfs)
 
static int compare_by_pid (const void *a, const void *b)
 
static int compare_by_memory (const void *a, const void *b)
 
static int compare_by_cpu (const void *a, const void *b)
 
static void sort_processes (perfs_t *perfs)
 
static void perfs_update (perfs_t *perfs)
 
static void perf_percentage (clock_t part, clock_t total, uint64_t *whole, uint64_t *thousandths)
 
static void perfs_print (perfs_t *perfs)
 
int main (void)
 

Variables

static uint64_t terminalColumns
 
static uint64_t terminalRows
 
static uint64_t processScrollOffset = 0
 
static clock_t lastSampleTime = 0
 
static uint64_t cpuAmount = 0
 
static sort_mode_t currentSortMode = SORT_CPU
 

Macro Definition Documentation

◆ SAMPLE_INTERVAL

#define SAMPLE_INTERVAL   (CLOCKS_PER_SEC)

Definition at line 10 of file main.c.

Enumeration Type Documentation

◆ sort_mode_t

Enumerator
SORT_PID 
SORT_MEMORY 
SORT_CPU 

Definition at line 19 of file main.c.

Function Documentation

◆ calculate_cpu_percentages()

◆ compare_by_cpu()

static int compare_by_cpu ( const void *  a,
const void *  b 
)
static

Definition at line 318 of file main.c.

References proc_perfs_t::cpuPercent.

Referenced by sort_processes().

◆ compare_by_memory()

static int compare_by_memory ( const void *  a,
const void *  b 
)
static

Definition at line 311 of file main.c.

References proc_perfs_t::userKiB.

Referenced by sort_processes().

◆ compare_by_pid()

static int compare_by_pid ( const void *  a,
const void *  b 
)
static

Definition at line 304 of file main.c.

References proc_perfs_t::pid.

Referenced by sort_processes().

◆ cpu_perf_count_cpus()

static uint64_t cpu_perf_count_cpus ( void  )
static

Definition at line 103 of file main.c.

References ERR, fclose(), fgets(), file, fopen(), and NULL.

Referenced by main().

◆ cpu_perf_read()

static uint64_t cpu_perf_read ( cpu_perfs_t cpuPerfs)
static

◆ main()

◆ mem_perf_read()

static uint64_t mem_perf_read ( mem_perfs_t memPerfs)
static

◆ perf_percentage()

static void perf_percentage ( clock_t  part,
clock_t  total,
uint64_t whole,
uint64_t thousandths 
)
static

Definition at line 450 of file main.c.

Referenced by perfs_print().

◆ perfs_print()

◆ perfs_update()

◆ proc_perfs_read()

◆ sort_processes()

static void sort_processes ( perfs_t perfs)
static

◆ terminal_size_get()

static void terminal_size_get ( void  )
static

Definition at line 28 of file main.c.

References buffer, fflush(), MAX_NAME, printf(), read(), sscanf(), STDIN_FILENO, stdout, terminalColumns, and terminalRows.

Referenced by main().

Variable Documentation

◆ cpuAmount

uint64_t cpuAmount = 0
static

Definition at line 17 of file main.c.

Referenced by cpu_perf_read(), main(), perfs_print(), and perfs_update().

◆ currentSortMode

sort_mode_t currentSortMode = SORT_CPU
static

Definition at line 26 of file main.c.

Referenced by perfs_print(), perfs_update(), and sort_processes().

◆ lastSampleTime

clock_t lastSampleTime = 0
static

Definition at line 16 of file main.c.

Referenced by perfs_update().

◆ processScrollOffset

uint64_t processScrollOffset = 0
static

Definition at line 14 of file main.c.

Referenced by perfs_print(), and perfs_update().

◆ terminalColumns

uint64_t terminalColumns
static

Definition at line 12 of file main.c.

Referenced by main(), perfs_print(), and terminal_size_get().

◆ terminalRows

uint64_t terminalRows
static

Definition at line 13 of file main.c.

Referenced by perfs_print(), and terminal_size_get().