1 /* Profile PC and write result to FIFO.
2 Copyright (C) 1999-2022 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
25 /* Nonzero if we are actually doing something. */
28 /* The file descriptor of the FIFO. */
33 __attribute__ ((constructor
))
36 /* See whether the environment variable `PCPROFILE_OUTPUT' is defined.
37 If yes, it should name a FIFO. We open it and mark ourself as active. */
38 const char *outfile
= getenv ("PCPROFILE_OUTPUT");
40 if (outfile
!= NULL
&& *outfile
!= '\0')
42 fd
= open (outfile
, O_RDWR
| O_CREAT
, 0666);
50 /* Write a magic word which tells the reader about the byte
51 order and the size of the following entries. */
52 word
= 0xdeb00000 | sizeof (void *);
53 if (TEMP_FAILURE_RETRY (write (fd
, &word
, 4)) != 4)
55 /* If even this fails we shouldn't try further. */
66 __attribute__ ((destructor
))
75 __cyg_profile_func_enter (void *this_fn
, void *call_site
)
82 /* Now write out the current position and that of the caller. We do
83 this now, and don't cache the because we want real-time output. */
87 write (fd
, buf
, sizeof buf
);
89 /* We don't handle entry and exit differently here. */
90 strong_alias (__cyg_profile_func_enter
, __cyg_profile_func_exit
)