Add .gitignore file
[s390-tools.git] / vmconvert / dump.cpp
blobb4c97d6ca5d241cb4ec5bb61b5f7e419ca05c7c0
1 /*
2 * dump.cpp
3 * dump base class
4 *
5 * Copyright IBM Corp. 2004, 2006.
6 *
7 * Author(s): Michael Holzheu
8 */
10 #include "dump.h"
12 int debug = 0;
14 void
15 s390TodToTimeval(uint64_t todval, struct timeval *xtime)
17 /* adjust todclock to 1970 */
18 todval -= 0x8126d60e46000000LL - (0x3c26700LL * 1000000 * 4096);
20 todval >>= 12;
21 xtime->tv_sec = todval / 1000000;
22 xtime->tv_usec = todval % 1000000;
25 Dump::Dump(const char *filename, const char *mode)
27 fh = fopen(filename, mode);
28 if(!fh){
29 throw(DumpErrnoException("Open dump file failed!"));
33 Dump::~Dump(void)
35 if(fh){
36 fclose(fh);
40 void
41 ProgressBar::initProgress(void)
43 progressPercentage = -1;
46 void
47 ProgressBar::displayProgress(uint64_t value, uint64_t maxValue)
49 char progress_bar[51];
50 int j;
52 if (progressPercentage == (int) (value * 100 / maxValue))
53 fprintf(stderr, "%6lld of %6lld |\r",
54 (long long) value, (long long) maxValue);
55 else { /* percent value has changed */
56 progressPercentage = (value * 100 / maxValue);
57 for (j = 0; j < progressPercentage / 2; j++)
58 progress_bar[j] = '#';
59 for (j = progressPercentage / 2; j < 50; j++)
60 progress_bar[j] = '-';
61 progress_bar[50] = 0;
62 fprintf(stderr, "%6lld of %6lld |%s| %3d%% \r",
63 (long long) value, (long long) maxValue,
64 progress_bar, progressPercentage);