pkg://Xdisk-0.8-2.src.rpm:18827/Xdisk-0.8.tar.gz
info downloads
Xdisk-0.8/ 40755 0 0 0 6173016641 10431 5 ustar root root Xdisk-0.8/Xdisk.cpp 100644 0 0 14614 6172537564 12355 0 ustar root root #include "Xdisk.hpp"
#include <qpainter.h>
#include <qevent.h>
#include <qpaintd.h>
#include <qpixmap.h>
#include <qfile.h>
#include <qfont.h>
#include <malloc.h>
#include <string.h>
// ----------------------------------------------------------------
Xdisk::Xdisk (QWidget *parent, const char *name, WFlags f,
char *label, QFont &font, int update, int scalevalue, int disks,
QColor &bgcolor, QColor &rdcolor, QColor &wrcolor,
QColor &sclcolor, QColor &lblcolor)
: QWidget (parent, name, f)
{
// Initialize meta object
initMetaObject();
// Initialize private data
write_color = wrcolor;
read_color = rdcolor;
back_color = bgcolor;
scale_color = sclcolor;
label_color = lblcolor;
frequency = update;
scale_value = scalevalue;
this->label = label;
this->font = font;
this->disks = disks;
data = NULL;
nb_data = 0;
read_new_data();
// Create timer
refreshTimer = new QTimer (this); // create internal timer
connect (refreshTimer, SIGNAL(timeout()), SLOT(timeToRefresh()));
refreshTimer->start (frequency * 1000); // refresh display every <frequency> seconds
}
// ----------------------------------------------------------------
Xdisk::~Xdisk ()
{
// Release timer and memory before dying
if (refreshTimer) {
refreshTimer->stop();
delete refreshTimer;
}
if (data) free (data);
}
// ----------------------------------------------------------------
void Xdisk::paintEvent (QPaintEvent *pe)
{
// if we're not visible there's no need to paint something
// am I right to test this ?
if (!isVisible()) return;
// no flickering with a pixmap
QPixmap pm (size());
QPainter p;
// begin painting the pixmap
pm.fill (back_color);
p.begin (&pm);
// draw text
if (label && *label) {
p.setPen (label_color);
p.setFont (font); // Why this doesn't work ? I have the same
// font every time, whatever 'font' is ...
// put it on the top-left corner
p.drawText (pm.rect(), AlignLeft | AlignTop, label);
}
// draw histograms
for (int i = 0; i < nb_data; i++) {
// hr,hw,hb are pixels value
int hr = (int)((float)data[i].read * ratio);
int hw = (int)((float)data[i].write * ratio);
if (hr+hw == 0) continue;
int hb = height() - hr - hw;
// begin from the top
p.moveTo (i, hb);
if (hw >= 1) {
p.setPen (write_color);
p.lineTo (i, hb+hw-1);
p.moveTo (i, hb+hw);
}
if (hr >= 1) {
p.setPen (read_color);
p.lineTo (i, height()-1);
}
}
// draw scale lines
p.setPen (scale_color);
for (int i = 0, j = scale_value; i < nb_scales; i++,j+=scale_value)
p.drawLine (0, height()-1-(int)(j*ratio),
width()-1,height()-1-(int)(j*ratio));
// that's all folks
p.end();
// put the pixmap on the widget
bitBlt (this, 0,0, &pm);
}
// ----------------------------------------------------------------
void Xdisk::resizeEvent (QResizeEvent *qr)
{
int new_width = qr->size().width();
int old_width = qr->oldSize().width();
// the first time we don't have anything
if (!data)
data = (RW_data*) calloc (new_width, sizeof(*data));
else {
// the widget grows, we put zero values at the left and move
// old data to the right
if (new_width > old_width) {
data = (RW_data*) realloc (data, new_width * sizeof(*data));
memmove (data + (new_width - old_width), data, old_width * sizeof(*data));
memset (data, 0, (new_width - old_width) * sizeof(*data));
// the widget shrink, we move data to the left to keep the
// most recent ones
} else if (new_width < old_width) {
memmove (data, data + (old_width - new_width), new_width * sizeof(*data));
data = (RW_data*) realloc (data, new_width * sizeof(*data));
// we could have erased the higher value, we have to
// rescale the histogram
compute_ratio();
}
}
nb_data = new_width;
}
// ----------------------------------------------------------------
// the timer slot :
// - read new data
// - compute new byte/pixel ratio
// - redraw all
void Xdisk::timeToRefresh ()
{
read_new_data();
compute_ratio();
repaint(FALSE); // avoid annoying flicker with 'update' or 'repaint(TRUE)'
}
// ----------------------------------------------------------------
// we compute the ratio byte/pixel and the number of scale lines
void Xdisk::compute_ratio ()
{
int maxval = 0;
for (int i=0; i < nb_data; i++) {
int sum = data[i].read + data[i].write;
if (maxval < sum)
maxval = sum;
}
nb_scales = (maxval + scale_value - 1) / scale_value;
maxval = nb_scales * scale_value - 1;
ratio = (float)height() / (float)maxval;
}
// ----------------------------------------------------------------
// read new data from /proc/stat (disk_rblk and disk_wblk)
// /proc/stat gives us cumulative data, we need to make a diff between
// successive values to gain real bytes/s
// note that /proc/stat give use sectors, not bytes but it's the same
// thing for us.
void Xdisk::read_new_data ()
{
int nb_read;
int nb_write;
int nb1, nb2, nb3, nb4;
char temp[250];
QFile *f;
f = new QFile ("/proc/stat");
if (f->open (IO_ReadOnly) == FALSE) return;
// disk-reads counter
do {
f->readLine (temp, sizeof(temp)-1);
} while (strncmp (temp, "disk_rblk", 7) != 0);
sscanf (&(temp[0])+9, "%d %d %d %d", &nb1, &nb2, &nb3, &nb4);
nb_read = 0;
if (disks & 1) nb_read += nb1;
if (disks & 2) nb_read += nb2;
if (disks & 4) nb_read += nb3;
if (disks & 8) nb_read += nb4;
// disk-writes counter
do {
f->readLine (temp, sizeof(temp)-1);
} while (strncmp (temp, "disk_wblk", 7) != 0);
sscanf (&(temp[0])+9, "%d %d %d %d", &nb1, &nb2, &nb3, &nb4);
nb_write = 0;
if (disks & 1) nb_write += nb1;
if (disks & 2) nb_write += nb2;
if (disks & 4) nb_write += nb3;
if (disks & 8) nb_write += nb4;
f->close();
delete f;
// when the constructor calls this routine, data hasn't been
// allocated, it just want to keep the current values
if (data) {
// move old data to the left to make room for a new
memmove (data, data+1, sizeof(*data) * (nb_data - 1));
// new data comes at the right most position
data[nb_data-1].read = nb_read - old_read;
data[nb_data-1].write = nb_write - old_write;
}
// keep cumulative data for the next time
old_read = nb_read;
old_write = nb_write;
}
Xdisk-0.8/Xdisk.hpp 100644 0 0 1755 6172536634 12341 0 ustar root root #ifndef Xdisk_HPP
#define Xdisk_HPP
// Widget displaying raw disk activity (ie: at the lowest level)
#include <qwidget.h>
#include <qcolor.h>
#include <qtimer.h>
#include <qfont.h>
class Xdisk : public QWidget
{
Q_OBJECT
public:
Xdisk (QWidget *parent, const char *name, WFlags f,
char *label, QFont &font, int update, int scalevalue, int disks,
QColor &bgcolor, QColor &rdcolor, QColor &wrcolor,
QColor &sclcolor, QColor &lblcolor);
~Xdisk ();
protected:
void paintEvent (QPaintEvent *);
void resizeEvent (QResizeEvent *);
private slots:
void timeToRefresh ();
private:
int frequency;
QTimer *refreshTimer;
struct RW_data { int read; int write; } *data;
int nb_data, old_read, old_write;
QColor read_color, write_color, back_color, scale_color, label_color;
int scale_value, nb_scales, disks;
float ratio;
char *label;
QFont font;
void read_new_data ();
void compute_ratio ();
};
#endif // Xdisk_HPP
Xdisk-0.8/Makefile 100644 0 0 2137 6172557754 12207 0 ustar root root INCDIR =/usr/lib/qt/include
CFLAGS =-O2 -m486 -fomit-frame-pointer -W -Wtemplate-debugging -Wparentheses \
-Wuninitialized -Wchar-subscripts -Wformat -Wtrigraphs -Wcomment \
-Wswitch -Wunused -Wreturn-type -Wimplicit -Wpointer-arith -Wsynth \
-Wconversion -Wno-overloaded-virtual \
-DNO_DEBUG -DNO_CHECK
LFLAGS =-lqt
CC =gcc -pipe
MOC =/usr/bin/moc
HEADERS =Xdisk.hpp
SOURCES =Xdisk.cpp main.cpp
OBJECTS =Xdisk.o main.o
SRCMETA =mXdisk.cpp
OBJMETA =mXdisk.o
TARGET =Xdisk
DISTRIB =Xdisk-0.8
.SUFFIXES:
.SUFFIXES: .cpp $(SUFFIXES)
.cpp.o:
$(CC) -c $(CFLAGS) -I$(INCDIR) $<
all: $(TARGET)
$(TARGET): $(OBJECTS) $(OBJMETA)
$(CC) $(OBJECTS) $(OBJMETA) -o $(TARGET) $(LFLAGS)
strip $(TARGET)
distribution: $(TARGET)
rm -f $(OBJECTS) $(SRCMETA) $(OBJMETA) *~ *.bak *% #*
tar czf ../$(DISTRIB).tar.gz ../$(DISTRIB)
showfiles:
@echo $(HEADERS) $(SOURCES) Makefile
depend: $(SOURCES)
@makedepend -I$(INCDIR) $(SOURCES) 2> /dev/null
clean:
-rm -f *.o *.bak *~ *% #*
-rm -f $(TARGET) $(SRCMETA)
mXdisk.cpp: Xdisk.hpp
$(MOC) -o mXdisk.cpp Xdisk.hpp
# DO NOT DELETE THIS LINE -- make depend depends on it.
Xdisk-0.8/Xdisk 100755 0 0 46074 6172560020 11563 0 ustar root root ELF 0# 4 H 4 ( 4 4 4 E E E U U D DG DW DW /lib/ld-linux.so.1 2 o - t ' 4 c Z # ; } h f d @ ? 9 * ] l e ( $ [ i 1 R ` . b I V W
8 T ! G O E u M \ v q k ~ Q "