2010-04-29 01:03:56 +00:00
/*
* mergeStats . h
*
* Created on : Apr 27 , 2010
* Author : sears
*/
# ifndef MERGESTATS_H_
# define MERGESTATS_H_
# include <stasis/common.h>
2010-05-19 23:42:06 +00:00
# undef try
# undef end
2010-04-29 01:03:56 +00:00
2010-05-19 23:42:06 +00:00
# include <sys/time.h>
# include <stdio.h>
# include "datatuple.h"
# include "datapage.h"
2010-06-02 21:47:58 +00:00
# include <mergeManager.h> // XXX for double_to_ts, etc... create a util class.
2010-04-29 23:13:04 +00:00
2010-05-19 23:42:06 +00:00
class mergeStats {
2010-04-29 23:13:04 +00:00
public :
2010-06-02 21:47:58 +00:00
mergeStats ( int merge_level , int64_t target_size ) :
2010-04-29 23:13:04 +00:00
merge_level ( merge_level ) ,
merge_count ( 0 ) ,
2010-05-26 00:58:17 +00:00
base_size ( 0 ) ,
2010-06-21 20:03:05 +00:00
mergeable_size ( 0 ) ,
2010-05-28 21:20:26 +00:00
target_size ( target_size ) ,
2010-05-26 00:58:17 +00:00
current_size ( 0 ) ,
2010-05-21 23:43:17 +00:00
bytes_out_with_overhead ( 0 ) ,
2010-04-29 23:13:04 +00:00
bytes_out ( 0 ) ,
num_tuples_out ( 0 ) ,
num_datapages_out ( 0 ) ,
bytes_in_small ( 0 ) ,
2010-05-12 22:16:41 +00:00
bytes_in_small_delta ( 0 ) ,
2010-04-29 23:13:04 +00:00
num_tuples_in_small ( 0 ) ,
bytes_in_large ( 0 ) ,
2010-05-12 22:16:41 +00:00
num_tuples_in_large ( 0 ) ,
2010-05-26 00:58:17 +00:00
just_handed_off ( false ) ,
2010-07-14 21:46:27 +00:00
mini_delta ( 0 ) ,
2010-06-05 00:41:52 +00:00
delta ( 0 ) ,
2010-06-18 23:00:23 +00:00
need_tick ( 0 ) ,
2010-06-05 00:41:52 +00:00
in_progress ( 0 ) ,
out_progress ( 0 ) ,
2010-05-26 00:58:17 +00:00
lifetime_elapsed ( 0 ) ,
lifetime_consumed ( 0 ) ,
2010-07-14 21:46:27 +00:00
bps ( 10.0 * 1024.0 * 1024.0 ) ,
2010-06-02 21:47:58 +00:00
print_skipped ( 0 ) ,
2010-05-12 22:16:41 +00:00
active ( false ) {
2010-04-29 23:13:04 +00:00
gettimeofday ( & sleep , 0 ) ;
2010-05-12 22:16:41 +00:00
gettimeofday ( & last , 0 ) ;
2010-06-02 21:47:58 +00:00
mergeManager : : double_to_ts ( & last_tick , mergeManager : : tv_to_double ( & last ) ) ;
2010-07-14 21:46:27 +00:00
mergeManager : : double_to_ts ( & last_mini_tick , mergeManager : : tv_to_double ( & last ) ) ;
2010-06-17 04:49:19 +00:00
pthread_mutex_init ( & mut , 0 ) ;
}
~ mergeStats ( ) {
pthread_mutex_destroy ( & mut ) ;
2010-04-29 01:03:56 +00:00
}
2010-06-02 21:47:58 +00:00
void new_merge2 ( ) {
2010-05-26 00:58:17 +00:00
if ( just_handed_off ) {
bytes_out = 0 ;
2010-06-05 00:41:52 +00:00
out_progress = 0 ;
2010-05-26 00:58:17 +00:00
just_handed_off = false ;
}
base_size = bytes_out ;
current_size = base_size ;
2010-04-29 23:13:04 +00:00
merge_count + + ;
2010-05-26 00:58:17 +00:00
bytes_out_with_overhead = 0 ;
bytes_out = 0 ;
2010-04-29 23:13:04 +00:00
num_tuples_out = 0 ;
num_datapages_out = 0 ;
bytes_in_small = 0 ;
2010-05-12 22:16:41 +00:00
bytes_in_small_delta = 0 ;
2010-04-29 23:13:04 +00:00
num_tuples_in_small = 0 ;
2010-05-26 00:58:17 +00:00
bytes_in_large = 0 ;
2010-04-29 23:13:04 +00:00
num_tuples_in_large = 0 ;
2010-06-05 00:41:52 +00:00
in_progress = 0 ;
2010-04-29 23:13:04 +00:00
gettimeofday ( & sleep , 0 ) ;
2010-04-29 01:03:56 +00:00
}
2010-04-29 23:13:04 +00:00
void starting_merge ( ) {
2010-05-12 22:16:41 +00:00
active = true ;
2010-04-29 23:13:04 +00:00
gettimeofday ( & start , 0 ) ;
2010-05-12 22:16:41 +00:00
gettimeofday ( & last , 0 ) ;
2010-06-02 21:47:58 +00:00
mergeManager : : double_to_ts ( & last_tick , mergeManager : : tv_to_double ( & last ) ) ;
2010-07-14 21:46:27 +00:00
mergeManager : : double_to_ts ( & last_mini_tick , mergeManager : : tv_to_double ( & last ) ) ;
2010-05-26 00:58:17 +00:00
2010-04-29 23:13:04 +00:00
}
2010-05-21 23:43:17 +00:00
void handed_off_tree ( ) {
2010-05-26 00:58:17 +00:00
if ( merge_level = = 2 ) {
} else {
mergeable_size = current_size ;
just_handed_off = true ;
}
2010-05-21 23:43:17 +00:00
}
2010-05-12 22:16:41 +00:00
void merged_tuples ( datatuple * merged , datatuple * small , datatuple * large ) {
}
2010-04-29 23:13:04 +00:00
void wrote_datapage ( DataPage < datatuple > * dp ) {
num_datapages_out + + ;
2010-05-21 23:43:17 +00:00
bytes_out_with_overhead + = ( PAGE_SIZE * dp - > get_page_count ( ) ) ;
2010-04-29 23:13:04 +00:00
}
pageid_t output_size ( ) {
return bytes_out ;
}
2010-06-02 21:47:58 +00:00
const int merge_level ; // 1 => C0->C1, 2 => C1->C2
2010-04-29 23:13:04 +00:00
protected :
pageid_t merge_count ; // This is the merge_count'th merge
struct timeval sleep ; // When did we go to sleep waiting for input?
2010-04-29 01:03:56 +00:00
struct timeval start ; // When did we wake up and start merging? (at steady state with max throughput, this should be equal to sleep)
struct timeval done ; // When did we finish merging?
2010-05-12 22:16:41 +00:00
struct timeval last ;
2010-04-29 01:03:56 +00:00
double float_tv ( struct timeval & tv ) {
return ( ( double ) tv . tv_sec ) + ( ( double ) tv . tv_usec ) / 1000000.0 ;
}
2010-04-29 23:13:04 +00:00
friend class mergeManager ;
2010-06-02 21:47:58 +00:00
2010-07-14 21:46:27 +00:00
struct timespec last_mini_tick ;
2010-05-21 23:43:17 +00:00
struct timespec last_tick ;
2010-06-21 20:03:05 +00:00
public : // XXX only accessed during initialization.
2010-08-05 17:43:46 +00:00
pageid_t base_size ; // size of table at beginning of merge. for c0, size of table at beginning of current c0-c1 merge round, plus data written since then. (this minus c1->bytes_in_small is the current size)
2010-06-21 20:03:05 +00:00
pageid_t mergeable_size ; // protected by mutex.
2010-05-26 00:58:17 +00:00
pageid_t target_size ;
pageid_t current_size ;
2010-08-05 17:43:46 +00:00
protected :
2010-04-29 01:03:56 +00:00
2010-05-21 23:43:17 +00:00
pageid_t bytes_out_with_overhead ; // How many bytes did we write (including internal tree nodes)?
2010-06-21 20:03:05 +00:00
public :
2010-05-26 00:58:17 +00:00
pageid_t bytes_out ; // How many bytes worth of tuples did we write?
2010-06-21 20:03:05 +00:00
protected :
2010-04-29 01:03:56 +00:00
pageid_t num_tuples_out ; // How many tuples did we write?
pageid_t num_datapages_out ; // How many datapages?
2010-08-21 03:09:18 +00:00
public :
2010-04-29 01:03:56 +00:00
pageid_t bytes_in_small ; // How many bytes from the small input tree (for C0, we ignore tree overheads)?
2010-08-21 03:09:18 +00:00
protected :
2010-05-12 22:16:41 +00:00
pageid_t bytes_in_small_delta ; // How many bytes from the small input tree during this tick (for C0, we ignore tree overheads)?
2010-04-29 01:03:56 +00:00
pageid_t num_tuples_in_small ; // Tuples from the small input?
pageid_t bytes_in_large ; // Bytes from the large input?
pageid_t num_tuples_in_large ; // Tuples from large input?
2010-05-26 00:58:17 +00:00
bool just_handed_off ;
2010-07-14 21:46:27 +00:00
int mini_delta ;
2010-06-05 00:41:52 +00:00
int delta ;
2010-06-18 23:00:23 +00:00
int need_tick ;
2010-06-05 00:41:52 +00:00
double in_progress ;
double out_progress ;
2010-05-26 00:58:17 +00:00
double lifetime_elapsed ;
double lifetime_consumed ;
2010-06-17 04:49:19 +00:00
double bps ;
2010-06-02 21:47:58 +00:00
int print_skipped ; // used by pretty print in mergeManager.
2010-05-12 22:16:41 +00:00
bool active ;
2010-06-17 04:49:19 +00:00
pthread_mutex_t mut ; // protects things touched in tick(), and nothing else.
2010-04-29 23:13:04 +00:00
public :
2010-04-29 01:03:56 +00:00
void pretty_print ( FILE * fd ) {
2010-04-29 23:13:04 +00:00
double sleep_time = float_tv ( start ) - float_tv ( sleep ) ;
double work_time = float_tv ( done ) - float_tv ( start ) ;
double total_time = sleep_time + work_time ;
2010-05-21 23:43:17 +00:00
double mb_out = ( ( double ) bytes_out_with_overhead ) / ( 1024.0 * 1024.0 ) ;
2010-04-29 23:13:04 +00:00
double mb_ins = ( ( double ) bytes_in_small ) / ( 1024.0 * 1024.0 ) ;
double mb_inl = ( ( double ) bytes_in_large ) / ( 1024.0 * 1024.0 ) ;
double kt_out = ( ( double ) num_tuples_out ) / ( 1024.0 ) ;
double kt_ins = ( ( double ) num_tuples_in_small ) / ( 1024.0 ) ;
double kt_inl = ( ( double ) num_tuples_in_large ) / ( 1024.0 ) ;
double mb_hdd = mb_out + mb_inl + ( merge_level = = 1 ? 0.0 : mb_ins ) ;
double kt_hdd = kt_out + kt_inl + ( merge_level = = 1 ? 0.0 : kt_ins ) ;
2010-04-29 01:03:56 +00:00
2010-04-29 23:13:04 +00:00
fprintf ( fd ,
" ===================================================================== \n "
" Thread %d merge %lld: sleep %6.2f sec, run %6.2f sec \n "
" megabytes kTuples datapages MB/s (real) kTup/s (real) \n "
" Wrote %7lld %7lld %9lld " " %6.1f %6.1f " " %8.1f %8.1f " " \n "
" Read (small) %7lld %7lld - " " %6.1f %6.1f " " %8.1f %8.1f " " \n "
" Read (large) %7lld %7lld - " " %6.1f %6.1f " " %8.1f %8.1f " " \n "
" Disk %7lld %7lld - " " %6.1f %6.1f " " %8.1f %8.1f " " \n "
" ..................................................................... \n "
" avg tuple len: %6.2fkb \n "
" effective throughput: (mb/s ; nsec/byte): (%.2f; %.2f) active " " \n "
" (%.2f; %.2f) wallclock " " \n "
" ..................................................................... \n "
,
merge_level , merge_count ,
sleep_time ,
work_time ,
( long long ) mb_out , ( long long ) kt_out , num_datapages_out , mb_out / work_time , mb_out / total_time , kt_out / work_time , kt_out / total_time ,
( long long ) mb_ins , ( long long ) kt_ins , mb_ins / work_time , mb_ins / total_time , kt_ins / work_time , kt_ins / total_time ,
( long long ) mb_inl , ( long long ) kt_inl , mb_inl / work_time , mb_inl / total_time , kt_inl / work_time , kt_inl / total_time ,
( long long ) mb_hdd , ( long long ) kt_hdd , mb_hdd / work_time , mb_hdd / total_time , kt_hdd / work_time , kt_hdd / total_time ,
mb_out / kt_out ,
mb_ins / work_time , 1000.0 * work_time / mb_ins , mb_ins / total_time , 1000.0 * total_time / mb_ins
) ;
2010-04-29 01:03:56 +00:00
}
2010-04-29 23:13:04 +00:00
} ;
2010-04-29 01:03:56 +00:00
# endif /* MERGESTATS_H_ */