PatchworkOS  3984a1d
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>
Include dependency graph for main.c:

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

◆ terminal_size_get()

static void terminal_size_get ( void  )
static

Definition at line 28 of file main.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cpu_perf_count_cpus()

static uint64_t cpu_perf_count_cpus ( void  )
static

Definition at line 103 of file main.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cpu_perf_read()

static uint64_t cpu_perf_read ( cpu_perfs_t cpuPerfs)
static

Definition at line 122 of file main.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mem_perf_read()

static uint64_t mem_perf_read ( mem_perfs_t memPerfs)
static

Definition at line 154 of file main.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ proc_perfs_read()

static proc_perfs_t * proc_perfs_read ( uint64_t procAmount)
static

Definition at line 182 of file main.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ calculate_cpu_percentages()

static void calculate_cpu_percentages ( perfs_t perfs)
static

Definition at line 283 of file main.c.

Here is the caller graph for this function:

◆ compare_by_pid()

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

Definition at line 304 of file main.c.

Here is the caller graph for this function:

◆ compare_by_memory()

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

Definition at line 311 of file main.c.

Here is the caller graph for this function:

◆ compare_by_cpu()

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

Definition at line 318 of file main.c.

Here is the caller graph for this function:

◆ sort_processes()

static void sort_processes ( perfs_t perfs)
static

Definition at line 329 of file main.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ perfs_update()

static void perfs_update ( perfs_t perfs)
static

Definition at line 345 of file main.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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.

Here is the caller graph for this function:

◆ perfs_print()

static void perfs_print ( perfs_t perfs)
static

Definition at line 465 of file main.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ main()

int main ( void  )

Definition at line 714 of file main.c.

Here is the call graph for this function:

Variable Documentation

◆ terminalColumns

uint64_t terminalColumns
static

Definition at line 12 of file main.c.

◆ terminalRows

uint64_t terminalRows
static

Definition at line 13 of file main.c.

◆ processScrollOffset

uint64_t processScrollOffset = 0
static

Definition at line 14 of file main.c.

◆ lastSampleTime

clock_t lastSampleTime = 0
static

Definition at line 16 of file main.c.

◆ cpuAmount

uint64_t cpuAmount = 0
static

Definition at line 17 of file main.c.

◆ currentSortMode

sort_mode_t currentSortMode = SORT_CPU
static

Definition at line 26 of file main.c.