diff --git a/CMakeLists.txt b/CMakeLists.txt index 3cf389d3..d721a627 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -51,6 +51,48 @@ set(CMAKE_AUTOMOC ON) set(CMAKE_AUTOUIC ON) set(CMAKE_AUTORCC ON) +include(CheckCXXCompilerFlag) + +set(AVX_SUPPORTED FALSE) +set(AVX_COMPILER_FLAG "") + +# Prioritize AVX2 as it's more capable than AVX1. +# Common flags for AVX2: -march=haswell (for Intel), -mavx2 (generic) +CHECK_CXX_COMPILER_FLAG("-march=haswell" CXX_SUPPORTS_HASWELL) +CHECK_CXX_COMPILER_FLAG("-mavx2" CXX_SUPPORTS_AVX2) + +if(CXX_SUPPORTS_HASWELL) + set(AVX_SUPPORTED TRUE) + set(AVX_COMPILER_FLAG "-march=haswell") + message(STATUS "AVX2 (Haswell) support detected. Adding compiler flag: ${AVX_COMPILER_FLAG}") +elseif(CXX_SUPPORTS_AVX2) + set(AVX_SUPPORTED TRUE) + set(AVX_COMPILER_FLAG "-mavx2") + message(STATUS "Generic AVX2 support detected. Adding compiler flag: ${AVX_COMPILER_FLAG}") +else() + # Common flags for AVX1: -march=sandybridge (for Intel), -mavx (generic) + CHECK_CXX_COMPILER_FLAG("-march=sandybridge" CXX_SUPPORTS_SANDYBRIDGE) + CHECK_CXX_COMPILER_FLAG("-mavx" CXX_SUPPORTS_AVX) + + if(CXX_SUPPORTS_SANDYBRIDGE) + set(AVX_SUPPORTED TRUE) + set(AVX_COMPILER_FLAG "-march=sandybridge") + message(STATUS "AVX1 (Sandy Bridge) support detected. Adding compiler flag: ${AVX_COMPILER_FLAG}") + elseif(CXX_SUPPORTS_AVX) + set(AVX_SUPPORTED TRUE) + set(AVX_COMPILER_FLAG "-mavx") + message(STATUS "Generic AVX1 support detected. Adding compiler flag: ${AVX_COMPILER_FLAG}") + else() + message(STATUS "Neither AVX1 nor AVX2 support detected. No specific AVX compiler flags added.") + endif() +endif() + +if(AVX_SUPPORTED) + add_compile_options(${AVX_COMPILER_FLAG}) +else() + message(STATUS "Building without specific AVX optimizations.") +endif() + add_subdirectory(src) # install the man page diff --git a/src/details.cpp b/src/details.cpp index f1dec5c6..1b7eee5c 100644 --- a/src/details.cpp +++ b/src/details.cpp @@ -144,15 +144,15 @@ Lookup *Sockets::lookup = nullptr; TableField *Sockets::fields() { - static QList< TableField > fields( { { tr( "Fd" ), 5, 8, Qt::AlignRight, tr( "File descriptor" ) } - , { tr( "Proto" ), 4, 8, Qt::AlignLeft, tr( "Protocol (TCP or UDP)" ) } - , { tr( "Recv-Q" ), 9, 8, Qt::AlignRight, tr( "Bytes in receive queue" ) } - , { tr( "Send-Q" ), 9, 8, Qt::AlignRight, tr( "Bytes in send queue" ) } - , { tr( "Local Addr" ), -1, 8, Qt::AlignLeft, tr( "Local IP address" ) } - , { tr( "Port" ), 6, 8, Qt::AlignLeft, tr( "Local port" ) } - , { tr( "Remote Addr" ), -1, 8, Qt::AlignLeft, tr( "Remote IP address" ) } - , { tr( "Port" ), 6, 8, Qt::AlignLeft, tr( "Remote port" ) } - , { tr( "State" ), 18, 8, Qt::AlignLeft, tr( "Connection state" ) } } ); + static QList< TableField > fields( { { tr( "Fd" ), tr( "File descriptor" ), 5, 8, Qt::AlignRight } + , { tr( "Proto" ), tr( "Protocol (TCP or UDP)" ), 4, 8, Qt::AlignLeft } + , { tr( "Recv-Q" ), tr( "Bytes in receive queue" ), 9, 8, Qt::AlignRight } + , { tr( "Send-Q" ), tr( "Bytes in send queue" ), 9, 8, Qt::AlignRight } + , { tr( "Local Addr" ), tr( "Local IP address" ), -1, 8, Qt::AlignLeft } + , { tr( "Port" ), tr( "Local port" ), 6, 8, Qt::AlignLeft } + , { tr( "Remote Addr" ), tr( "Remote IP address" ), -1, 8, Qt::AlignLeft } + , { tr( "Port" ), tr( "Remote port" ), 6, 8, Qt::AlignLeft } + , { tr( "State" ), tr( "Connection state" ), 18, 8, Qt::AlignLeft } } ); return fields.data(); } @@ -389,13 +389,13 @@ void Sockets::update_hostname(unsigned int) {} #endif TableField *Maps::fields() { - static QList< TableField > fields( { { tr( "Address Range" ), -1, 8, Qt::AlignLeft, tr( "Mapped addresses (hex) )" ) } - , { tr( "Size" ), 8, 8, Qt::AlignRight, tr( "Kbytes mapped (dec)" ) } - , { tr( "Perm" ), 5, 8, Qt::AlignLeft, tr( "Permission flags" ) } - , { tr( "Offset" ), -1, 8, Qt::AlignRight, tr( "File offset at start of mapping (hex)" ) } - , { tr( "Device" ), 8, 8, Qt::AlignLeft, tr( "Major,Minor device numbers (dec)" ) } - , { tr( "Inode" ), 10, 8, Qt::AlignRight, tr( "Inode number (dec)" ) } - , { tr( "File" ), -9, 8, Qt::AlignLeft, tr( "File name (if available)" ) } } ); + static QList< TableField > fields( { { tr( "Address Range" ), tr( "Mapped addresses (hex) )" ), -1, 8, Qt::AlignLeft } + , { tr( "Size" ), tr( "Kbytes mapped (dec)" ), 8, 8, Qt::AlignRight } + , { tr( "Perm" ), tr( "Permission flags" ), 5, 8, Qt::AlignLeft } + , { tr( "Offset" ), tr( "File offset at start of mapping (hex)" ), -1, 8, Qt::AlignRight } + , { tr( "Device" ), tr( "Major,Minor device numbers (dec)" ), 8, 8, Qt::AlignLeft } + , { tr( "Inode" ), tr( "Inode number (dec)" ), 10, 8, Qt::AlignRight } + , { tr( "File" ), tr( "File name (if available)" ), -9, 8, Qt::AlignLeft } } ); return fields.data(); } @@ -459,7 +459,7 @@ QString Maps::text(int row, int col) s.setNum(mi->inode); break; case FILENAME: - s = mi->filename; + s = QString(mi->filename); if (!Qps::show_file_path) { int i = s.lastIndexOf('/'); @@ -492,11 +492,11 @@ bool Maps::refresh_maps() { return procinfo()->read_maps(); } TableField *Files::fields() { - static QList< TableField > fields( { { tr( "Fd" ), 5, 8, Qt::AlignRight, tr( "File descriptor" ) } + static QList< TableField > fields( { { tr( "Fd" ), tr( "File descriptor" ), 5, 8, Qt::AlignRight } #ifdef LINUX - , { tr( "Mode" ), 3, 8, Qt::AlignLeft, tr( "Open mode" ) } + , { tr( "Mode" ), tr( "Open mode" ), 3, 8, Qt::AlignLeft } #endif - , { tr( "Name" ), -1, 8, Qt::AlignLeft, tr( "File name (if available)" )} } ); + , { tr( "Name" ), tr( "File name (if available)" ), -1, 8, Qt::AlignLeft } } ); return fields.data(); } @@ -576,8 +576,8 @@ QString Files::text(int row, int col) TableField *Environ::fields() { - static QList< TableField > fields( { { tr( "Variable" ), -1, 8, Qt::AlignLeft, tr( "Variable name" ) } - , { tr( "Value" ), -1, 8, Qt::AlignLeft, tr( "Variable value" ) } } ); + static QList< TableField > fields( { { tr( "Variable" ), tr( "Variable name" ), -1, 8, Qt::AlignLeft } + , { tr( "Value" ), tr( "Variable value" ), -1, 8, Qt::AlignLeft } } ); return fields.data(); } @@ -624,9 +624,9 @@ void Environ::refresh() TableField *AllFields::fields() { - static QList< TableField > fields( { { tr( "Field" ), -1, 8, Qt::AlignLeft, tr( "Field name" ) } - , { tr( "Description" ), -1, 8, Qt::AlignLeft, tr( "Field description" ) } - , { tr( "Value" ), -1, 8, Qt::AlignLeft, tr( "Field value" ) } } ); + static QList< TableField > fields( { { tr( "Field" ), tr( "Field name" ), -1, 8, Qt::AlignLeft } + , { tr( "Description" ), tr( "Field description" ), -1, 8, Qt::AlignLeft } + , { tr( "Value" ), tr( "Field value" ), -1, 8, Qt::AlignLeft } } ); return fields.data(); } diff --git a/src/details.h b/src/details.h index b6ce50e6..53f1e0a5 100644 --- a/src/details.h +++ b/src/details.h @@ -107,7 +107,7 @@ class Sockets : public SimpleTable QString text(int row, int col) override; private: - enum + enum : unsigned char { FD, PROTO, @@ -143,7 +143,7 @@ class Maps : public SimpleTable QString text(int row, int col) override; private: - enum + enum : unsigned char { ADDRESS, SIZE, @@ -171,7 +171,7 @@ class Files : public SimpleTable QString text(int row, int col) override; private: - enum + enum : unsigned char { FILEDESC, #ifdef LINUX @@ -197,7 +197,7 @@ class Environ : public SimpleTable QString text(int row, int col) override; private: - enum + enum : unsigned char { ENVNAME, ENVVALUE, @@ -220,7 +220,7 @@ class AllFields : public SimpleTable QString text(int row, int col) override; private: - enum + enum : unsigned char { FIELDNAME, FIELDDESC, diff --git a/src/htable.cpp b/src/htable.cpp index f2fc7c0d..f4c4742e 100644 --- a/src/htable.cpp +++ b/src/htable.cpp @@ -265,7 +265,7 @@ bool TableBody::isCellChanged(int row, int col) else { bool result = false; - if (attr->text == str and attr->selected == selected and + if (attr->text == str.data() and attr->selected == selected and attr->sorted == sorted and attr->xpos == xpos and attr->w == width // and attr->size==tmp_size and @@ -336,10 +336,10 @@ bool TableHead::isCellChanged(int row, int col) { result = true; } - else if (attr->text != str || attr->sorted != sorted + else if (attr->text != str.data() || attr->sorted != sorted || attr->size != tmp_size || attr->xpos != xpos) { - attr->text = str; + attr->text = str.data(); attr->sorted = sorted; attr->xpos = xpos; attr->size = tmp_size; @@ -482,7 +482,7 @@ void TableBody::paintCell(QPainter *p, int row, int col) p->drawText(gap, 0, w, h, align, htable->text(row, col)); // cache write! - attr->text = htable->text(row, col); + attr->text = htable->text(row, col).data(); attr->xpos = htable->colXPos(col); attr->size = tmp_size; } @@ -923,7 +923,7 @@ void TableCache::setRow(int row) for (i = row; i < nrow; i++) { for (int j = 0; j < 48; j++) - rows[i]->cells[j].text = ""; + rows[i]->cells[j].text = reinterpret_cast(""); } } nrow = row; @@ -939,7 +939,7 @@ void TableCache::setCol(int col) int i, size = rows.size(); for (i = 0; i < size; i++) for (int j = col; j < ncol; j++) - rows[i]->cells[j].text = ""; + rows[i]->cells[j].text = reinterpret_cast(""); } ncol = col; } diff --git a/src/htable.h b/src/htable.h index 9f10508c..08ea89f1 100644 --- a/src/htable.h +++ b/src/htable.h @@ -46,21 +46,21 @@ class HeadedTable; class CellAttribute { public: - QString text; - bool selected; - bool sorted; + const QChar *text; QSize size; QColor backColor; // table share QColor foreColor; // rows share - int xpos; // cols share - int ypos; // rows share - int w; // cols share - int depth; // rows share - int folded; // - int lastchild; // + unsigned short xpos; // cols share + unsigned short ypos; // rows share + unsigned short w; // cols share + unsigned short depth; // rows share + unsigned short folded; // + unsigned short lastchild; // + bool selected; + bool sorted; CellAttribute() { - text = ""; + text = nullptr; sorted = selected = false; xpos = -1, ypos = -1, w = 0, depth = -1, folded = -1; lastchild = 0; @@ -212,7 +212,7 @@ class TableBody : public QtTableView int first_drag_row; // row where drag started int prev_drag_row; // row where drag was at last event bool autoscrolling; // true if we are autoscrolling right now - enum + enum : unsigned char { UP, DOWN @@ -237,7 +237,7 @@ class HeadedTable : public QWidget TableBody *body; CellAttribute *attr; // DEL temporarily buffer - enum NodeState + enum NodeState : unsigned char { Leaf, Open, diff --git a/src/infobar.h b/src/infobar.h index 68e41494..3e4b1feb 100644 --- a/src/infobar.h +++ b/src/infobar.h @@ -173,22 +173,22 @@ class GraphBase : public QWidget virtual QString doHistoryTXT(SysHistory *sysh); Procview *procview; - int official_height; - int npoints; // nr of history points currently remembered + unsigned short official_height; + unsigned short npoints; // nr of history points currently remembered private: // history points are stored in fixed point, scaled by history_scale static const unsigned int history_scale = 256; - int hist_size; // history buffer size DEL - float *history; // (circular) history buffer DEL - int h_index; // next history index to use float peak; // largest value in history + float *history; // (circular) history buffer DEL + unsigned short hist_size; // history buffer size DEL + unsigned short h_index; // next history index to use + + unsigned short px, py; // pointer position bool dirty; // history changed since pixmap was drawn QPixmap pixmap; QPixmap icon_pm; - - int px, py; // pointer position }; class IO_Graph : public GraphBase diff --git a/src/misc.cpp b/src/misc.cpp index 114099c7..f22cc829 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -38,17 +38,32 @@ extern bool flag_thread_ok; #include #include +#ifdef __AVX2__ +#include +#endif + // 300% faster than glibc (by fasthyun@magicn.com) int x_atoi(const char *sstr) { const char *str = sstr; int val = 0; +#ifdef __AVX2__ + __m256i val_vec = _mm256_setzero_si256(); + __m256i ten_vec = _mm256_set1_epi32(10); + while (*str && (str[0] >= '0' && str[0] <= '9')) { + val_vec = _mm256_mullo_epi32(val_vec, ten_vec); + val_vec = _mm256_add_epi32(val_vec, _mm256_set1_epi32(*str - '0')); + str++; + } + val = _mm256_extract_epi32(val_vec, 0); // Extract the first integer +#else while (*str) { val *= 10; val += *str - 48; str++; } +#endif return val; } diff --git a/src/misc.h b/src/misc.h index b058ab8f..43475ad0 100644 --- a/src/misc.h +++ b/src/misc.h @@ -49,8 +49,10 @@ #include #include -char *userName(int uid, int euid); -char *groupName(int gid, int egid); +int x_atoi(const char *sstr); + +const QString userName(int uid, int euid); +const QString groupName(int gid, int egid); void setQpsTheme(); @@ -116,7 +118,7 @@ class TBloon : public QLabel // virtual void moveEvent (QMoveEvent * event ); private: QWidget *paren; - QString text; + const QChar *text; QTimeLine *timeLine; }; diff --git a/src/prefs.cpp b/src/prefs.cpp index 00b80f27..7d9e4e7c 100644 --- a/src/prefs.cpp +++ b/src/prefs.cpp @@ -23,6 +23,7 @@ #include "prefs.h" #include "proc.h" #include "qps.h" +#include "misc.h" #include #include #include @@ -47,12 +48,12 @@ struct Boxvar { Q_DECLARE_TR_FUNCTIONS(Boxvar) public: - const QString text; + const QChar *text; bool *variable; QCheckBox *cb; - Boxvar() : text( QString() ), variable( static_cast< bool * >( nullptr ) ), cb( static_cast< QCheckBox *>( nullptr ) ) {} - Boxvar( const QString t, bool *v, QCheckBox *c ) : text( t ), variable( v ), cb( c ) {} + Boxvar() : text( nullptr ), variable( static_cast< bool * >( nullptr ) ), cb( static_cast< QCheckBox *>( nullptr ) ) {} + Boxvar( const QString &t, bool *v, QCheckBox *c ) : text( t.constData() ), variable( v ), cb( c ) {} static QList< Boxvar > *general_boxes() { @@ -95,11 +96,11 @@ struct Cbgroup { Q_DECLARE_TR_FUNCTIONS(Cbgroup) public: - const QString caption; + const QChar *caption; QList< Boxvar > *boxvar; - Cbgroup() : caption( QString() ), boxvar( static_cast< QList< Boxvar > * >( nullptr ) ) {} - Cbgroup( const QString c, QList< Boxvar > *b ) : caption( c ), boxvar( b ) {} + Cbgroup() : caption( nullptr ), boxvar( static_cast< QList< Boxvar > * >( nullptr ) ) {} + Cbgroup( const QString &c, QList< Boxvar > *b ) : caption( c.constData() ), boxvar( b ) {} static QList< Cbgroup > &groups() { @@ -126,8 +127,8 @@ QValidator::State Swapvalid::validate(QString &s, int &) const s[i] = 'K'; if (s[i] == 'm') s[i] = 'M'; - // int val = atoi((const char *)s); - int val = s.toInt(); + int val = x_atoi(s.toUtf8().constData()); + //int val = s.toInt(); bool percent; if (s[i] == '%') { @@ -166,14 +167,14 @@ Preferences::Preferences(QWidget *parent) : QDialog(parent) QList< Cbgroup >::iterator endItG = Cbgroup::groups().end(); for( QList< Cbgroup >::iterator itG = Cbgroup::groups().begin(); itG != endItG; ++ itG ) { - QGroupBox *grp = new QGroupBox( itG->caption, this ); + QGroupBox *grp = new QGroupBox( *itG->caption, this ); QVBoxLayout *vbox = new QVBoxLayout; if ( itG->boxvar ) { QList< Boxvar >::iterator endItB = itG->boxvar->end(); for( QList< Boxvar >::iterator itB = itG->boxvar->begin(); itB != endItB; ++ itB ) { - itB->cb = new QCheckBox( itB->text, grp ); + itB->cb = new QCheckBox( *itB->text, grp ); vbox->addWidget( itB->cb ); connect( itB->cb, &QAbstractButton::clicked, this, &Preferences::update_reality); } diff --git a/src/proc.cpp b/src/proc.cpp index 8ade56a5..20c71c7e 100644 --- a/src/proc.cpp +++ b/src/proc.cpp @@ -56,6 +56,7 @@ #include "uidstr.h" #include "ttystr.h" #include "wchan.h" +#include "misc.h" #include #include @@ -75,10 +76,10 @@ bool Procview::flag_show_file_path = false; bool Procview::flag_cumulative = false; // times cumulative with children's bool Procview::flag_pcpu_single = false; // %CPU= pcpu/num_cpus int pagesize; -int Proc::update_msec = 1024; +unsigned short Proc::update_msec = 1024; // socket states, from and touched to avoid name collisions -enum +enum : unsigned char { SSFREE = 0, /* not allocated */ SSUNCONNECTED, /* unconnected to any socket */ @@ -325,7 +326,7 @@ int Cat_int::compare(Procinfo *a, Procinfo *b) // COMMON Cat_percent::Cat_percent(const QString &heading, const QString &explain, int w, float Procinfo::*member) - : Category(heading, explain), float_member(member), field_width(w) + : Category(heading, explain), field_width(w), float_member(member) { } @@ -1312,7 +1313,7 @@ int Proc::read_pid_tasks(int pid) if (e->d_name[0] == '.') continue; // skip "." , ".." - thread_pid = atoi(e->d_name); + thread_pid = x_atoi(e->d_name); if (pid == thread_pid) continue; // skip @@ -2140,7 +2141,7 @@ bool Procinfo::read_fds() { if (e->d_name[0] == '.') continue; - int fdnum = atoi(e->d_name); + int fdnum = x_atoi(e->d_name); std::string str(path); str.append(e->d_name); read_fd(fdnum, str.c_str()); @@ -2312,10 +2313,10 @@ bool Procinfo::read_maps() line[len - 1] = '\0'; while (line[n] == ' ' && line[n]) n++; - mi->filename = line + n; + mi->filename = reinterpret_cast(line + n); } else if ((mi->major | mi->minor | mi->inode) == 0) - mi->filename = "(anonymous)"; + mi->filename = QString::fromLocal8Bit("(anonymous)").constData(); maps.append(mi); } fclose(f); @@ -2759,7 +2760,7 @@ void Proc::read_proc_all() int pid; Procinfo *pi = nullptr; - pid = atoi(e->d_name); + pid = x_atoi(e->d_name); pi = procs.value(pid, NULL); diff --git a/src/proc.h b/src/proc.h index 0b1f64c2..63242323 100644 --- a/src/proc.h +++ b/src/proc.h @@ -45,7 +45,7 @@ void check_system_requirement(); int get_kernel_version(); //#define F_PID 0x00000000 -enum fields +enum fields : char { F_PID = 0, #ifdef LINUX @@ -133,7 +133,7 @@ class Details; class Sockinfo { public: - enum proto_t + enum proto_t : unsigned char { TCP, UDP @@ -183,7 +183,7 @@ class Mapsinfo unsigned long from, to; unsigned long offset; unsigned long inode; - QString filename; // null if name unknown + const QChar *filename; // null if name unknown char perm[4]; // "rwx[ps]"; last is private/shared flag unsigned minor, major; }; @@ -225,8 +225,8 @@ class Category QString name; QString help; - int index; - int id; + unsigned short index; + unsigned short id; bool reversed; // testing bool flag_int_value; // testing: for total sum , cat_memory , cat_int }; @@ -434,8 +434,8 @@ class Cat_percent : public Category int compare(Procinfo *a, Procinfo *b) override; protected: + unsigned short field_width; float Procinfo::*float_member; - int field_width; }; class Cat_tty : public Cat_string @@ -496,13 +496,19 @@ class Procinfo // Process Infomation QList sock_inodes; // socket inodes or NULL if not read #endif - int pid; - bool clone; - - bool first_run; // for optimization - char hashstr[128 * 8]; // cache size_t hashlen; int hashcmp(char *str); + char hashstr[128 * 8]; // cache + bool first_run; // for optimization + + bool clone; + char state; + + bool accepted; + int test_stop; // for test + int session; // ??? + + int pid; QString command; // COMMAND QString cmdline; // COMMAND_LINE @@ -511,14 +517,9 @@ class Procinfo // Process Infomation QString cwd; // null if not read QString root; // null if not read - bool accepted; - int test_stop; // for test - int session; // ??? - int uid, euid; int gid, egid; - char state; int ppid; // Parent's PID int pgrp; dev_t tty; // tty major:minor device @@ -528,18 +529,23 @@ class Procinfo // Process Infomation int tgid; // thread leader's id #ifdef LINUX - double tms; // slice time int slpavg; + double tms; // slice time unsigned long affcpu; int suid, fsuid; int sgid, fsgid; - int tpgid; unsigned long cminflt; unsigned long cmajflt; + + int tpgid; #endif + // Linux: the cpu used most of the time of the process + // Solaris: the cpu on which the process last ran + int which_cpu; + unsigned long io_read; // KB unsigned long io_write; // KB unsigned long io_read_KBps; // K byte/sec @@ -587,10 +593,6 @@ class Procinfo // Process Infomation int policy; // -1 = uninitialized int rtprio; // 0-99, higher can pre-empt lower (-1 = uninitialized) - // Linux: the cpu used most of the time of the process - // Solaris: the cpu on which the process last ran - int which_cpu; - // computed %cpu and %mem since last update float wcpu, old_wcpu; // %WCPUwheight cpu float pcpu; // %CPU: percent cpu after last update @@ -613,11 +615,12 @@ class Procinfo // Process Infomation bool hidekids : 1; // true if children are hidden in tree view bool lastchild : 1; // true if last (visible) child in tree view + char refcnt; + short level; // distance from process root QList children; // real child processes static const int MAX_CMD_LEN = 512; - char refcnt; // virtual child for Table_Tree QList table_children; @@ -696,31 +699,35 @@ Q_DECLARE_TR_FUNCTIONS(Proc) #ifdef SOLARIS static kstat_ctl_t *kc; // NULL if kstat not opened #endif + + unsigned short maxSizeHistory; + unsigned int current_gen; + QHash categories; Proclist procs; // processes indexed by pid // TESTING - QString supasswd; // test - int syshistoryMAX; - Proclist *hprocs; // temp_hprocs list - Proclist *mprocs; // - QList history; + [[maybe_unused]] QString supasswd; // test + [[maybe_unused]] int syshistoryMAX; + [[maybe_unused]] Proclist *hprocs; // temp_hprocs list + [[maybe_unused]] Proclist *mprocs; // + [[maybe_unused]] QList history; void setHistory(int tick); Proclist getHistory(int pos); - int qps_pid; // test - float loadQps; // TEST - static int update_msec; + [[maybe_unused]] int qps_pid; // test + [[maybe_unused]] float loadQps; // TEST + static unsigned short update_msec; // class - int num_cpus; // current number of CPUs - int old_num_cpus; // previous number of CPUs + unsigned short num_cpus; // current number of CPUs + unsigned short old_num_cpus; // previous number of CPUs + unsigned int num_process; // number of process long num_network_process; // number of network(socket) process long num_opened_files; // number of opened normal(not socket) files - int num_process; // number of process long dt_total; // long dt_used; // cpu used time in clktick @@ -735,8 +742,8 @@ Q_DECLARE_TR_FUNCTIONS(Proc) unsigned int clk_tick; // the number of clock ticks per second. unsigned int boot_time; // boot time in seconds since the Epoch - int mem_total, mem_free; // (Kb) - int swap_total, swap_free; // in kB + unsigned int mem_total, mem_free; // (Kb) + unsigned int swap_total, swap_free; // in kB int mem_available, mem_shared, mem_buffers, mem_cached; // Linux @@ -762,7 +769,7 @@ Q_DECLARE_TR_FUNCTIONS(Proc) #endif // Solaris #defines CPU_xxx so we must avoid them - enum + enum : unsigned char { CPUTIME_USER, #ifdef LINUX @@ -777,9 +784,6 @@ Q_DECLARE_TR_FUNCTIONS(Proc) }; //#define CPU_TIMES(cpu, kind) cpu_times_vec[cpu * CPUTIMES + kind] - - unsigned int current_gen; - int maxSizeHistory; }; class Procview : public Proc @@ -839,7 +843,7 @@ class Procview : public Proc static bool treeview; // true if viewed in tree form bool enable; // tmp - enum procstates + enum procstates : unsigned char { ALL, OWNED, @@ -848,7 +852,7 @@ class Procview : public Proc HIDDEN, NETWORK }; - enum fieldstates + enum fieldstates : unsigned char { USER = HIDDEN + 1, JOBS, diff --git a/src/qps.h b/src/qps.h index d8b69447..0b68808b 100644 --- a/src/qps.h +++ b/src/qps.h @@ -100,7 +100,7 @@ class Qps : public QWidget static bool flag_qps_hide; // colors which may be set by the user - enum + enum : unsigned char { COLOR_CPU_USER, #ifdef LINUX @@ -126,7 +126,7 @@ class Qps : public QWidget NUM_COLORS }; - enum menuid + enum menuid : unsigned char { MENU_SIGQUIT, MENU_SIGILL, diff --git a/src/qttableview.cpp b/src/qttableview.cpp index a2c61bc5..396b9381 100644 --- a/src/qttableview.cpp +++ b/src/qttableview.cpp @@ -35,7 +35,7 @@ #include "qttableview.h" -enum ScrollBarDirtyFlags +enum ScrollBarDirtyFlags : unsigned char { verSteps = 0x02, verRange = 0x04, diff --git a/src/tablefield.h b/src/tablefield.h index 787eb6b1..61baf796 100644 --- a/src/tablefield.h +++ b/src/tablefield.h @@ -27,11 +27,11 @@ struct TableField { - QString name; - int width; - int gap; - int align; - QString tooltip; + const QString name; + const QString tooltip; + short width; + unsigned short gap; + unsigned short align; }; #endif // TABLEFIELD_H