Skip to content

Commit

Permalink
c0cp progress added.
Browse files Browse the repository at this point in the history
  • Loading branch information
nezzzu committed May 31, 2020
1 parent 4160d41 commit 6aa297f
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 5 deletions.
2 changes: 2 additions & 0 deletions c0appz.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ int c0appz_timeout(uint64_t sz);
int c0appz_timein();
int c0appz_dump_perf(void);
/* qos */
int qos_pthread_wait();
int qos_pthread_start(void);
int qos_pthread_stop(int s);

/* pool */
int c0appz_pool_ini(void);
int c0appz_pool_set(int pid);
Expand Down
21 changes: 17 additions & 4 deletions c0cp.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
extern int perf; /* performance */
int force=0; /* overwrite */
int cont=0; /* continuous mode */
extern uint64_t qos_served;
extern uint64_t qos_remain;
extern uint64_t qos_laps_served;
extern uint64_t qos_laps_remain;

/* main */
int main(int argc, char **argv)
Expand Down Expand Up @@ -171,22 +175,29 @@ int main(int argc, char **argv)
stat64(fname,&fs);
assert(fsz==fs.st_size);
laps=cont;
qos_served=0;
qos_remain=bsz*cnt*laps;
qos_laps_served=0;
qos_laps_remain=laps;
qos_pthread_start();
c0appz_timein();
while(cont>0){
printf("[%d/%d]:\n",(int)laps-cont+1,(int)laps);
pos = (laps-cont)*cnt*bsz;
c0appz_mw(fbuf,idh,idl,pos,bsz,cnt);
cont--;
}
ppf("%8s","write");
c0appz_timeout((uint64_t)bsz * (uint64_t)cnt * (uint64_t)laps);
qos_pthread_stop(0);
qos_pthread_wait();
printf("%" PRIu64 " x %" PRIu64 " = %" PRIu64 "\n",cnt,bsz,cnt*bsz);
free(fbuf);
goto end;
}

qos_served=0;
qos_remain=bsz*cnt;
qos_laps_served=0;
qos_laps_remain=1;
qos_pthread_start();
c0appz_timein();
/* copy */
Expand All @@ -198,11 +209,13 @@ int main(int argc, char **argv)
};
ppf("%8s","copy");
c0appz_timeout((uint64_t)bsz * (uint64_t)cnt);
qos_pthread_stop(0);
qos_pthread_wait();

end:

qos_pthread_stop(rc);
// qos_pthread_stop(rc);
// qos_pthread_wait();


/* resize */
truncate64(fname,fs.st_size);
Expand Down
72 changes: 71 additions & 1 deletion qos.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <inttypes.h>
#include <pthread.h>

/*
Expand All @@ -35,13 +36,20 @@ pthread_mutex_t qos_lock; /* lock qos_total_weight */
static pthread_t tid; /* real-time bw thread */
extern int perf; /* option performance */

uint64_t qos_served=0;
uint64_t qos_remain=0;
uint64_t qos_laps_served=0;
uint64_t qos_laps_remain=0;

/*
******************************************************************************
* STATIC FUNCTION PROTOTYPES
******************************************************************************
*/
static int qos_print_bw(void);
static void *disp_realtime_bw(void *arg);
static int progress_rt(char *s);
static int progress_rb(char *s);

/*
******************************************************************************
Expand All @@ -63,11 +71,18 @@ int qos_pthread_stop(int s)
{
if(s) return 0;
if(!perf) return 0;
// pthread_join(tid,NULL);
if(qos_remain>0) return 0;
pthread_cancel(tid);
return 0;
}

/* qos_pthread_wait() */
int qos_pthread_wait()
{
pthread_join(tid,NULL);
return 0;
}

/*
******************************************************************************
* STATIC FUNCTIONS
Expand All @@ -80,12 +95,31 @@ int qos_pthread_stop(int s)
static int qos_print_bw(void)
{
double bw=0;
double pr=0;
char s[16];
uint64_t tot1=0;
uint64_t tot2=0;

bw=(double)qos_total_weight/1000000;
tot1 = qos_laps_served+qos_laps_remain;
tot2 = qos_served+qos_remain;

/* reset total weight */
pthread_mutex_lock(&qos_lock);
qos_served += qos_total_weight;
qos_remain -= qos_total_weight;
qos_total_weight=0;
qos_laps_served = (tot1*qos_served)/tot2;
qos_laps_remain = tot1- qos_laps_served;
pthread_mutex_unlock(&qos_lock);

/* print */
pr=100*qos_served/(qos_served+qos_remain);
printf("bw = %08.4f MB/s\n",bw);
sprintf(s,"%02d/%02d",(int)qos_laps_served,(int)(qos_laps_served+qos_laps_remain));
progress_rt(s);
sprintf(s,"%3d%%",(int)pr);
progress_rb(s);
return 0;
}

Expand All @@ -99,11 +133,47 @@ static void *disp_realtime_bw(void *arg)
while(1)
{
qos_print_bw();
if(qos_remain<=0) pthread_cancel(tid);
sleep(1);
}
return 0;
}

/*
* progress_rb()
* Update progress information at the right
* bottom corner of the console.
*/
static int progress_rb(char *s)
{
// return 0;
printf("\033[s");
printf("\033[99999;99999H");
printf("\033[8D");
// printf("\033[1A\033[K\033[1B");
printf("[ %5s ]",s);
printf("\033[u");
return 0;
}

/*
* progress_rt()
* Update progress information at the right
* top corner of the console.
*/
static int progress_rt(char *s)
{
// return 0;
printf("\033[s");
printf("\033[99999;99999H");
printf("\033[8D");
printf("\033[1A");
printf("\033[1A\033[K\033[1B");
printf("[ %5s ]",s);
printf("\033[u");
return 0;
}

/*
* Local variables:
* c-indentation-style: "K&R"
Expand Down

0 comments on commit 6aa297f

Please sign in to comment.