XRootD
ProgressDisplay Class Reference
+ Inheritance diagram for ProgressDisplay:
+ Collaboration diagram for ProgressDisplay:

Public Member Functions

 ProgressDisplay ()
 Constructor. More...
 
 ProgressDisplay ()
 
virtual void BeginJob (uint16_t jobNum, uint16_t jobTotal, const XrdCl::URL *source, const XrdCl::URL *destination)
 Begin job. More...
 
virtual void EndJob (uint16_t jobNum, const XrdCl::PropertyList *results)
 End job. More...
 
virtual void EndJob (uint16_t jobNum, const XrdCl::PropertyList *results)
 
std::string GetProgressBar (time_t now)
 Get progress bar. More...
 
std::string GetSummaryBar (time_t now)
 Get sumary bar. More...
 
virtual void JobProgress (uint16_t jobNum, uint64_t bytesProcessed, uint64_t bytesTotal)
 Job progress. More...
 
virtual void JobProgress (uint16_t jobNum, uint64_t bytesProcessed, uint64_t bytesTotal)
 
void PrintAdditionalCheckSum (bool print)
 
void PrintCheckSum (const XrdCl::URL *url, const std::string &checkSum, uint64_t size)
 Print the checksum. More...
 
void PrintProgressBar (bool print)
 
void PrintSourceCheckSum (bool print)
 
void PrintTargetCheckSum (bool print)
 
- Public Member Functions inherited from XrdCl::CopyProgressHandler
virtual ~CopyProgressHandler ()
 
virtual bool ShouldCancel (uint16_t jobNum)
 Determine whether the job should be canceled. More...
 

Detailed Description

Definition at line 47 of file XrdClCopy.cc.

Constructor & Destructor Documentation

◆ ProgressDisplay() [1/2]

ProgressDisplay::ProgressDisplay ( )
inline

Constructor.

Definition at line 53 of file XrdClCopy.cc.

53  : pPrevious(0), pPrintProgressBar(true),
54  pPrintSourceCheckSum(false), pPrintTargetCheckSum(false),
55  pPrintAdditionalCheckSum(false)
56  {}

◆ ProgressDisplay() [2/2]

ProgressDisplay::ProgressDisplay ( )
inline

Definition at line 1427 of file XrdClFS.cc.

1427  : pBytesProcessed(0), pBytesTotal(0), pPrevious(0)
1428  {}

Member Function Documentation

◆ BeginJob()

virtual void ProgressDisplay::BeginJob ( uint16_t  jobNum,
uint16_t  jobTotal,
const XrdCl::URL source,
const XrdCl::URL destination 
)
inlinevirtual

Begin job.

Reimplemented from XrdCl::CopyProgressHandler.

Definition at line 61 of file XrdClCopy.cc.

65  {
66  XrdSysMutexHelper scopedLock( pMutex );
67  if( pPrintProgressBar )
68  {
69  if( jobTotal > 1 )
70  {
71  std::cerr << "Job: " << jobNum << "/" << jobTotal << std::endl;
72  std::cerr << "Source: " << source->GetURL() << std::endl;
73  std::cerr << "Target: " << destination->GetURL() << std::endl;
74  }
75  }
76  pPrevious = 0;
77 
78  JobData d;
79  d.started = time(0);
80  d.source = source;
81  d.target = destination;
82  pOngoingJobs[jobNum] = d;
83  }
std::string GetURL() const
Get the URL.
Definition: XrdClURL.hh:86

References XrdCl::URL::GetURL().

+ Here is the call graph for this function:

◆ EndJob() [1/2]

virtual void ProgressDisplay::EndJob ( uint16_t  jobNum,
const XrdCl::PropertyList results 
)
inlinevirtual

End job.

Reimplemented from XrdCl::CopyProgressHandler.

Definition at line 88 of file XrdClCopy.cc.

89  {
90  XrdSysMutexHelper scopedLock( pMutex );
91 
92  std::map<uint16_t, JobData>::iterator it = pOngoingJobs.find( jobNum );
93  if( it == pOngoingJobs.end() )
94  return;
95 
96  JobData &d = it->second;
97 
98  // make sure the last available status was printed, which may not be
99  // the case when processing stdio since we throttle printing and don't
100  // know the total size
101  JobProgress( jobNum, d.bytesProcessed, d.bytesTotal );
102 
103  if( pPrintProgressBar )
104  {
105  if( pOngoingJobs.size() > 1 )
106  std::cerr << "\r" << std::string(70, ' ') << "\r";
107  else
108  std::cerr << std::endl;
109  }
110 
112  results->Get( "status", st );
113  if( !st.IsOK() )
114  {
115  pOngoingJobs.erase(it);
116  return;
117  }
118 
119  std::string checkSum;
120  uint64_t size;
121  results->Get( "size", size );
122  if( pPrintSourceCheckSum )
123  {
124  results->Get( "sourceCheckSum", checkSum );
125  PrintCheckSum( d.source, checkSum, size );
126  }
127 
128  if( pPrintTargetCheckSum )
129  {
130  results->Get( "targetCheckSum", checkSum );
131  PrintCheckSum( d.target, checkSum, size );
132  }
133 
134  if( pPrintAdditionalCheckSum )
135  {
136  std::vector<std::string> addcksums;
137  results->Get( "additionalCkeckSum", addcksums );
138  for( auto &cks : addcksums )
139  PrintCheckSum( d.source, cks, size );
140  }
141 
142  pOngoingJobs.erase(it);
143  }
void PrintCheckSum(const XrdCl::URL *url, const std::string &checkSum, uint64_t size)
Print the checksum.
Definition: XrdClCopy.cc:256
virtual void JobProgress(uint16_t jobNum, uint64_t bytesProcessed, uint64_t bytesTotal)
Job progress.
Definition: XrdClCopy.cc:221
bool Get(const std::string &name, Item &item) const
bool IsOK() const
We're fine.
Definition: XrdClStatus.hh:124

References XrdCl::PropertyList::Get(), XrdCl::Status::IsOK(), JobProgress(), and PrintCheckSum().

+ Here is the call graph for this function:

◆ EndJob() [2/2]

virtual void ProgressDisplay::EndJob ( uint16_t  jobNum,
const XrdCl::PropertyList result 
)
inlinevirtual

Notify when the previous job has finished

Parameters
jobNumjob number
resultresult of the job

Reimplemented from XrdCl::CopyProgressHandler.

Definition at line 1433 of file XrdClFS.cc.

1434  {
1435  JobProgress( jobNum, pBytesProcessed, pBytesTotal );
1436  std::cerr << std::endl;
1437  }

◆ GetProgressBar()

std::string ProgressDisplay::GetProgressBar ( time_t  now)
inline

Get progress bar.

Definition at line 148 of file XrdClCopy.cc.

149  {
150  JobData &d = pOngoingJobs.begin()->second;
151 
152  uint64_t speed = 0;
153  if( now-d.started )
154  speed = d.bytesProcessed/(now-d.started);
155  else
156  speed = d.bytesProcessed;
157 
158  std::string bar;
159  int prog = 0;
160  int proc = 0;
161 
162  if( d.bytesTotal )
163  {
164  prog = (int)((double)d.bytesProcessed/d.bytesTotal*50);
165  proc = (int)((double)d.bytesProcessed/d.bytesTotal*100);
166  }
167  else
168  {
169  prog = 50;
170  proc = 100;
171  }
172  bar.append( prog, '=' );
173  if( prog < 50 )
174  bar += ">";
175 
176  std::ostringstream o;
177  o << "[" << XrdCl::Utils::BytesToString(d.bytesProcessed) << "B/";
178  o << XrdCl::Utils::BytesToString(d.bytesTotal) << "B]";
179  o << "[" << std::setw(3) << std::right << proc << "%]";
180  o << "[" << std::setw(50) << std::left;
181  o << bar;
182  o << "]";
183  o << "[" << XrdCl::Utils::BytesToString(speed) << "B/s] ";
184  return o.str();
185  }
static std::string BytesToString(uint64_t bytes)
Convert bytes to a human readable string.
Definition: XrdClUtils.cc:367

References XrdCl::Utils::BytesToString().

Referenced by JobProgress().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetSummaryBar()

std::string ProgressDisplay::GetSummaryBar ( time_t  now)
inline

Get sumary bar.

Definition at line 190 of file XrdClCopy.cc.

191  {
192  std::map<uint16_t, JobData>::iterator it;
193  std::ostringstream o;
194 
195  for( it = pOngoingJobs.begin(); it != pOngoingJobs.end(); ++it )
196  {
197  JobData &d = it->second;
198  uint16_t jobNum = it->first;
199 
200  uint64_t speed = 0;
201  if( now-d.started )
202  speed = d.bytesProcessed/(now-d.started);
203 
204  int proc = 0;
205  if( d.bytesTotal )
206  proc = (int)((double)d.bytesProcessed/d.bytesTotal*100);
207  else
208  proc = 100;
209 
210  o << "[#" << jobNum << ": ";
211  o << proc << "% ";
212  o << XrdCl::Utils::BytesToString(speed) << "B/s] ";
213  }
214  o << " ";
215  return o.str();
216  }

References XrdCl::Utils::BytesToString().

Referenced by JobProgress().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ JobProgress() [1/2]

virtual void ProgressDisplay::JobProgress ( uint16_t  jobNum,
uint64_t  bytesProcessed,
uint64_t  bytesTotal 
)
inlinevirtual

Job progress.

Reimplemented from XrdCl::CopyProgressHandler.

Definition at line 221 of file XrdClCopy.cc.

224  {
225  XrdSysMutexHelper scopedLock( pMutex );
226 
227  if( pPrintProgressBar )
228  {
229  time_t now = time(0);
230  if( (now - pPrevious < 1) && (bytesProcessed != bytesTotal) )
231  return;
232  pPrevious = now;
233 
234  std::map<uint16_t, JobData>::iterator it = pOngoingJobs.find( jobNum );
235  if( it == pOngoingJobs.end() )
236  return;
237 
238  JobData &d = it->second;
239 
240  d.bytesProcessed = bytesProcessed;
241  d.bytesTotal = bytesTotal;
242 
243  std::string progress;
244  if( pOngoingJobs.size() == 1 )
245  progress = GetProgressBar( now );
246  else
247  progress = GetSummaryBar( now );
248 
249  std::cerr << "\r" << progress << std::flush;
250  }
251  }
std::string GetProgressBar(time_t now)
Get progress bar.
Definition: XrdClCopy.cc:148
std::string GetSummaryBar(time_t now)
Get sumary bar.
Definition: XrdClCopy.cc:190

References GetProgressBar(), and GetSummaryBar().

Referenced by EndJob().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ JobProgress() [2/2]

virtual void ProgressDisplay::JobProgress ( uint16_t  jobNum,
uint64_t  bytesProcessed,
uint64_t  bytesTotal 
)
inlinevirtual

Notify about the progress of the current job

Parameters
jobNumjob number
bytesProcessedbytes processed by the current job
bytesTotaltotal number of bytes to be processed by the current job

Reimplemented from XrdCl::CopyProgressHandler.

Definition at line 1442 of file XrdClFS.cc.

1445  {
1446  pBytesProcessed = bytesProcessed;
1447  pBytesTotal = bytesTotal;
1448 
1449  time_t now = time(0);
1450  if( (now - pPrevious < 1) && (bytesProcessed != bytesTotal) )
1451  return;
1452  pPrevious = now;
1453 
1454  std::cerr << "\r";
1455  std::cerr << "Progress: ";
1456  std::cerr << XrdCl::Utils::BytesToString(bytesProcessed) << "B ";
1457 
1458  if( bytesTotal )
1459  std::cerr << "(" << bytesProcessed*100/bytesTotal << "%)";
1460 
1461  std::cerr << std::flush;
1462  }

References XrdCl::Utils::BytesToString().

+ Here is the call graph for this function:

◆ PrintAdditionalCheckSum()

void ProgressDisplay::PrintAdditionalCheckSum ( bool  print)
inline

Definition at line 284 of file XrdClCopy.cc.

284 { pPrintAdditionalCheckSum = print; }

Referenced by main().

+ Here is the caller graph for this function:

◆ PrintCheckSum()

void ProgressDisplay::PrintCheckSum ( const XrdCl::URL url,
const std::string &  checkSum,
uint64_t  size 
)
inline

Print the checksum.

Definition at line 256 of file XrdClCopy.cc.

259  {
260  if( checkSum.empty() )
261  return;
262  std::string::size_type i = checkSum.find( ':' );
263  std::cerr << checkSum.substr( 0, i+1 ) << " ";
264  std::cerr << checkSum.substr( i+1, checkSum.length()-i ) << " ";
265 
266  if( url->IsLocalFile() )
267  std::cerr << url->GetPath() << " ";
268  else
269  {
270  std::cerr << url->GetProtocol() << "://" << url->GetHostId();
271  std::cerr << url->GetPath() << " ";
272  }
273 
274  std::cerr << size;
275  std::cerr << std::endl;
276  }
std::string GetHostId() const
Get the host part of the URL (user:password@host:port)
Definition: XrdClURL.hh:99
const std::string & GetProtocol() const
Get the protocol.
Definition: XrdClURL.hh:118
bool IsLocalFile() const
Definition: XrdClURL.cc:467
const std::string & GetPath() const
Get the path.
Definition: XrdClURL.hh:217

References XrdCl::URL::GetHostId(), XrdCl::URL::GetPath(), XrdCl::URL::GetProtocol(), and XrdCl::URL::IsLocalFile().

Referenced by EndJob().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ PrintProgressBar()

void ProgressDisplay::PrintProgressBar ( bool  print)
inline

Definition at line 281 of file XrdClCopy.cc.

281 { pPrintProgressBar = print; }

Referenced by main().

+ Here is the caller graph for this function:

◆ PrintSourceCheckSum()

void ProgressDisplay::PrintSourceCheckSum ( bool  print)
inline

Definition at line 282 of file XrdClCopy.cc.

282 { pPrintSourceCheckSum = print; }

Referenced by main().

+ Here is the caller graph for this function:

◆ PrintTargetCheckSum()

void ProgressDisplay::PrintTargetCheckSum ( bool  print)
inline

Definition at line 283 of file XrdClCopy.cc.

283 { pPrintTargetCheckSum = print; }

Referenced by main().

+ Here is the caller graph for this function:

The documentation for this class was generated from the following files: