* g++.dg/cpp0x/pr79296.C: Move dg-do compile directive first.
[official-gcc.git] / libcilkrts / runtime / stats.c
blob407a85ddd98a62a05bd32b539cd3d08f52969697
1 /* stats.c -*-C-*-
3 *************************************************************************
5 * Copyright (C) 2009-2016, Intel Corporation
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
17 * distribution.
18 * * Neither the name of Intel Corporation nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
29 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
30 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
32 * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
35 * *********************************************************************
37 * PLEASE NOTE: This file is a downstream copy of a file mainitained in
38 * a repository at cilkplus.org. Changes made to this file that are not
39 * submitted through the contribution process detailed at
40 * http://www.cilkplus.org/submit-cilk-contribution will be lost the next
41 * time that a new version is released. Changes only submitted to the
42 * GNU compiler collection or posted to the git repository at
43 * https://bitbucket.org/intelcilkruntime/intel-cilk-runtime.git are
44 * not tracked.
46 * We welcome your contributions to this open source project. Thank you
47 * for your assistance in helping us improve Cilk Plus.
48 **************************************************************************/
50 #include "stats.h"
51 #include "bug.h"
52 #include "os.h"
53 #include "local_state.h"
55 #include <stdio.h>
57 #define INVALID_START (0ULL - 1ULL)
59 #ifdef CILK_PROFILE
60 /* MSVC does not support designated initializers, grrrr... */
61 static const char *names[] = {
62 /*[INTERVAL_IN_SCHEDULER]*/ "in scheduler",
63 /*[INTERVAL_WORKING]*/ " of which: working",
64 /*[INTERVAL_IN_RUNTIME]*/ " of which: in runtime",
65 /*[INTERVAL_IN_SCHED_LOOP]*/ " of which: in sched loop",
66 /*[INTERVAL_STEALING]*/ " of which: stealing",
67 /*[INTERVAL_STEAL_SUCCESS]*/ "steal success: detach",
68 /*[INTERVAL_STEAL_FAIL_EMPTYQ]*/ "steal fail: empty queue",
69 /*[INTERVAL_STEAL_FAIL_LOCK]*/ "steal fail: victim locked",
70 /*[INTERVAL_STEAL_FAIL_USER_WORKER]*/ "steal fail: user worker",
71 /*[INTERVAL_STEAL_FAIL_DEKKER]*/ "steal fail: dekker",
72 /*[INTERVAL_SYNC_CHECK]*/ "sync check",
73 /*[INTERVAL_THE_EXCEPTION_CHECK]*/ "THE exception check",
74 /*[INTERVAL_THE_EXCEPTION_CHECK_USELESS]*/ " of which: useless",
75 /*[INTERVAL_RETURNING]*/ "returning",
76 /*[INTERVAL_FINALIZE_CHILD]*/ "finalize child",
77 /*[INTERVAL_PROVABLY_GOOD_STEAL]*/ "provably good steal",
78 /*[INTERVAL_UNCONDITIONAL_STEAL]*/ "unconditional steal",
79 /*[INTERVAL_ALLOC_FULL_FRAME]*/ "alloc full frame",
80 /*[INTERVAL_FRAME_ALLOC_LARGE]*/ "large frame alloc",
81 /*[INTERVAL_FRAME_ALLOC]*/ "small frame alloc",
82 /*[INTERVAL_FRAME_ALLOC_GLOBAL]*/ " of which: to global pool",
83 /*[INTERVAL_FRAME_FREE_LARGE]*/ "large frame free",
84 /*[INTERVAL_FRAME_FREE]*/ "small frame free",
85 /*[INTERVAL_FRAME_FREE_GLOBAL]*/ " of which: to global pool",
86 /*[INTERVAL_MUTEX_LOCK]*/ "mutex lock",
87 /*[INTERVAL_MUTEX_LOCK_SPINNING]*/ " spinning",
88 /*[INTERVAL_MUTEX_LOCK_YIELDING]*/ " yielding",
89 /*[INTERVAL_MUTEX_TRYLOCK]*/ "mutex trylock",
90 /*[INTERVAL_FIBER_ALLOCATE]*/ "fiber_allocate",
91 /*[INTERVAL_FIBER_DEALLOCATE]*/ "fiber_deallocate",
92 /*[INTERVAL_FIBER_ALLOCATE_FROM_THREAD]*/ "fiber_allocate_from_thread",
93 /*[INTERVAL_FIBER_DEALLOCATE_FROM_THREAD]*/ "fiber_deallocate (thread)",
94 /*[INTERVAL_SUSPEND_RESUME_OTHER]*/ "fiber suspend self + resume",
95 /*[INTERVAL_DEALLOCATE_RESUME_OTHER]*/ "fiber deallocate self + resume",
96 /*[INTERVAL_INIT_WORKER]*/ "init worker thread",
97 /*[INTERVAL_SCHEDULE_WAIT]*/ "schedule wait state",
99 #endif
101 void __cilkrts_init_stats(statistics *s)
103 int i;
104 for (i = 0; i < INTERVAL_N; ++i) {
105 s->start[i] = INVALID_START;
106 s->accum[i] = 0;
107 s->count[i] = 0;
110 s->stack_hwm = 0;
113 #ifdef CILK_PROFILE
114 void __cilkrts_accum_stats(statistics *to, statistics *from)
116 int i;
118 for (i = 0; i < INTERVAL_N; ++i) {
119 to->accum[i] += from->accum[i];
120 to->count[i] += from->count[i];
121 from->accum[i] = 0;
122 from->count[i] = 0;
125 if (from->stack_hwm > to->stack_hwm)
126 to->stack_hwm = from->stack_hwm;
127 from->stack_hwm = 0;
130 void __cilkrts_note_interval(__cilkrts_worker *w, enum interval i)
132 if (w) {
133 statistics *s = w->l->stats;
134 CILK_ASSERT(s->start[i] == INVALID_START);
135 s->count[i]++;
139 void __cilkrts_start_interval(__cilkrts_worker *w, enum interval i)
141 if (w) {
142 statistics *s = w->l->stats;
143 CILK_ASSERT(s->start[i] == INVALID_START);
144 s->start[i] = __cilkrts_getticks();
145 s->count[i]++;
149 void __cilkrts_stop_interval(__cilkrts_worker *w, enum interval i)
151 if (w) {
152 statistics *s = w->l->stats;
153 CILK_ASSERT(s->start[i] != INVALID_START);
154 s->accum[i] += __cilkrts_getticks() - s->start[i];
155 s->start[i] = INVALID_START;
159 void dump_stats_to_file(FILE *stat_file, statistics *s)
161 // Only print out stats for worker if they are nonzero.
162 if (s->accum[INTERVAL_IN_SCHEDULER] > 0) {
163 int i;
164 fprintf(stat_file, "\nCILK PLUS RUNTIME SYSTEM STATISTICS:\n\n");
165 fprintf(stat_file,
166 " %-32s: %15s %10s %12s %10s\n",
167 "event",
168 "count",
169 "ticks",
170 "ticks/count",
171 "%total"
173 for (i = 0; i < INTERVAL_N; ++i) {
174 fprintf(stat_file, " %-32s: %15llu", names[i], s->count[i]);
175 if (s->accum[i]) {
176 fprintf(stat_file, " %10.3g %12.3g %10.2f",
177 (double)s->accum[i],
178 (double)s->accum[i] / (double)s->count[i],
179 100.0 * (double)s->accum[i] /
180 (double)s->accum[INTERVAL_IN_SCHEDULER]);
182 fprintf(stat_file, "\n");
185 else {
186 fprintf(stat_file, "empty statistics\n");
189 #endif // CILK_PROFILE
191 /* End stats.c */