[tin-dev] [PATCH] replace stpwatch.h

Urs Janßen urs at tin.org
Wed Jul 26 10:14:41 CEST 2023


if compiled with -DPROFILE (on screen timing info for a few funcs; hardly
useable) we no longer use stpwatch.h and ftime() (function is obsolete) but
gettimeofday() or clock_gettime(). if none of the two is available profiling
is silently disabled.

=== modified file 'Makefile'
--- old/Makefile	2023-07-22 14:42:31 +0000
+++ new/Makefile	2023-07-26 06:42:49 +0000
@@ -40,7 +40,6 @@
 	$(INCDIR)/policy.h \
 	$(INCDIR)/proto.h \
 	$(INCDIR)/rfc2046.h \
-	$(INCDIR)/stpwatch.h \
 	$(INCDIR)/tcurses.h \
 	$(INCDIR)/tin.h \
 	$(INCDIR)/tinrc.h \

=== modified file 'doc/TODO'
--- old/doc/TODO	2023-07-25 04:17:45 +0000
+++ new/doc/TODO	2023-07-26 06:40:46 +0000
@@ -599,9 +599,6 @@
 
 Internal Changes
 ----------------
-o  use tin_gettime() in *StopWatch() instead of ftime(3)
-   [Urs Janssen <urs at tin.org>]
-
 o  in ENABLE_NLS case replace PLURAL() macro with proper use of
    ngettext(3) (if found by configure) to support languages with
    more than one plural form.

=== modified file 'include/extern.h'
--- old/include/extern.h	2023-07-07 09:25:56 +0000
+++ new/include/extern.h	2023-07-26 07:56:09 +0000
@@ -1191,9 +1191,9 @@
 	extern constext txt_reconnect_to_news_server[];
 #endif /* NNTP_ABLE */
 extern constext txt_refs_line_only[];
-#ifdef HAVE_GETTIMEOFDAY
+#if defined(HAVE_CLOCK_GETTIME) || defined(HAVE_GETTIMEOFDAY)
 	extern constext txt_remaining[];
-#endif /* HAVE_GETTIMEOFDAY */
+#endif /* HAVE_CLOCK_GETTIME || HAVE_GETTIMEOFDAY */
 extern constext txt_remove_bogus[];
 extern constext txt_removed_rule[];
 extern constext txt_rename_error[];

=== removed file 'include/stpwatch.h'
--- old/include/stpwatch.h	2022-11-03 11:55:26 +0000
+++ new/include/stpwatch.h	1970-01-01 00:00:00 +0000
@@ -1,102 +0,0 @@
-/*
- *  Project   : tin - a Usenet reader
- *  Module    : stpwatch.h
- *  Author    : I. Lea
- *  Created   : 1993-08-03
- *  Updated   : 2008-11-22
- *  Notes     : Simple stopwatch routines for timing code using timeb
- *	             or gettimeofday structs
- *
- * Copyright (c) 1993-2023 Iain Lea <iain at bricbrac.de>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- *    this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * 3. Neither the name of the copyright holder nor the names of its
- *    contributors may be used to endorse or promote products derived from
- *    this software without specific prior written permission.
- *
- * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-
-#ifndef STPWATCH_H
-#	define STPWATCH_H 1
-
-#	ifdef PROFILE
-
-#		if defined(HAVE_SYS_TIMEB_H) && defined(HAVE_FTIME)
-#			include <sys/timeb.h>
-
-char msg_tb[LEN];
-char tmp_tb[LEN];
-struct timeb beg_tb;
-struct timeb end_tb;
-
-#			define LSECS 700000000	/* offset to keep numbers smaller (1992-03-07 20:26:40 UTC) */
-
-#			define BegStopWatch(msg)	{strcpy (msg_tb, msg); ftime (&beg_tb);}
-
-#			define EndStopWatch()		{ftime (&end_tb);}
-
-#			define PrintStopWatch()	{sprintf (tmp_tb, "%s: Beg=[%ld.%d] End=[%ld.%d] Elap=[%ld ms]", \
-				 msg_tb, beg_tb.time, beg_tb.millitm, \
-				 end_tb.time, end_tb.millitm, \
-				 (((end_tb.time - LSECS) * 1000) + end_tb.millitm) - \
-				 (((beg_tb.time - LSECS) * 1000) + beg_tb.millitm)); \
-				 error_message(2, tmp_tb);}
-
-#		else	/* HAVE_SYS_TIMEB_H && HAVE_FTIME */
-
-#		ifdef	HAVE_SYS_TIME_H
-#			include <sys/time.h>
-
-char msg_tb[LEN];
-char tmp_tb[LEN];
-float d_time;
-struct timeval beg_tb, end_tb;
-
-#			define BegStopWatch(msg)	{strcpy (msg_tb, msg); \
-				 (void) gettimeofday (&beg_tb, NULL);}
-
-#			define EndStopWatch()		{(void) gettimeofday (&end_tb, NULL); \
-				if ((end_tb.tv_usec -= beg_tb.tv_usec) < 0) { \
-					end_tb.tv_sec--; \
-					end_tb.tv_usec += 1000000; \
-				 } \
-				 end_tb.tv_sec -= beg_tb.tv_sec; \
-				 d_time = (end_tb.tv_sec * 1000.0 + ((float) end_tb.tv_usec) / 1000.0);}
-
-#			define PrintStopWatch()	{sprintf (tmp_tb, "StopWatch(%s): %6.3f ms", msg_tb, d_time); \
-				 error_message(2, tmp_tb);}
-
-#		endif /* HAVE_SYS_TIME_H */
-#	endif /* HAVE_SYS_TIMEB_H && HAVE_FTIME */
-
-#	else	/* PROFILE */
-
-#		define BegStopWatch(msg)
-#		define EndStopWatch()
-#		define PrintStopWatch()
-
-#	endif /* PROFILE */
-#endif /* !STPWATCH_H */

=== modified file 'src/Makefile.in'
--- old/src/Makefile.in	2023-02-08 20:48:12 +0000
+++ new/src/Makefile.in	2023-07-26 06:42:37 +0000
@@ -138,7 +138,6 @@
 	$(INCDIR)/policy.h \
 	$(INCDIR)/proto.h \
 	$(INCDIR)/rfc2046.h \
-	$(INCDIR)/stpwatch.h \
 	$(INCDIR)/tin.h \
 	$(INCDIR)/tinrc.h \
 	$(INCDIR)/tnntp.h \
@@ -525,8 +524,7 @@
 
 $(OBJDIR)/active$o :		$(SRCDIR)/active.c $(TIN_DEP)
 $(OBJDIR)/art$o :		$(SRCDIR)/art.c $(TIN_DEP) \
-				$(INCDIR)/newsrc.h \
-				$(INCDIR)/stpwatch.h
+				$(INCDIR)/newsrc.h
 $(OBJDIR)/attrib$o :		$(SRCDIR)/attrib.c $(TIN_DEP) \
 				$(INCDIR)/version.h
 $(OBJDIR)/auth$o :		$(SRCDIR)/auth.c $(TIN_DEP)

=== modified file 'src/art.c'
--- old/src/art.c	2023-07-22 14:31:33 +0000
+++ new/src/art.c	2023-07-26 07:58:35 +0000
@@ -48,9 +48,23 @@
 #	include "newsrc.h"
 #endif /* !NEWSRC_H */
 
-#ifndef STPWATCH_H
-#	include "stpwatch.h"
-#endif /* !STPWATCH_H */
+#if defined(PROFILE) /* TODO: write to some log? */
+#	if defined(HAVE_CLOCK_GETTIME) || defined(HAVE_GETTIMEOFDAY)
+		static struct t_tintime start_time;
+		static struct t_tintime stop_time;
+#		define BegStopWatch()	tin_gettime(&start_time)
+#		define EndStopWatch(msg)	{ \
+			tin_gettime(&stop_time); \
+			error_message(2, "%s: %.6fs", msg, ((stop_time.tv_sec - start_time.tv_sec) * 1000000000.0 + stop_time.tv_nsec - start_time.tv_nsec) / 1000000000.0); \
+		}
+#	else
+#		define BegStopWatch()
+#		define EndStopWatch(msg)
+#	endif /* HAVE_CLOCK_GETTIME || HAVE_GETTIMEOFDAY */
+#else
+#	define BegStopWatch()
+#	define EndStopWatch(msg)
+#endif /* PROFILE */
 
 /*
  * TODO: fixup to remove CURR_GROUP dependency in all sort funcs
@@ -429,16 +443,14 @@
 	free_art_array();
 	free_msgids();
 
-	BegStopWatch("setup_hard_base()");
-
+	BegStopWatch();
 	/*
 	 * Get list of valid article numbers
 	 */
 	if (setup_hard_base(group) < 0)
 		return FALSE;
 
-	EndStopWatch();
-	PrintStopWatch();
+	EndStopWatch("setup_hard_base()");
 
 #ifdef DEBUG
 	if (debug & DEBUG_NEWSRC) {
@@ -575,22 +587,23 @@
 	 * Create the reference tree. The msgid and ref ptrs will
 	 * be free()d now that the NovFile has been written.
 	 */
+	BegStopWatch();
 	build_references(group);
+	EndStopWatch("build_references()");
 
 	/*
 	 * Needs access to the reference tree
 	 */
+	BegStopWatch();
 	filtered = filter_articles(group);
-
-	BegStopWatch("make_threads()");
+	EndStopWatch("filter_articles()");
 
 	/*
 	 * Thread the group
 	 */
+	BegStopWatch();
 	make_threads(group, FALSE);
-
-	EndStopWatch();
-	PrintStopWatch();
+	EndStopWatch("make_threads()");
 
 	if ((changed > 0 || filtered) && !batch_mode)
 		clear_message();

=== modified file 'src/lang.c'
--- old/src/lang.c	2023-07-19 23:58:32 +0000
+++ new/src/lang.c	2023-07-26 07:55:27 +0000
@@ -793,9 +793,9 @@
 constext txt_reading_newsgroups_file[] = N_("Reading newsgroups file... ");
 constext txt_reading_newsrc[] = N_("Reading newsrc file...");
 constext txt_refs_line_only[] = N_("References: line              ");
-#ifdef HAVE_GETTIMEOFDAY
+#if defined(HAVE_CLOCK_GETTIME) || defined(HAVE_GETTIMEOFDAY)
 	constext txt_remaining[] = N_("(%d:%02d remaining)");
-#endif /* HAVE_GETTIMEOFDAY */
+#endif /* HAVE_CLOCK_GETTIME || HAVE_GETTIMEOFDAY */
 constext txt_remove_bogus[] = N_("Bogus group %s removed.");
 constext txt_removed_rule[] = N_("Removed from this rule: ");
 constext txt_rename_error[] = N_("Error: rename %s to %s");




More information about the tin-dev mailing list