wip: wip wip wip wip wip wip wip

wip?
This commit is contained in:
Alastair Poole 2021-05-17 16:30:30 +01:00
parent 2568058a44
commit a6e45b02b7
6 changed files with 1780 additions and 1 deletions

129
src/bin/next/filesystems.c Normal file
View File

@ -0,0 +1,129 @@
#include "filesystems.h"
#include <stdio.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#if defined(__linux__)
#include <sys/vfs.h>
#endif
#if defined(__APPLE__) && defined(__MACH__)
# define __MacOS__
#endif
#if defined (__MacOS__) || defined(__FreeBSD__) || defined(__DragonFly__)
# include <sys/types.h>
# include <sys/sysctl.h>
# include <sys/param.h>
# include <sys/ucred.h>
# include <sys/mount.h>
#endif
#if defined(__OpenBSD__) || defined(__NetBSD__)
# include <sys/param.h>
# include <sys/sysctl.h>
# include <sys/mount.h>
#endif
Eina_List *
file_system_info_all_get(void)
{
Eina_List *list = NULL;
# if defined(__linux__)
FILE *f;
char *dev, *mount, *type_name, *cp, *end;
struct statfs stats;
char buf[4096];
f = fopen("/proc/mounts", "r");
if (!f) return NULL;
while ((fgets(buf, sizeof(buf), f)) != NULL)
{
mount = strchr(buf, ' ') + 1;
if (!mount) continue;
dev = strndup(buf, mount - buf);
cp = strchr(mount, ' ');
if (!cp) continue;
end = cp;
*end = '\0';
cp++;
end = strchr(cp, ' ');
if (!end) continue;
type_name = strndup(cp, end - cp);
if ((strstr(cp, "nodev")) || (statfs(mount, &stats) < 0) ||
(stats.f_blocks == 0 && stats.f_bfree == 0))
{
free(dev);
free(type_name);
continue;
}
File_System *fs = calloc(1, sizeof(File_System));
fs->mount = strdup(mount);
fs->path = dev;
fs->type_name = type_name;
fs->usage.total = stats.f_bsize * stats.f_blocks;
fs->usage.used = fs->usage.total - (stats.f_bsize * stats.f_bfree);
list = eina_list_append(list, fs);
}
fclose(f);
# else
struct statfs *mounts;
int i, count;
count = getmntinfo(&mounts, MNT_WAIT);
for (i = 0; i < count; i++)
{
File_System *fs = calloc(1, sizeof(File_System));
fs->mount = strdup(mounts[i].f_mntonname);
fs->path = strdup(mounts[i].f_mntfromname);
#if defined(__OpenBSD__)
#else
fs->type = mounts[i].f_type;
#endif
fs->type_name = strdup(mounts[i].f_fstypename);
fs->usage.total = mounts[i].f_bsize * mounts[i].f_blocks;
fs->usage.used = fs->usage.total - (mounts[i].f_bsize * mounts[i].f_bfree);
list = eina_list_append(list, fs);
}
# endif
return list;
}
void
file_system_info_free(File_System *fs)
{
free(fs->mount);
free(fs->path);
if (fs->type_name)
free(fs->type_name);
free(fs);
}
Eina_Bool
file_system_in_use(const char *name)
{
Eina_List *list;
File_System *fs;
Eina_Bool mounted = 0;
if (!name) return 0;
list = file_system_info_all_get();
EINA_LIST_FREE(list, fs)
{
if (fs->type_name && (!strcasecmp(fs->type_name, name)))
mounted = 1;
file_system_info_free(fs);
}
return mounted;
}

View File

@ -0,0 +1,28 @@
#ifndef __FILESYSTEMS_H__
#define __FILESYSTEMS_H__
#include <Eina.h>
typedef struct {
unsigned long long total;
unsigned long long used;
} _Usage;
typedef struct _File_System {
char *path;
char *mount;
char *type_name;
unsigned int type;
_Usage usage;
} File_System;
Eina_List *
file_system_info_all_get(void);
void
file_system_info_free(File_System *fs);
Eina_Bool
file_system_in_use(const char *name);
#endif

View File

@ -136,7 +136,7 @@ int
cores_frequency(void);
int
core_id_frequency(int d);
core_id_frequency(int id);
int
core_id_temperature(int id);

View File

@ -1,4 +1,8 @@
src_watch += files([
'machine.c',
'machine.h',
'process.c',
'process.h',
'filesystems.c',
'filesystems.h',
])

1499
src/bin/next/process.c Normal file

File diff suppressed because it is too large Load Diff

119
src/bin/next/process.h Normal file
View File

@ -0,0 +1,119 @@
#ifndef __PROC_H__
#define __PROC_H__
#include <Eina.h>
#include <stdint.h>
#include <unistd.h>
#if !defined(PID_MAX)
# define PID_MAX 99999
#endif
typedef struct _Proc_Info
{
pid_t pid;
pid_t ppid;
uid_t uid;
int8_t nice;
int8_t priority;
int cpu_id;
int32_t numthreads;
int64_t cpu_time;
double cpu_usage;
int64_t run_time;
int64_t start;
uint64_t mem_size;
uint64_t mem_virt;
uint64_t mem_rss;
uint64_t mem_shared;
char *command;
char *arguments;
char state[32];
char wchan[32];
Eina_List *fds;
int numfiles;
short is_kernel;
int tid;
char *thread_name;
Eina_List *threads;
Eina_List *children;
} Proc_Info;
Eina_List *
proc_info_all_get(void);
Proc_Info *
proc_info_by_pid(int pid);
void
proc_info_free(Proc_Info *proc);
void
proc_info_kthreads_show_set(Eina_Bool enabled);
Eina_Bool
proc_info_kthreads_show_get(void);
Eina_List *
proc_info_all_children_get(void);
Eina_List *
proc_info_pid_children_get(pid_t pid);
void
proc_info_pid_children_free(Proc_Info *procs);
int
proc_sort_by_pid(const void *p1, const void *p2);
int
proc_sort_by_uid(const void *p1, const void *p2);
int
proc_sort_by_nice(const void *p1, const void *p2);
int
proc_sort_by_pri(const void *p1, const void *p2);
int
proc_sort_by_cpu(const void *p1, const void *p2);
int
proc_sort_by_threads(const void *p1, const void *p2);
int
proc_sort_by_files(const void *p1, const void *p2);
int
proc_sort_by_size(const void *p1, const void *p2);
int
proc_sort_by_virt(const void *p1, const void *p2);
int
proc_sort_by_rss(const void *p1, const void *p2);
int
proc_sort_by_shared(const void *p1, const void *p2);
int
proc_sort_by_time(const void *p1, const void *p2);
int
proc_sort_by_cpu_usage(const void *p1, const void *p2);
int
proc_sort_by_cmd(const void *p1, const void *p2);
int
proc_sort_by_state(const void *p1, const void *p2);
int
proc_sort_by_age(const void *p1, const void *p2);
#endif