File: SyncTracer.cpp

package info (click to toggle)
spring 0.81.2.1%2Bdfsg1-6
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 28,496 kB
  • ctags: 37,096
  • sloc: cpp: 238,659; ansic: 13,784; java: 12,175; awk: 3,428; python: 1,159; xml: 738; perl: 405; sh: 297; makefile: 267; pascal: 228; objc: 192
file content (125 lines) | stat: -rw-r--r-- 2,200 bytes parent folder | download
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
116
117
118
119
120
121
122
123
124
125
// SyncTracer.cpp: implementation of the CSyncTracer class.
//
//////////////////////////////////////////////////////////////////////

#include "StdAfx.h"
#include "SyncTracer.h"
#include <stdio.h>
#include "LogOutput.h"
#include "GlobalUnsynced.h"
#include "mmgr.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CSyncTracer tracefile;

bool CSyncTracer::init()
{
#ifdef TRACE_SYNC
	if (logfile == 0) {
		char c[100];
		if (gu)
			sprintf(c, "trace%i.log", gu->myTeam);
		else
			sprintf(c, "trace_early.log");
		logfile = new std::ofstream(c);
		logOutput.Print("Sync trace log: %s\n", c);
	}
#endif
	return logfile != 0;
}

CSyncTracer::CSyncTracer()
{
	file = 0;
	logfile = 0;
	nowActive = 0;
	firstActive = 0;
}

CSyncTracer::~CSyncTracer()
{
#ifdef TRACE_SYNC
	delete file;
	delete logfile;
#endif
}

void CSyncTracer::Commit()
{
#ifdef TRACE_SYNC
	if(file == 0){
		char c[100];
		if (gu)
			sprintf(c, "trace%i.log", gu->myTeam);
		else
			sprintf(c, "trace_early.log");
		file = new std::ofstream(c);
	}
#endif

	if (!file)
		return;

	(*file) << traces[firstActive].c_str();
	while(nowActive!=firstActive){
		firstActive++;
		if(firstActive==10)
			firstActive=0;
		(*file) << traces[firstActive].c_str();
	}
	traces[nowActive]="";
}

void CSyncTracer::NewInterval()
{
	nowActive++;
	if(nowActive==10)
		nowActive=0;
	traces[nowActive]="";
}

void CSyncTracer::DeleteInterval()
{
	if(firstActive!=nowActive)
		firstActive++;
	if(firstActive==10)
		firstActive=0;
}

CSyncTracer& CSyncTracer::operator<<(const char* c)
{
	traces[nowActive]+=c;
	if (init()) (*logfile) << c;
	return *this;
}

CSyncTracer& CSyncTracer::operator<<(const int i)
{
	char t[20];
	sprintf(t,"%d",i);
	traces[nowActive]+=t;
	if (init()) (*logfile) << i;
	return *this;
}

CSyncTracer& CSyncTracer::operator<<(const unsigned i)
{
	char t[20];
	sprintf(t,"%d",i);
	traces[nowActive]+=t;
	if (init()) (*logfile) << i;
	return *this;
}

CSyncTracer& CSyncTracer::operator<<(const float f)
{
	char t[50];
	sprintf(t,"%f",f);
	traces[nowActive]+=t;
	if (init()) (*logfile) << f;
	return *this;
}