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

Public Member Functions

 ProgressDisplay ()
 Constructor. More...
 
 ProgressDisplay ()
 
virtual void BeginJob (uint32_t jobNum, uint32_t jobTotal, const XrdCl::URL *source, const XrdCl::URL *destination)
 Begin job. More...
 
virtual void EndJob (uint32_t jobNum, const XrdCl::PropertyList *results)
 End job. More...
 
virtual void EndJob (uint32_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 (uint32_t jobNum, uint64_t bytesProcessed, uint64_t bytesTotal)
 Job progress. More...
 
virtual void JobProgress (uint32_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 (uint32_t jobNum)
 Determine whether the job should be canceled. More...
 

Detailed Description

Definition at line 50 of file XrdClCopy.cc.

Constructor & Destructor Documentation

◆ ProgressDisplay() [1/2]

ProgressDisplay::ProgressDisplay ( )
inline

Constructor.

Definition at line 56 of file XrdClCopy.cc.

56  : pPrevious(0), pPrintProgressBar(true),
57  pPrintSourceCheckSum(false), pPrintTargetCheckSum(false),
58  pPrintAdditionalCheckSum(false)
59  {}

◆ ProgressDisplay() [2/2]

ProgressDisplay::ProgressDisplay ( )
inline

Definition at line 1558 of file XrdClFS.cc.

1558  : pBytesProcessed(0), pBytesTotal(0), pPrevious(0)
1559  {}

Member Function Documentation

◆ BeginJob()

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

Begin job.

Reimplemented from XrdCl::CopyProgressHandler.

Definition at line 64 of file XrdClCopy.cc.

68  {
69  XrdSysMutexHelper scopedLock( pMutex );
70  if( pPrintProgressBar )
71  {
72  if( jobTotal > 1 )
73  {
74  std::cerr << "Job: " << jobNum << "/" << jobTotal << std::endl;
75  std::cerr << "Source: " << source->GetURL() << std::endl;
76  std::cerr << "Target: " << destination->GetURL() << std::endl;
77  }
78  }
79  pPrevious = 0;
80 
81  JobData d;
82  d.started = time(0);
83  d.source = source;
84  d.target = destination;
85  pOngoingJobs[jobNum] = d;
86  }
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 ( uint32_t  jobNum,
const XrdCl::PropertyList *  results 
)
inlinevirtual

End job.

Reimplemented from XrdCl::CopyProgressHandler.

Definition at line 91 of file XrdClCopy.cc.

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

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

+ Here is the call graph for this function:

◆ EndJob() [2/2]

virtual void ProgressDisplay::EndJob ( uint32_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 1564 of file XrdClFS.cc.

1565  {
1566  JobProgress( jobNum, pBytesProcessed, pBytesTotal );
1567  std::cerr << std::endl;
1568  }

◆ GetProgressBar()

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

Get progress bar.

Definition at line 151 of file XrdClCopy.cc.

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

References XrdCl::Utils::BytesToString().

+ Here is the call graph for this function:

◆ GetSummaryBar()

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

Get sumary bar.

Definition at line 193 of file XrdClCopy.cc.

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

References XrdCl::Utils::BytesToString().

+ Here is the call graph for this function:

◆ JobProgress() [1/2]

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

Job progress.

Reimplemented from XrdCl::CopyProgressHandler.

Definition at line 224 of file XrdClCopy.cc.

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

◆ JobProgress() [2/2]

virtual void ProgressDisplay::JobProgress ( uint32_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 1573 of file XrdClFS.cc.

1576  {
1577  pBytesProcessed = bytesProcessed;
1578  pBytesTotal = bytesTotal;
1579 
1580  time_t now = time(0);
1581  if( (now - pPrevious < 1) && (bytesProcessed != bytesTotal) )
1582  return;
1583  pPrevious = now;
1584 
1585  std::cerr << "\r";
1586  std::cerr << "Progress: ";
1587  std::cerr << XrdCl::Utils::BytesToString(bytesProcessed) << "B ";
1588 
1589  if( bytesTotal )
1590  std::cerr << "(" << bytesProcessed*100/bytesTotal << "%)";
1591 
1592  std::cerr << std::flush;
1593  }

References XrdCl::Utils::BytesToString().

+ Here is the call graph for this function:

◆ PrintAdditionalCheckSum()

void ProgressDisplay::PrintAdditionalCheckSum ( bool  print)
inline

Definition at line 287 of file XrdClCopy.cc.

287 { 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 259 of file XrdClCopy.cc.

262  {
263  if( checkSum.empty() )
264  return;
265  std::string::size_type i = checkSum.find( ':' );
266  std::cerr << checkSum.substr( 0, i+1 ) << " ";
267  std::cerr << checkSum.substr( i+1, checkSum.length()-i ) << " ";
268 
269  if( url->IsLocalFile() )
270  std::cerr << url->GetPath() << " ";
271  else
272  {
273  std::cerr << url->GetProtocol() << "://" << url->GetHostId();
274  std::cerr << url->GetPath() << " ";
275  }
276 
277  std::cerr << size;
278  std::cerr << std::endl;
279  }
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:450
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().

+ Here is the call graph for this function:

◆ PrintProgressBar()

void ProgressDisplay::PrintProgressBar ( bool  print)
inline

Definition at line 284 of file XrdClCopy.cc.

284 { pPrintProgressBar = print; }

Referenced by main().

+ Here is the caller graph for this function:

◆ PrintSourceCheckSum()

void ProgressDisplay::PrintSourceCheckSum ( bool  print)
inline

Definition at line 285 of file XrdClCopy.cc.

285 { pPrintSourceCheckSum = print; }

Referenced by main().

+ Here is the caller graph for this function:

◆ PrintTargetCheckSum()

void ProgressDisplay::PrintTargetCheckSum ( bool  print)
inline

Definition at line 286 of file XrdClCopy.cc.

286 { pPrintTargetCheckSum = print; }

Referenced by main().

+ Here is the caller graph for this function:

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