Debian Codegraph @

gprofng/testsuite/gprofng.display/synprog/so_syx.c

raw symbols SCIP
1 /* Copyright (C) 2021-2025 Free Software Foundation, Inc.
2 Contributed by Oracle.
3
4 This file is part of GNU Binutils.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
9 any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, 51 Franklin Street - Fifth Floor, Boston,
19 MA 02110-1301, USA. */
20
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include "stopwatch.h"
24
25 static void sx_burncpu ();
26
27 int
28 sx_cputime ()
29 {
30 wlog ("start of sx_cputime", NULL);
31
32 /* put a memory leak in here */
33 (void) malloc (13);
34
35 fprintf (stderr, "sx_burncpu @ %p\n", sx_burncpu);
36 sx_burncpu ();
37 wlog ("end of sx_cputime", NULL);
38 return 13;
39 }
40
41 void sx_init () __attribute__ ((constructor));
42
43 void
44 sx_init ()
45 {
46 fprintf (stderr, "sx_init executed\n");
47 }
48
49 /* sx_burncpu - loop to use a bunch of user time */
50 void
51 sx_burncpu ()
52 {
53 hrtime_t start = gethrtime ();
54 hrtime_t vstart = gethrvtime ();
55 volatile float x = 0.; /* temp variable for f.p. calculation */
56 long long count = 0;
57 do
58 {
59 x = 0.0;
60 for (int j = 0; j < 100000; j++)
61 x = x + 1.0;
62 count++;
63 }
64 while (start + testtime * 1e9 > gethrtime ());
65
66 fprintf (stderr, " Performed %lld while-loop iterations\n", count);
67 whrvlog (gethrtime () - start, gethrvtime () - vstart, "sx_burncpu", NULL);
68 }