From c8eb9be8f015850e89b8532adf27cd7ca2eb3923 Mon Sep 17 00:00:00 2001 From: Fred Gleason Date: Sun, 27 Feb 2022 13:04:49 -0500 Subject: [PATCH] 2022-02-27 Fred Gleason * Added an 'RDTimeProbe' class. Signed-off-by: Fred Gleason --- ChangeLog | 2 + lib/Makefile.am | 1 + lib/librd.pro | 2 + lib/rdtimeprobe.cpp | 104 ++++++++++++++++++++++++++++++++++++++++++++ lib/rdtimeprobe.h | 59 +++++++++++++++++++++++++ 5 files changed, 168 insertions(+) create mode 100644 lib/rdtimeprobe.cpp create mode 100644 lib/rdtimeprobe.h diff --git a/ChangeLog b/ChangeLog index 17f1cfa1..def198f6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -22893,3 +22893,5 @@ * Fixed a bug in rddbmgr(8) that could cause the 346=>347 schema conversion to hang indefinitely with databases containing large cart libraries. +2022-02-27 Fred Gleason + * Added an 'RDTimeProbe' class. diff --git a/lib/Makefile.am b/lib/Makefile.am index 1ee51c78..d2c8e4b9 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -263,6 +263,7 @@ dist_librd_la_SOURCES = dbversion.h\ rdtextvalidator.cpp rdtextvalidator.h\ rdtimeedit.cpp rdtimeedit.h\ rdtimeengine.cpp rdtimeengine.h\ + rdtimeprobe.cpp rdtimeprobe.h\ rdtrackereditdialog.cpp rdtrackereditdialog.h\ rdtrackermodel.cpp rdtrackermodel.h\ rdtrackertableview.cpp rdtrackertableview.h\ diff --git a/lib/librd.pro b/lib/librd.pro index 4f6342aa..cb653e3f 100644 --- a/lib/librd.pro +++ b/lib/librd.pro @@ -203,6 +203,7 @@ SOURCES += rdtextfile.cpp SOURCES += rdtextvalidator.cpp SOURCES += rdtimeedit.cpp SOURCES += rdtimeengine.cpp +SOURCES += rdtimeprobe.cpp SOURCES += rdtrackereditdialog.cpp SOURCES += rdtrackermodel.cpp SOURCES += rdtrackertableview.cpp @@ -393,6 +394,7 @@ HEADERS += rdtextvalidator.h HEADERS += rdtimeedit.h HEADERS += rdtimeedit.h HEADERS += rdtimeengine.h +HEADERS += rdtimeprobe.h HEADERS += rdtrackereditdialog.h HEADERS += rdtrackermodel.h HEADERS += rdtrackertableview.h diff --git a/lib/rdtimeprobe.cpp b/lib/rdtimeprobe.cpp new file mode 100644 index 00000000..f4d7354f --- /dev/null +++ b/lib/rdtimeprobe.cpp @@ -0,0 +1,104 @@ +// rdtimeprobe.cpp +// +// Report elapsed times for profiling and optimization +// +// (C) Copyright 2022 Fred Gleason +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU Library 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 "rdtimeprobe.h" + +RDTimeProbeStamp::RDTimeProbeStamp(struct timespec *tp) +{ + d_timespec=*tp; +} + + +RDTimeProbeStamp::~RDTimeProbeStamp() +{ +} + + +QString RDTimeProbeStamp::toString() const +{ + QDateTime dt=QDateTime::fromMSecsSinceEpoch(1000*(qint64)d_timespec.tv_sec); + QString microsec=QString::asprintf(".%06ld",d_timespec.tv_nsec); + + return dt.time().toString("hh:mm:ss")+microsec.left(4); +} + + +double RDTimeProbeStamp::operator-(const RDTimeProbeStamp &other) +{ + double lhs=(double)d_timespec.tv_sec+(double)d_timespec.tv_nsec/1000000000.0; + double rhs=(double)other.d_timespec.tv_sec+ + (double)other.d_timespec.tv_nsec/1000000000.0; + + return lhs-rhs; +} + + +RDTimeProbeStamp *RDTimeProbeStamp::currentStamp() +{ + struct timespec now; + + memset(&now,0,sizeof(now)); + clock_gettime(CLOCK_REALTIME,&now); + + return new RDTimeProbeStamp(&now); +} + + + + +RDTimeProbe::RDTimeProbe(FILE *out) +{ + d_current_timestamp=NULL; + d_output_stream=out; + + fprintf(d_output_stream, + "================================================================\n"); + fprintf(d_output_stream,"%p: RDTimeProbe created\n",this); +} + + +RDTimeProbe::~RDTimeProbe() +{ + fprintf(d_output_stream,"%p: RDTimeProbe destroyed\n",this); + fprintf(d_output_stream, + "================================================================\n"); + if(d_current_timestamp!=NULL) { + delete d_current_timestamp; + } +} + + +void RDTimeProbe::printWaypoint(const QString &label) +{ + RDTimeProbeStamp *now=RDTimeProbeStamp::currentStamp(); + double diff=0.0; + + if(d_current_timestamp!=NULL) { + diff=*now-*d_current_timestamp; + } + QString diff_str=QString::asprintf("%18.6lf",diff).trimmed(); + fprintf(d_output_stream,"%p : %s [%s] : %s\n", + this, + now->toString().toUtf8().constData(), + diff_str.toUtf8().constData(), + label.toUtf8().constData()); + delete d_current_timestamp; + d_current_timestamp=now; +} diff --git a/lib/rdtimeprobe.h b/lib/rdtimeprobe.h new file mode 100644 index 00000000..cc31b280 --- /dev/null +++ b/lib/rdtimeprobe.h @@ -0,0 +1,59 @@ +// rdtimeprobe.h +// +// Report elapsed times for profiling and optimization +// +// (C) Copyright 2022 Fred Gleason +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU Library 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 RDTIMEPROBE_H +#define RDTIMEPROBE_H + +#include +#include + +#include +#include + +class RDTimeProbeStamp +{ + public: + RDTimeProbeStamp(struct timespec *tp=NULL); + ~RDTimeProbeStamp(); + QString toString() const; + double operator-(const RDTimeProbeStamp &other); + static RDTimeProbeStamp *currentStamp(); + + private: + struct timespec d_timespec; +}; + + + + +class RDTimeProbe +{ + public: + RDTimeProbe(FILE *out=stderr); + ~RDTimeProbe(); + void printWaypoint(const QString &label); + + private: + RDTimeProbeStamp *d_current_timestamp; + FILE *d_output_stream; +}; + + +#endif // RDTIMEPROBE_H