From 79518592e431fc649b835eb993b2044366afca79 Mon Sep 17 00:00:00 2001 From: Fred Gleason Date: Thu, 24 Apr 2025 16:29:39 -0400 Subject: [PATCH] 2025-04-24 Fred Gleason * Added a 'RDTimeArray' class for optimization and debugging. Signed-off-by: Fred Gleason --- CODINGSTYLE | 8 +++ ChangeLog | 2 + lib/Makefile.am | 5 +- lib/librd.pro | 4 +- lib/rdtimearray.cpp | 129 ++++++++++++++++++++++++++++++++++++++++++++ lib/rdtimearray.h | 60 +++++++++++++++++++++ 6 files changed, 205 insertions(+), 3 deletions(-) create mode 100644 lib/rdtimearray.cpp create mode 100644 lib/rdtimearray.h diff --git a/CODINGSTYLE b/CODINGSTYLE index 6769440d..2da20559 100644 --- a/CODINGSTYLE +++ b/CODINGSTYLE @@ -441,6 +441,14 @@ For example: Entries should be sorted by surname, then christian name of the author. +DEBUGGING/OPTIMIZATION AIDS: +The following classes exist for aiding the debugging and optimization +process: + + RDTimeArray. Record a series of code points with microsecond precision + and then render the results to a QString. See 'lib/rdtimearray.h'. + + QUESTIONS: Questions about coding style, or indeed any aspect of Rivendell development, are welcomed on the Rivendell-prog mailing list. Subscription information diff --git a/ChangeLog b/ChangeLog index 831923cc..c4e8e1ff 100644 --- a/ChangeLog +++ b/ChangeLog @@ -24975,3 +24975,5 @@ * Incremented the database version to 376. 2025-04-07 Fred Gleason * Incremented the package version to 4.3.0int8. +2025-04-24 Fred Gleason + * Added a 'RDTimeArray' class for optimization and debugging. diff --git a/lib/Makefile.am b/lib/Makefile.am index b0662575..9e857f4a 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -1,8 +1,8 @@ ## Makefile.am ## -## Automake.am for rivendell/lib +## Makefile.am for rivendell/lib ## -## (C) Copyright 2002-2023 Fred Gleason +## (C) Copyright 2002-2025 Fred Gleason ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License version 2 as @@ -264,6 +264,7 @@ dist_librd_la_SOURCES = dbversion.h\ rdtempdirectory.cpp rdtempdirectory.h\ rdtextfile.cpp rdtextfile.h\ rdtextvalidator.cpp rdtextvalidator.h\ + rdtimearray.cpp rdtimearray.h\ rdtimeedit.cpp rdtimeedit.h\ rdtimeengine.cpp rdtimeengine.h\ rdtimeprobe.cpp rdtimeprobe.h\ diff --git a/lib/librd.pro b/lib/librd.pro index aa830152..542da99f 100644 --- a/lib/librd.pro +++ b/lib/librd.pro @@ -2,7 +2,7 @@ # # The lib/ QMake project file for Rivendell. # -# (C) Copyright 2003-2022 Fred Gleason +# (C) Copyright 2003-2025 Fred Gleason # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 as @@ -204,6 +204,7 @@ SOURCES += rdtableview.cpp SOURCES += rdtempdirectory.cpp SOURCES += rdtextfile.cpp SOURCES += rdtextvalidator.cpp +SOURCES += rdtimearray.cpp SOURCES += rdtimeedit.cpp SOURCES += rdtimeengine.cpp SOURCES += rdtimeprobe.cpp @@ -399,6 +400,7 @@ HEADERS += rdtableview.h HEADERS += rdtempdirectory.h HEADERS += rdtextfile.h HEADERS += rdtextvalidator.h +HEADERS += rdtimearray.h HEADERS += rdtimeedit.h HEADERS += rdtimeedit.h HEADERS += rdtimeengine.h diff --git a/lib/rdtimearray.cpp b/lib/rdtimearray.cpp new file mode 100644 index 00000000..5546df2b --- /dev/null +++ b/lib/rdtimearray.cpp @@ -0,0 +1,129 @@ +// rdtimearray.cpp +// +// Record a sequence of precise points in time with microsecond precision. +// +// (C) Copyright 2025 Fred Gleason +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License version 2 as +// published by the Free Software Foundation. +// +// This program 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. +// +// You should have received a copy of the GNU General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +// + +#include + +#include + +#include "rdtimearray.h" + +RDTimePoint::RDTimePoint(const QString &label) +{ + struct timeval tv; + + gettimeofday(&tv,NULL); + d_label=label; + d_usecs=1000000*tv.tv_sec+tv.tv_usec; +} + + +QString RDTimePoint::label() const +{ + return d_label; +} + + +int64_t RDTimePoint::usecs() const +{ + return d_usecs; +} + + +QString RDTimePoint::toString() const +{ + return QString::asprintf("%s: %ld",d_label.toUtf8().constData(),d_usecs); +} + + +int64_t RDTimePoint::operator-(const RDTimePoint &rhs) const +{ + return d_usecs-rhs.d_usecs; +} + + + + +RDTimeArray::RDTimeArray() +{ +} + + +int RDTimeArray::size() const +{ + return d_points.size(); +} + + +RDTimePoint RDTimeArray::timePoint(int n) const +{ + return d_points.at(n); +} + + +void RDTimeArray::addPoint(QString label) +{ + if(label.isEmpty()) { + label=QObject::tr("point")+QString::asprintf(" %d",d_points.size()); + } + d_points.push_back(RDTimePoint(label)); +} + + +QString RDTimeArray::toString(int from,int to) const +{ + QString ret; + + if(to<0) { + to=d_points.size()-1; + } + for(int i=from;i<(to+1);i++) { + ret+=QString::asprintf("%s: %ld\n", + d_points.at(i).label().toUtf8().constData(), + d_points.at(i).usecs()); + } + return ret; +} + + +QString RDTimeArray::offsetsToString(int from,int to) const +{ + QString ret; + + if(to<0) { + to=d_points.size()-1; + } + for(int i=from;i<(to+1);i++) { + ret+=QString::asprintf("%s - %s: %ld\n", + d_points.at(i).label().toUtf8().constData(), + d_points.at(i-1).label().toUtf8().constData(), + d_points.at(i)-d_points.at(i-1)); + } + return ret; + +} + + +int64_t RDTimeArray::usecsElapsed(int from,int to) const +{ + if(to<0) { + to=d_points.size()-1; + } + return d_points.at(to)-d_points.at(from); +} diff --git a/lib/rdtimearray.h b/lib/rdtimearray.h new file mode 100644 index 00000000..03b24624 --- /dev/null +++ b/lib/rdtimearray.h @@ -0,0 +1,60 @@ +// rdtimearray.h +// +// Record a sequence of precise points in time with microsecond precision. +// +// (C) Copyright 2025 Fred Gleason +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License version 2 as +// published by the Free Software Foundation. +// +// This program 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. +// +// You should have received a copy of the GNU General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +// + +#ifndef RDTIMEARRAY_H +#define RDTIMEARRAY_H + +#include + +#include +#include + +class RDTimePoint +{ + public: + RDTimePoint(const QString &label); + QString label() const; + int64_t usecs() const; + QString toString() const; + int64_t operator-(const RDTimePoint &rhs) const; + + private: + QString d_label; + int64_t d_usecs; +}; + + +class RDTimeArray +{ + public: + RDTimeArray(); + int size() const; + RDTimePoint timePoint(int n) const; + void addPoint(QString label=""); + QString toString(int from=0,int to=-1) const; + QString offsetsToString(int from=1,int to=-1) const; + int64_t usecsElapsed(int from=0,int to=-1) const; + + private: + QList d_points; +}; + + +#endif // RDTIMEARRAY_H