37
37
*
38
38
*
39
39
* IDENTIFICATION
40
- * $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.267 2002/02/23 01:31:35 petere Exp $
40
+ * $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.268 2002/03/02 20:46:12 tgl Exp $
41
41
*
42
42
* NOTES
43
43
*
@@ -769,6 +769,14 @@ pmdaemonize(int argc, char *argv[])
769
769
{
770
770
int i ;
771
771
pid_t pid ;
772
+ #ifdef LINUX_PROFILE
773
+ struct itimerval prof_itimer ;
774
+ #endif
775
+
776
+ #ifdef LINUX_PROFILE
777
+ /* see comments in BackendStartup */
778
+ getitimer (ITIMER_PROF , & prof_itimer );
779
+ #endif
772
780
773
781
pid = fork ();
774
782
if (pid == (pid_t ) - 1 )
@@ -783,6 +791,10 @@ pmdaemonize(int argc, char *argv[])
783
791
_exit (0 );
784
792
}
785
793
794
+ #ifdef LINUX_PROFILE
795
+ setitimer (ITIMER_PROF , & prof_itimer , NULL );
796
+ #endif
797
+
786
798
MyProcPid = getpid (); /* reset MyProcPid to child */
787
799
788
800
/* GH: If there's no setsid(), we hopefully don't need silent mode.
@@ -1801,13 +1813,16 @@ SignalChildren(int signal)
1801
1813
/*
1802
1814
* BackendStartup -- start backend process
1803
1815
*
1804
- * returns: STATUS_ERROR if the fork/exec failed, STATUS_OK otherwise.
1816
+ * returns: STATUS_ERROR if the fork failed, STATUS_OK otherwise.
1805
1817
*/
1806
1818
static int
1807
1819
BackendStartup (Port * port )
1808
1820
{
1809
1821
Backend * bn ; /* for backend cleanup */
1810
1822
pid_t pid ;
1823
+ #ifdef LINUX_PROFILE
1824
+ struct itimerval prof_itimer ;
1825
+ #endif
1811
1826
1812
1827
/*
1813
1828
* Compute the cancel key that will be assigned to this backend. The
@@ -1838,6 +1853,16 @@ BackendStartup(Port *port)
1838
1853
fflush (stdout );
1839
1854
fflush (stderr );
1840
1855
1856
+ #ifdef LINUX_PROFILE
1857
+ /*
1858
+ * Linux's fork() resets the profiling timer in the child process.
1859
+ * If we want to profile child processes then we need to save and restore
1860
+ * the timer setting. This is a waste of time if not profiling, however,
1861
+ * so only do it if commanded by specific -DLINUX_PROFILE switch.
1862
+ */
1863
+ getitimer (ITIMER_PROF , & prof_itimer );
1864
+ #endif
1865
+
1841
1866
#ifdef __BEOS__
1842
1867
/* Specific beos actions before backend startup */
1843
1868
beos_before_backend_startup ();
@@ -1849,6 +1874,10 @@ BackendStartup(Port *port)
1849
1874
{
1850
1875
int status ;
1851
1876
1877
+ #ifdef LINUX_PROFILE
1878
+ setitimer (ITIMER_PROF , & prof_itimer , NULL );
1879
+ #endif
1880
+
1852
1881
#ifdef __BEOS__
1853
1882
/* Specific beos backend startup actions */
1854
1883
beos_backend_startup ();
@@ -2487,10 +2516,18 @@ SSDataBase(int xlop)
2487
2516
{
2488
2517
pid_t pid ;
2489
2518
Backend * bn ;
2519
+ #ifdef LINUX_PROFILE
2520
+ struct itimerval prof_itimer ;
2521
+ #endif
2490
2522
2491
2523
fflush (stdout );
2492
2524
fflush (stderr );
2493
2525
2526
+ #ifdef LINUX_PROFILE
2527
+ /* see comments in BackendStartup */
2528
+ getitimer (ITIMER_PROF , & prof_itimer );
2529
+ #endif
2530
+
2494
2531
#ifdef __BEOS__
2495
2532
/* Specific beos actions before backend startup */
2496
2533
beos_before_backend_startup ();
@@ -2505,6 +2542,10 @@ SSDataBase(int xlop)
2505
2542
char dbbuf [ARGV_SIZE ];
2506
2543
char xlbuf [ARGV_SIZE ];
2507
2544
2545
+ #ifdef LINUX_PROFILE
2546
+ setitimer (ITIMER_PROF , & prof_itimer , NULL );
2547
+ #endif
2548
+
2508
2549
#ifdef __BEOS__
2509
2550
/* Specific beos actions after backend startup */
2510
2551
beos_backend_startup ();
@@ -2603,7 +2644,7 @@ SSDataBase(int xlop)
2603
2644
*/
2604
2645
if (xlop == BS_XLOG_CHECKPOINT )
2605
2646
{
2606
- if (!(bn = (Backend * ) calloc ( 1 , sizeof (Backend ))))
2647
+ if (!(bn = (Backend * ) malloc ( sizeof (Backend ))))
2607
2648
{
2608
2649
elog (DEBUG , "CheckPointDataBase: malloc failed" );
2609
2650
ExitPostmaster (1 );
0 commit comments