-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathstats.c
More file actions
115 lines (103 loc) · 3.23 KB
/
stats.c
File metadata and controls
115 lines (103 loc) · 3.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
* ---- The Unbalanced Tree Search (UTS) Benchmark ----
*
* Copyright (c) 2010 See AUTHORS file for copyright holders
*
* This file is part of the unbalanced tree search benchmark. This
* project is licensed under the MIT Open Source license. See the LICENSE
* file for copyright and licensing information.
*
* UTS is a collaborative project between researchers at the University of
* Maryland, the University of North Carolina at Chapel Hill, and the Ohio
* State University. See AUTHORS file for more information.
*
*/
/***********************************************************
* *
* TRACING EXTENSION TO UTS: *
* *
***********************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <sys/time.h>
#include "uts_dm.h"
#ifndef sgi
double wctime() {
struct timeval tv;
gettimeofday(&tv, NULL);
return (tv.tv_sec + 1E-6 * tv.tv_usec);
}
#else
double wctime() {
timespec_t tv;
double time;
clock_gettime(CLOCK_SGI_CYCLE,&tv);
time = ((double) tv.tv_sec) + ((double)tv.tv_nsec / 1e9);
if (debug&16)
printf("SGI high resolution clock: %f\n",time);
return time;
}
#endif
/* Initialize trace collection stuff */
void ss_initStats(StealStack *s) {
int i;
s->timeLast = wctime();
for (i = 0; i < SS_NSTATES; i++) {
s->time[i] = 0.0;
s->entries[i] = 0;
}
s->curState = SS_IDLE;
}
/* Change states */
void ss_setState(StealStack *s, int state) {
double time;
if (state < 0 || state >= SS_NSTATES)
ss_error("ss_setState: thread state out of range", 1);
if (state == s->curState)
return;
time = wctime();
s->time[s->curState] += time - s->timeLast;
#ifdef TRACE
/* close out last session record */
s->sessionRecords[s->curState][s->entries[s->curState] - 1].endTime = time;
if (s->curState == SS_WORK) {
s->stealRecords[s->entries[SS_WORK] - 1].nodeCount = s->nNodes
- s->stealRecords[s->entries[SS_WORK] - 1].nodeCount;
}
/* initialize new session record */
s->sessionRecords[state][s->entries[state]].startTime = time;
if (state == SS_WORK) {
s->stealRecords[s->entries[SS_WORK]].nodeCount = s->nNodes;
}
#endif
s->entries[state]++;
s->timeLast = time;
s->curState = state;
}
#ifdef TRACE
// print session records for each thread (used when trace is enabled)
void ss_printTrace(StealStack *s, int numRecords) {
int i, j, k;
double offset;
for (i = 0; i < numRecords; i++) {
offset = s[i].startTime - s[0].startTime;
for (j = 0; j < SS_NSTATES; j++)
for (k = 0; k < s[i].entries[j]; k++) {
printf ("%d %d %f %f", i, j,
s[i].sessionRecords[j][k].startTime - offset,
s[i].sessionRecords[j][k].endTime - offset);
if (j == SS_WORK)
printf (" %d %ld",
s[i].stealRecords[k].victimThread,
s[i].stealRecords[k].nodeCount);
printf ("\n");
}
}
}
/* Called when we have a successful steal to update our stats */
void ss_markSteal(StealStack *s, int victim) {
/* update session record of theif */
s->stealRecords[s->entries[SS_WORK]].victimThread = victim;
}
#endif