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 45 of file XrdClCopy.cc.

Constructor & Destructor Documentation

◆ ProgressDisplay() [1/2]

ProgressDisplay::ProgressDisplay ( )
inline

Constructor.

Definition at line 51 of file XrdClCopy.cc.

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

◆ 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 59 of file XrdClCopy.cc.

63  {
64  XrdSysMutexHelper scopedLock( pMutex );
65  if( pPrintProgressBar )
66  {
67  if( jobTotal > 1 )
68  {
69  std::cerr << "Job: " << jobNum << "/" << jobTotal << std::endl;
70  std::cerr << "Source: " << source->GetURL() << std::endl;
71  std::cerr << "Target: " << destination->GetURL() << std::endl;
72  }
73  }
74  pPrevious = 0;
75 
76  JobData d;
77  d.started = time(0);
78  d.source = source;
79  d.target = destination;
80  pOngoingJobs[jobNum] = d;
81  }
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 86 of file XrdClCopy.cc.

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

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

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 188 of file XrdClCopy.cc.

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

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 219 of file XrdClCopy.cc.

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

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 282 of file XrdClCopy.cc.

282 { 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 254 of file XrdClCopy.cc.

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

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 279 of file XrdClCopy.cc.

279 { pPrintProgressBar = print; }

Referenced by main().

+ Here is the caller graph for this function:

◆ PrintSourceCheckSum()

void ProgressDisplay::PrintSourceCheckSum ( bool  print)
inline

Definition at line 280 of file XrdClCopy.cc.

280 { pPrintSourceCheckSum = print; }

Referenced by main().

+ Here is the caller graph for this function:

◆ PrintTargetCheckSum()

void ProgressDisplay::PrintTargetCheckSum ( bool  print)
inline

Definition at line 281 of file XrdClCopy.cc.

281 { pPrintTargetCheckSum = print; }

Referenced by main().

+ Here is the caller graph for this function:

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