-
Notifications
You must be signed in to change notification settings - Fork 149
/
MonitorTestLib.cc
213 lines (196 loc) · 8.87 KB
/
MonitorTestLib.cc
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
//------------------------------------------------------------------------------
// Copyright (c) 2012 by European Organization for Nuclear Research (CERN)
// Author: Lukasz Janyst <ljanyst@cern.ch>
//------------------------------------------------------------------------------
// XRootD is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// XRootD is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with XRootD. If not, see <http://www.gnu.org/licenses/>.
//------------------------------------------------------------------------------
#include "XrdCl/XrdClMonitor.hh"
#include "XrdCl/XrdClLog.hh"
#include "XrdCl/XrdClUtils.hh"
#include "XrdVersion.hh"
#include "TestEnv.hh"
XrdVERSIONINFO( XrdClGetMonitor, MonitorTest );
class MonitorTest: public XrdCl::Monitor
{
public:
//--------------------------------------------------------------------------
// Contructor
//--------------------------------------------------------------------------
MonitorTest( const std::string &exec, const std::string ¶m ):
pExec( exec ),
pParam( param ),
pInitialized(false)
{
XrdCl::Log *log = XrdClTests::TestEnv::GetLog();
log->Debug( 2, "Constructed monitoring, exec %s, param %s",
exec.c_str(), param.c_str() );
}
//--------------------------------------------------------------------------
// Destructor
//--------------------------------------------------------------------------
virtual ~MonitorTest() {}
//--------------------------------------------------------------------------
// Event
//--------------------------------------------------------------------------
virtual void Event( EventCode evCode, void *evData )
{
using namespace XrdCl;
using namespace XrdClTests;
Log *log = TestEnv::GetLog();
switch( evCode )
{
//----------------------------------------------------------------------
// Got a connect event
//----------------------------------------------------------------------
case EvConnect:
{
ConnectInfo *i = (ConnectInfo*)evData;
std::string timeStarted = Utils::TimeToString( i->sTOD.tv_sec );
std::string timeDone = Utils::TimeToString( i->sTOD.tv_sec );
log->Debug( 2, "Successfully connected to: %s, started: %s, "
"finished: %s, authentication: %s, streams: %d",
i->server.c_str(), timeStarted.c_str(), timeDone.c_str(),
i->auth.empty() ? "none" : i->auth.c_str(),
i->streams );
break;
}
//----------------------------------------------------------------------
// Got a disconnect event
//----------------------------------------------------------------------
case EvDisconnect:
{
DisconnectInfo *i = (DisconnectInfo*)evData;
log->Debug( 2, "Disconnected from: %s, bytes sent: %ld, "
"bytes received: %ld, connection time: %d, "
"disconnection status: %s",
i->server.c_str(), i->sBytes, i->rBytes,
i->cTime, i->status.ToString().c_str() );
break;
}
//----------------------------------------------------------------------
// Got an open event
//----------------------------------------------------------------------
case EvOpen:
{
OpenInfo *i = (OpenInfo*)evData;
log->Debug( 2, "Successfully opened file %s at %s, size %ld",
i->file->GetURL().c_str(), i->dataServer.c_str(),
i->fSize );
break;
}
//----------------------------------------------------------------------
// Got a close event
//----------------------------------------------------------------------
case EvClose:
{
CloseInfo *i = (CloseInfo*)evData;
std::string timeOpen = Utils::TimeToString( i->oTOD.tv_sec );
std::string timeClosed = Utils::TimeToString( i->cTOD.tv_sec );
log->Debug( 2, "Closed file %s, opened: %s, closed: %s, status: %s",
i->file->GetURL().c_str(), timeOpen.c_str(),
timeClosed.c_str(), i->status->ToStr().c_str() );
log->Debug( 2, "Closed file %s, bytes: read: %ld, readv: %ld, write:"
" %ld, writev: %ld", i->file->GetURL().c_str(), i->rBytes, i->vrBytes,
i->wBytes, i->vwBytes );
log->Debug( 2, "Closed file %s, count: read: %d, readv: %d/%d, "
"write: %d", i->file->GetURL().c_str(), i->rCount,
i->vCount, i->vSegs, i->wCount );
break;
}
//----------------------------------------------------------------------
// Got an error event
//----------------------------------------------------------------------
case EvErrIO:
{
ErrorInfo *i = (ErrorInfo*)evData;
std::string op;
switch( i->opCode )
{
case ErrorInfo::ErrOpen: op = "Open"; break;
case ErrorInfo::ErrRead: op = "Read"; break;
case ErrorInfo::ErrReadV: op = "ReadV"; break;
case ErrorInfo::ErrWrite: op = "Write"; break;
case ErrorInfo::ErrWriteV: op = "WriteV"; break;
case ErrorInfo::ErrUnc: op = "Unclassified"; break;
};
log->Debug( 2, "Operation on file %s encountered an error: %s "
"while %s", i->file->GetURL().c_str(),
i->status->ToStr().c_str(), op.c_str() );
break;
}
//----------------------------------------------------------------------
// Got a copy begin event
//----------------------------------------------------------------------
case EvCopyBeg:
{
CopyBInfo *i = (CopyBInfo*)evData;
log->Debug( 2, "Copy operation started: origin %s, target: %s ",
i->transfer.origin->GetURL().c_str(),
i->transfer.target->GetURL().c_str() );
break;
}
//----------------------------------------------------------------------
// Got a copy end event
//----------------------------------------------------------------------
case EvCopyEnd:
{
CopyEInfo *i = (CopyEInfo*)evData;
std::string timeStart = Utils::TimeToString( i->bTOD.tv_sec );
std::string timeEnd = Utils::TimeToString( i->eTOD.tv_sec );
log->Debug( 2, "Copy operation ended: origin: %s, target: %s, "
"start time %s, end time: %s, status: %s",
i->transfer.origin->GetURL().c_str(),
i->transfer.target->GetURL().c_str(),
timeStart.c_str(), timeEnd.c_str(),
i->status->ToStr().c_str() );
break;
}
//----------------------------------------------------------------------
// Got a copy end event
//----------------------------------------------------------------------
case EvCheckSum:
{
CheckSumInfo *i = (CheckSumInfo*)evData;
log->Debug( 2, "Checksum for transfer: origin: %s, target: %s, "
"checksum %s, is ok: %d",
i->transfer.origin->GetURL().c_str(),
i->transfer.target->GetURL().c_str(),
i->cksum.c_str(), (int)i->isOK );
log->Debug( 2, "Checksum for transfer: origin: %s, target: %s, "
"us elapsed at origin %ld, us leapsed at target: %ld",
i->transfer.origin->GetURL().c_str(),
i->transfer.target->GetURL().c_str(),
i->oTime, i->tTime );
break;
}
}
}
private:
std::string pExec;
std::string pParam;
bool pInitialized;
};
//------------------------------------------------------------------------------
// C-mangled symbol for dlopen
//------------------------------------------------------------------------------
extern "C"
{
void *XrdClGetMonitor( const char *exec, const char *param )
{
XrdCl::Log *log = XrdClTests::TestEnv::GetLog();
log->Debug( 2, "Constructing monitoring, exec %s, param %s",
exec, param ? param : "" );
return new MonitorTest( exec, param ? param : "" );
}
}