Fossil SCM

Improved error message upon timeout. Combine redundant implementations of the function that finds user and kernel CPU usage.

drh 2021-08-07 17:28 trunk
Commit 6c3d370496dfb7c91d2ef20e0523cfcb35663d160fce0d3ca3ea9710fb6e7efd
3 files changed +6 -1 +2 -39 -1
+6 -1
--- src/main.c
+++ src/main.c
@@ -2781,12 +2781,16 @@
27812781
/*
27822782
** Respond to a SIGALRM by writing a message to the error log (if there
27832783
** is one) and exiting.
27842784
*/
27852785
#ifndef _WIN32
2786
+static int nAlarmSeconds = 0;
27862787
static void sigalrm_handler(int x){
2787
- fossil_panic("TIMEOUT");
2788
+ sqlite3_uint64 tmUser = 0, tmKernel = 0;
2789
+ fossil_cpu_times(&tmUser, &tmKernel);
2790
+ fossil_panic("Timeout after %d seconds - user %,llu µs, sys %,llu µs",
2791
+ nAlarmSeconds, tmUser, tmKernel);
27882792
}
27892793
#endif
27902794
27912795
/*
27922796
** Arrange to timeout using SIGALRM after N seconds. Or if N==0, cancel
@@ -2798,10 +2802,11 @@
27982802
*/
27992803
void fossil_set_timeout(int N){
28002804
#ifndef _WIN32
28012805
signal(SIGALRM, sigalrm_handler);
28022806
alarm(N);
2807
+ nAlarmSeconds = N;
28032808
#endif
28042809
}
28052810
28062811
/*
28072812
** COMMAND: server*
28082813
--- src/main.c
+++ src/main.c
@@ -2781,12 +2781,16 @@
2781 /*
2782 ** Respond to a SIGALRM by writing a message to the error log (if there
2783 ** is one) and exiting.
2784 */
2785 #ifndef _WIN32
 
2786 static void sigalrm_handler(int x){
2787 fossil_panic("TIMEOUT");
 
 
 
2788 }
2789 #endif
2790
2791 /*
2792 ** Arrange to timeout using SIGALRM after N seconds. Or if N==0, cancel
@@ -2798,10 +2802,11 @@
2798 */
2799 void fossil_set_timeout(int N){
2800 #ifndef _WIN32
2801 signal(SIGALRM, sigalrm_handler);
2802 alarm(N);
 
2803 #endif
2804 }
2805
2806 /*
2807 ** COMMAND: server*
2808
--- src/main.c
+++ src/main.c
@@ -2781,12 +2781,16 @@
2781 /*
2782 ** Respond to a SIGALRM by writing a message to the error log (if there
2783 ** is one) and exiting.
2784 */
2785 #ifndef _WIN32
2786 static int nAlarmSeconds = 0;
2787 static void sigalrm_handler(int x){
2788 sqlite3_uint64 tmUser = 0, tmKernel = 0;
2789 fossil_cpu_times(&tmUser, &tmKernel);
2790 fossil_panic("Timeout after %d seconds - user %,llu µs, sys %,llu µs",
2791 nAlarmSeconds, tmUser, tmKernel);
2792 }
2793 #endif
2794
2795 /*
2796 ** Arrange to timeout using SIGALRM after N seconds. Or if N==0, cancel
@@ -2798,10 +2802,11 @@
2802 */
2803 void fossil_set_timeout(int N){
2804 #ifndef _WIN32
2805 signal(SIGALRM, sigalrm_handler);
2806 alarm(N);
2807 nAlarmSeconds = N;
2808 #endif
2809 }
2810
2811 /*
2812 ** COMMAND: server*
2813
+2 -39
--- src/th_main.c
+++ src/th_main.c
@@ -1749,47 +1749,10 @@
17491749
{ 0, 0 }
17501750
};
17511751
return Th_CallSubCommand(interp, p, argc, argv, argl, aSub);
17521752
}
17531753
1754
-#ifdef _WIN32
1755
-# include <windows.h>
1756
-#else
1757
-# include <sys/time.h>
1758
-# include <sys/resource.h>
1759
-#endif
1760
-
1761
-/*
1762
-** Get user and kernel times in microseconds.
1763
-*/
1764
-static void getCpuTimes(sqlite3_uint64 *piUser, sqlite3_uint64 *piKernel){
1765
-#ifdef _WIN32
1766
- FILETIME not_used;
1767
- FILETIME kernel_time;
1768
- FILETIME user_time;
1769
- GetProcessTimes(GetCurrentProcess(), &not_used, &not_used,
1770
- &kernel_time, &user_time);
1771
- if( piUser ){
1772
- *piUser = ((((sqlite3_uint64)user_time.dwHighDateTime)<<32) +
1773
- (sqlite3_uint64)user_time.dwLowDateTime + 5)/10;
1774
- }
1775
- if( piKernel ){
1776
- *piKernel = ((((sqlite3_uint64)kernel_time.dwHighDateTime)<<32) +
1777
- (sqlite3_uint64)kernel_time.dwLowDateTime + 5)/10;
1778
- }
1779
-#else
1780
- struct rusage s;
1781
- getrusage(RUSAGE_SELF, &s);
1782
- if( piUser ){
1783
- *piUser = ((sqlite3_uint64)s.ru_utime.tv_sec)*1000000 + s.ru_utime.tv_usec;
1784
- }
1785
- if( piKernel ){
1786
- *piKernel =
1787
- ((sqlite3_uint64)s.ru_stime.tv_sec)*1000000 + s.ru_stime.tv_usec;
1788
- }
1789
-#endif
1790
-}
17911754
17921755
/*
17931756
** TH1 command: utime
17941757
**
17951758
** Return the number of microseconds of CPU time consumed by the current
@@ -1802,11 +1765,11 @@
18021765
const char **argv,
18031766
int *argl
18041767
){
18051768
sqlite3_uint64 x;
18061769
char zUTime[50];
1807
- getCpuTimes(&x, 0);
1770
+ fossil_cpu_times(&x, 0);
18081771
sqlite3_snprintf(sizeof(zUTime), zUTime, "%llu", x);
18091772
Th_SetResult(interp, zUTime, -1);
18101773
return TH_OK;
18111774
}
18121775
@@ -1823,11 +1786,11 @@
18231786
const char **argv,
18241787
int *argl
18251788
){
18261789
sqlite3_uint64 x;
18271790
char zUTime[50];
1828
- getCpuTimes(0, &x);
1791
+ fossil_cpu_times(0, &x);
18291792
sqlite3_snprintf(sizeof(zUTime), zUTime, "%llu", x);
18301793
Th_SetResult(interp, zUTime, -1);
18311794
return TH_OK;
18321795
}
18331796
18341797
--- src/th_main.c
+++ src/th_main.c
@@ -1749,47 +1749,10 @@
1749 { 0, 0 }
1750 };
1751 return Th_CallSubCommand(interp, p, argc, argv, argl, aSub);
1752 }
1753
1754 #ifdef _WIN32
1755 # include <windows.h>
1756 #else
1757 # include <sys/time.h>
1758 # include <sys/resource.h>
1759 #endif
1760
1761 /*
1762 ** Get user and kernel times in microseconds.
1763 */
1764 static void getCpuTimes(sqlite3_uint64 *piUser, sqlite3_uint64 *piKernel){
1765 #ifdef _WIN32
1766 FILETIME not_used;
1767 FILETIME kernel_time;
1768 FILETIME user_time;
1769 GetProcessTimes(GetCurrentProcess(), &not_used, &not_used,
1770 &kernel_time, &user_time);
1771 if( piUser ){
1772 *piUser = ((((sqlite3_uint64)user_time.dwHighDateTime)<<32) +
1773 (sqlite3_uint64)user_time.dwLowDateTime + 5)/10;
1774 }
1775 if( piKernel ){
1776 *piKernel = ((((sqlite3_uint64)kernel_time.dwHighDateTime)<<32) +
1777 (sqlite3_uint64)kernel_time.dwLowDateTime + 5)/10;
1778 }
1779 #else
1780 struct rusage s;
1781 getrusage(RUSAGE_SELF, &s);
1782 if( piUser ){
1783 *piUser = ((sqlite3_uint64)s.ru_utime.tv_sec)*1000000 + s.ru_utime.tv_usec;
1784 }
1785 if( piKernel ){
1786 *piKernel =
1787 ((sqlite3_uint64)s.ru_stime.tv_sec)*1000000 + s.ru_stime.tv_usec;
1788 }
1789 #endif
1790 }
1791
1792 /*
1793 ** TH1 command: utime
1794 **
1795 ** Return the number of microseconds of CPU time consumed by the current
@@ -1802,11 +1765,11 @@
1802 const char **argv,
1803 int *argl
1804 ){
1805 sqlite3_uint64 x;
1806 char zUTime[50];
1807 getCpuTimes(&x, 0);
1808 sqlite3_snprintf(sizeof(zUTime), zUTime, "%llu", x);
1809 Th_SetResult(interp, zUTime, -1);
1810 return TH_OK;
1811 }
1812
@@ -1823,11 +1786,11 @@
1823 const char **argv,
1824 int *argl
1825 ){
1826 sqlite3_uint64 x;
1827 char zUTime[50];
1828 getCpuTimes(0, &x);
1829 sqlite3_snprintf(sizeof(zUTime), zUTime, "%llu", x);
1830 Th_SetResult(interp, zUTime, -1);
1831 return TH_OK;
1832 }
1833
1834
--- src/th_main.c
+++ src/th_main.c
@@ -1749,47 +1749,10 @@
1749 { 0, 0 }
1750 };
1751 return Th_CallSubCommand(interp, p, argc, argv, argl, aSub);
1752 }
1753
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1754
1755 /*
1756 ** TH1 command: utime
1757 **
1758 ** Return the number of microseconds of CPU time consumed by the current
@@ -1802,11 +1765,11 @@
1765 const char **argv,
1766 int *argl
1767 ){
1768 sqlite3_uint64 x;
1769 char zUTime[50];
1770 fossil_cpu_times(&x, 0);
1771 sqlite3_snprintf(sizeof(zUTime), zUTime, "%llu", x);
1772 Th_SetResult(interp, zUTime, -1);
1773 return TH_OK;
1774 }
1775
@@ -1823,11 +1786,11 @@
1786 const char **argv,
1787 int *argl
1788 ){
1789 sqlite3_uint64 x;
1790 char zUTime[50];
1791 fossil_cpu_times(0, &x);
1792 sqlite3_snprintf(sizeof(zUTime), zUTime, "%llu", x);
1793 Th_SetResult(interp, zUTime, -1);
1794 return TH_OK;
1795 }
1796
1797
-1
--- src/util.c
+++ src/util.c
@@ -35,11 +35,10 @@
3535
# include <sys/resource.h>
3636
# include <unistd.h>
3737
# include <fcntl.h>
3838
# include <errno.h>
3939
#endif
40
-
4140
4241
/*
4342
** Exit. Take care to close the database first.
4443
*/
4544
NORETURN void fossil_exit(int rc){
4645
--- src/util.c
+++ src/util.c
@@ -35,11 +35,10 @@
35 # include <sys/resource.h>
36 # include <unistd.h>
37 # include <fcntl.h>
38 # include <errno.h>
39 #endif
40
41
42 /*
43 ** Exit. Take care to close the database first.
44 */
45 NORETURN void fossil_exit(int rc){
46
--- src/util.c
+++ src/util.c
@@ -35,11 +35,10 @@
35 # include <sys/resource.h>
36 # include <unistd.h>
37 # include <fcntl.h>
38 # include <errno.h>
39 #endif
 
40
41 /*
42 ** Exit. Take care to close the database first.
43 */
44 NORETURN void fossil_exit(int rc){
45

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button