mirror of
https://github.com/ElvishArtisan/rivendell.git
synced 2025-05-18 22:22:36 +02:00
2025-04-24 Fred Gleason <fredg@paravelsystems.com>
* Added a 'RDTimeArray' class for optimization and debugging. Signed-off-by: Fred Gleason <fredg@paravelsystems.com>
This commit is contained in:
parent
c4b781ce8e
commit
79518592e4
@ -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
|
||||
|
@ -24975,3 +24975,5 @@
|
||||
* Incremented the database version to 376.
|
||||
2025-04-07 Fred Gleason <fredg@paravelsystems.com>
|
||||
* Incremented the package version to 4.3.0int8.
|
||||
2025-04-24 Fred Gleason <fredg@paravelsystems.com>
|
||||
* Added a 'RDTimeArray' class for optimization and debugging.
|
||||
|
@ -1,8 +1,8 @@
|
||||
## Makefile.am
|
||||
##
|
||||
## Automake.am for rivendell/lib
|
||||
## Makefile.am for rivendell/lib
|
||||
##
|
||||
## (C) Copyright 2002-2023 Fred Gleason <fredg@paravelsystems.com>
|
||||
## (C) Copyright 2002-2025 Fred Gleason <fredg@paravelsystems.com>
|
||||
##
|
||||
## 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\
|
||||
|
@ -2,7 +2,7 @@
|
||||
#
|
||||
# The lib/ QMake project file for Rivendell.
|
||||
#
|
||||
# (C) Copyright 2003-2022 Fred Gleason <fredg@paravelsystems.com>
|
||||
# (C) Copyright 2003-2025 Fred Gleason <fredg@paravelsystems.com>
|
||||
#
|
||||
# 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
|
||||
|
129
lib/rdtimearray.cpp
Normal file
129
lib/rdtimearray.cpp
Normal file
@ -0,0 +1,129 @@
|
||||
// rdtimearray.cpp
|
||||
//
|
||||
// Record a sequence of precise points in time with microsecond precision.
|
||||
//
|
||||
// (C) Copyright 2025 Fred Gleason <fredg@paravelsystems.com>
|
||||
//
|
||||
// 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 <sys/time.h>
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#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);
|
||||
}
|
60
lib/rdtimearray.h
Normal file
60
lib/rdtimearray.h
Normal file
@ -0,0 +1,60 @@
|
||||
// rdtimearray.h
|
||||
//
|
||||
// Record a sequence of precise points in time with microsecond precision.
|
||||
//
|
||||
// (C) Copyright 2025 Fred Gleason <fredg@paravelsystems.com>
|
||||
//
|
||||
// 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 <stdint.h>
|
||||
|
||||
#include <QList>
|
||||
#include <QString>
|
||||
|
||||
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<RDTimePoint> d_points;
|
||||
};
|
||||
|
||||
|
||||
#endif // RDTIMEARRAY_H
|
Loading…
x
Reference in New Issue
Block a user