Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8d8aa93

Browse files
committed
Add code to allow profiling of backends on Linux: save and restore the
profiling timer setting across fork(). The correct way to build aprofilable backend on Linux is now gmake PROFILE="-pg -DLINUX_PROFILE"
1 parent78ab803 commit8d8aa93

File tree

1 file changed

+44
-3
lines changed

1 file changed

+44
-3
lines changed

‎src/backend/postmaster/postmaster.c

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
*
3838
*
3939
* 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 $
4141
*
4242
* NOTES
4343
*
@@ -769,6 +769,14 @@ pmdaemonize(int argc, char *argv[])
769769
{
770770
inti;
771771
pid_tpid;
772+
#ifdefLINUX_PROFILE
773+
structitimervalprof_itimer;
774+
#endif
775+
776+
#ifdefLINUX_PROFILE
777+
/* see comments in BackendStartup */
778+
getitimer(ITIMER_PROF,&prof_itimer);
779+
#endif
772780

773781
pid=fork();
774782
if (pid== (pid_t)-1)
@@ -783,6 +791,10 @@ pmdaemonize(int argc, char *argv[])
783791
_exit(0);
784792
}
785793

794+
#ifdefLINUX_PROFILE
795+
setitimer(ITIMER_PROF,&prof_itimer,NULL);
796+
#endif
797+
786798
MyProcPid=getpid();/* reset MyProcPid to child */
787799

788800
/* GH: If there's no setsid(), we hopefully don't need silent mode.
@@ -1801,13 +1813,16 @@ SignalChildren(int signal)
18011813
/*
18021814
* BackendStartup -- start backend process
18031815
*
1804-
* returns: STATUS_ERROR if the fork/exec failed, STATUS_OK otherwise.
1816+
* returns: STATUS_ERROR if the fork failed, STATUS_OK otherwise.
18051817
*/
18061818
staticint
18071819
BackendStartup(Port*port)
18081820
{
18091821
Backend*bn;/* for backend cleanup */
18101822
pid_tpid;
1823+
#ifdefLINUX_PROFILE
1824+
structitimervalprof_itimer;
1825+
#endif
18111826

18121827
/*
18131828
* Compute the cancel key that will be assigned to this backend. The
@@ -1838,6 +1853,16 @@ BackendStartup(Port *port)
18381853
fflush(stdout);
18391854
fflush(stderr);
18401855

1856+
#ifdefLINUX_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+
18411866
#ifdef__BEOS__
18421867
/* Specific beos actions before backend startup */
18431868
beos_before_backend_startup();
@@ -1849,6 +1874,10 @@ BackendStartup(Port *port)
18491874
{
18501875
intstatus;
18511876

1877+
#ifdefLINUX_PROFILE
1878+
setitimer(ITIMER_PROF,&prof_itimer,NULL);
1879+
#endif
1880+
18521881
#ifdef__BEOS__
18531882
/* Specific beos backend startup actions */
18541883
beos_backend_startup();
@@ -2487,10 +2516,18 @@ SSDataBase(int xlop)
24872516
{
24882517
pid_tpid;
24892518
Backend*bn;
2519+
#ifdefLINUX_PROFILE
2520+
structitimervalprof_itimer;
2521+
#endif
24902522

24912523
fflush(stdout);
24922524
fflush(stderr);
24932525

2526+
#ifdefLINUX_PROFILE
2527+
/* see comments in BackendStartup */
2528+
getitimer(ITIMER_PROF,&prof_itimer);
2529+
#endif
2530+
24942531
#ifdef__BEOS__
24952532
/* Specific beos actions before backend startup */
24962533
beos_before_backend_startup();
@@ -2505,6 +2542,10 @@ SSDataBase(int xlop)
25052542
chardbbuf[ARGV_SIZE];
25062543
charxlbuf[ARGV_SIZE];
25072544

2545+
#ifdefLINUX_PROFILE
2546+
setitimer(ITIMER_PROF,&prof_itimer,NULL);
2547+
#endif
2548+
25082549
#ifdef__BEOS__
25092550
/* Specific beos actions after backend startup */
25102551
beos_backend_startup();
@@ -2603,7 +2644,7 @@ SSDataBase(int xlop)
26032644
*/
26042645
if (xlop==BS_XLOG_CHECKPOINT)
26052646
{
2606-
if (!(bn= (Backend*)calloc(1,sizeof(Backend))))
2647+
if (!(bn= (Backend*)malloc(sizeof(Backend))))
26072648
{
26082649
elog(DEBUG,"CheckPointDataBase: malloc failed");
26092650
ExitPostmaster(1);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp