diff options
| author | Wiimm <wiimm@wiimm.de> | 2022-05-13 19:22:13 +0200 |
|---|---|---|
| committer | Wiimm <wiimm@wiimm.de> | 2022-05-13 19:22:13 +0200 |
| commit | 568365f5bdd4dc71a156ca963d89ac002f405a34 (patch) | |
| tree | 730d0311536d8fd46a56b74e2c8cac028e778243 /project/dclib/dclib-file.h | |
| parent | 9ae8841ec4720e74173e2f72fac33f0848bbf435 (diff) | |
SZS v2.27a
Diffstat (limited to 'project/dclib/dclib-file.h')
| -rw-r--r-- | project/dclib/dclib-file.h | 164 |
1 files changed, 150 insertions, 14 deletions
diff --git a/project/dclib/dclib-file.h b/project/dclib/dclib-file.h index 041929d..f9dd2fc 100644 --- a/project/dclib/dclib-file.h +++ b/project/dclib/dclib-file.h @@ -14,16 +14,16 @@ * * *************************************************************************** * * - * Copyright (c) 2012-2021 by Dirk Clemens <wiimm@wiimm.de> * + * Copyright (c) 2012-2022 by Dirk Clemens <wiimm@wiimm.de> * * * *************************************************************************** * * - * This program is free software; you can redistribute it and/or modify * + * This library is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * - * This program is distributed in the hope that it will be useful, * + * This library is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * @@ -44,6 +44,63 @@ // /////////////////////////////////////////////////////////////////////////////// +/////////////// log helpers /////////////// +/////////////////////////////////////////////////////////////////////////////// + +#define TRY_OPEN_FILE ((FILE*)1) +#define SETUP_TRY_OPEN_FILE(f,fname,mode) \ + static FILE *f = TRY_OPEN_FILE; f = TryOpenFile(f,fname,mode) + +FILE * TryOpenFile ( FILE *f, ccp fname, ccp mode ); + +//----------------------------------------------------------------------------- +// [[TimestampMode_t] + +typedef enum TimestampMode_t +{ + TSM_OFF, // no timestamp + TSM_SEC, // timstamp HH:MM:SS + TSM_MSEC, // timstamp HH:MM:SS.123 + TSM_USEC, // timstamp HH:MM:SS.123456 +} +TimestampMode_t; + +//----------------------------------------------------------------------------- +// [[LogFile_t] + +typedef struct LogFile_t +{ + FILE *log; // NULL or log file + mem_t tag; // A string to print before message + TimestampMode_t ts_mode; // How to print the timestamp + bool flush; // TRUE: fflush() for each log +} +LogFile_t; + +//----------------------------------------------------------------------------- + +extern LogFile_t GlobalLogFile; + +int GetLogTimestamp ( char *buf, uint buf_size, TimestampMode_t ts_mode ); +int PrintLogTimestamp ( LogFile_t *lf ); + +int PutLogFile ( LogFile_t *lf, ccp text, int text_len ); +int PrintArgLogFile ( LogFile_t *lf, ccp format, va_list arg ); +int PrintLogFile ( LogFile_t *lf, ccp format, ... ) + __attribute__ ((__format__(__printf__,2,3))); + +//----------------------------------------------------------------------------- + +exmem_t SearchToolByPATH ( ccp tool ); +exmem_t SearchToolByList ( ccp * list, int max ); // max<0: NULL is list terminator + +FILE * OpenPipeToPager(); +void ClosePagerFile(); +bool StdoutToPager(); +void CloseStdoutToPager(); + +// +/////////////////////////////////////////////////////////////////////////////// /////////////// enum FileMode_t /////////////// /////////////////////////////////////////////////////////////////////////////// // [[FileMode_t]] @@ -750,7 +807,6 @@ typedef struct TraceLog_t ccp fname; // name of file to open FILE *log; // NULL or open log file int level; // log level, don't log if <0 - } TraceLog_t; @@ -892,6 +948,7 @@ int ExistDirectory bool IsSameFilename ( ccp fn1, ccp fn2 ); /////////////////////////////////////////////////////////////////////////////// +// [[FindConfigFile_t]] typedef enum FindConfigFile_t { @@ -1008,11 +1065,17 @@ uint NumberedFilename #endif +/////////////////////////////////////////////////////////////////////////////// + +// return a string of the internal cache +// if ret_level: store level here. +ccp GetBlockDeviceHolder ( ccp name, ccp sep, int *ret_level ); + // /////////////////////////////////////////////////////////////////////////////// /////////////// normalize filenames /////////////// /////////////////////////////////////////////////////////////////////////////// -// [[trailing_slash]] +// [[trailing_slash]] typedef enum trailing_slash { @@ -1180,8 +1243,11 @@ typedef struct FDList_t { bool use_poll; // false: use select(), true: use poll() - u64 now_usec; // set on Clear() and Wait(), result of GetTimeUSec(false) - u64 timeout_usec; // next timeout, based on GetTimeUSec(false) + u_usec_t now_usec; // set on Clear() and Wait(), result of GetTimeUSec(false) + u_usec_t timeout_usec; // next timeout, based on GetTimeUSec(false) (TIME!) + u_nsec_t timeout_nsec; // next timeout, based on GetTimerNSec() (TIMER!) + u_usec_t min_wait_usec; // if >0: minimal waiting time (increment 'timeout_usec') + //--- select() params @@ -1198,11 +1264,12 @@ typedef struct FDList_t //--- statistics + FILE *debug_file; // not NULL: print debug line each select() and poll() uint n_sock; // current number of registered sockets // equals poll_used if poll is used uint wait_count; // total number of waits - u64 wait_usec; // total wait time in usec - u64 cur_usec; // current wait time in usec + u_usec_t wait_usec; // total wait time in usec + u_usec_t last_wait_usec; // last wait time in usec } FDList_t; @@ -1222,14 +1289,14 @@ uint AddFDList ( // returns the pool-index if available, ~0 otherwise - FDList_t *fdl, // valid socket list - int sock, // socket to add - uint events // bit field: POLLIN|POLLOUT|POLLERR + FDList_t *fdl, // valid socket list + int sock, // socket to add + uint events // bit field: POLLIN|POLLPRI|POLLOUT|POLLRDHUP|... ); uint GetEventFDList ( - // returns bit field: POLLIN|POLLOUT|POLLERR + // returns bit field: POLLIN|POLLOUT|POLLERR|... FDList_t *fdl, // valid socket list int sock, // socket to look for @@ -1506,7 +1573,7 @@ typedef struct PrintScript_t ccp var_name; // NULL or variable name for result ccp var_prefix; // NULL or prefix for member names int var_size; // if > 0: print size of var name (some 'fform' only) - int eq_tabstop; // if > 0: indent '=' to set tabstop (some 'fform' only) + int eq_tabstop; // if > 0: indent '=' to set tabstop (some 'fform' only) LowerUpper_t force_case; // change case of var names if not LOUP_AUTO bool create_array; // true: create ar arrays bool auto_quote; // true: detect quotes and use EscapeString() @@ -1552,6 +1619,75 @@ __attribute__ ((__format__(__printf__,3,4))); // /////////////////////////////////////////////////////////////////////////////// +/////////////// CpuStatus_t /////////////// +/////////////////////////////////////////////////////////////////////////////// +// [[CpuStatus_t]] + +typedef struct CpuStatus_t +{ + bool valid; // TRUE: data valid (setup done) + u_nsec_t nsec; // GetTimerNSec() + int clock_ticks; // number of clock ticks per second + int n_cpu; // total number of cpus + + // all times in 1e4 ticks per second (in 0.01%) + u64 user; // time spent in user mode. + u64 nice; // time spent in user mode with low priority. + u64 system; // time spent in system mode. + u64 idle; // time spent in the idle task. + + int running_proc; // currently runnable processes + int total_proc; // currently total processes + + union + { + struct + { + double loadavg_1m; // load average last minute + double loadavg_5m; // load average last 5 minutes + double loadavg_15m; // load average last 12 minutes + }; + + double loadavg[3]; // load average as array + }; +} +CpuStatus_t; + +//----------------------------------------------------------------------------- + +// prev_cpuinfo == NULL: get absolute values +// prev_cpuinfo != NULL: update 'prev_cpuinfo' and get delta +CpuStatus_t GetCpuStatus ( CpuStatus_t * prev_cpuinfo ); + +ccp PrintCpuStatus ( const CpuStatus_t * cpuinfo ); + +// +/////////////////////////////////////////////////////////////////////////////// +/////////////// MemoryStatus_t /////////////// +/////////////////////////////////////////////////////////////////////////////// +// [[MemoryStatus_t]] + +typedef struct MemoryStatus_t +{ + // man 5 proc | oo +//proc/meminfo + + u64 total; // Total usable RAM. + u64 free; // The sum of LowFree + HighFree. + u64 avail; // An estimate of available memory for starting new applications. + u64 buffers; // Relatively temporary storage. + u64 cached; // In-memory cache for files read from the disk. + + u64 used; // = total - free - buffers - cached; +} +MemoryStatus_t; + +//----------------------------------------------------------------------------- + +MemoryStatus_t GetMemoryStatus(void); +ccp PrintMemoryStatus ( const MemoryStatus_t * ms ); + +// +/////////////////////////////////////////////////////////////////////////////// /////////////// E N D /////////////// /////////////////////////////////////////////////////////////////////////////// |
