Skip to content

Commit

Permalink
workloadgen: time tracking using ceph's utime_t's instead of timevals.
Browse files Browse the repository at this point in the history
Signed-off-by: Joao Eduardo Luis <[email protected]>
  • Loading branch information
Joao Eduardo Luis committed May 8, 2012
1 parent 772276c commit 8bacc51
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 52 deletions.
51 changes: 16 additions & 35 deletions src/test/filestore/workload_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ WorkloadGenerator::WorkloadGenerator(vector<const char*> args)
m_suppress_write_data(false), m_suppress_write_xattr_obj(false),
m_suppress_write_xattr_coll(false), m_suppress_write_log(false),
m_do_stats(false),
m_stats_written_data(0), m_stats_duration(0), m_stats_lock("Stats Lock"),
m_stats_written_data(0), m_stats_duration(), m_stats_lock("Stats Lock"),
m_stats_show_secs(5)
{
int err = 0;
Expand Down Expand Up @@ -373,11 +373,8 @@ void WorkloadGenerator::run()
bool create_coll = false;
int ops_run = 0;

struct timeval time_elapsed;
if (gettimeofday(&time_elapsed, NULL) < 0) {
dout(0) << __func__ << " gettimeofday error: " << strerror(errno) << dendl;
exit(1);
}
utime_t stats_interval(m_stats_show_secs, 0);
utime_t stats_time = ceph_clock_now(NULL);

do {
C_StatState *stat_state = NULL;
Expand All @@ -402,45 +399,29 @@ void WorkloadGenerator::run()
bool destroy_collection = false;
TestFileStoreState::coll_entry_t *entry = NULL;

int ret;
struct timeval tv_begin;
ret = gettimeofday(&tv_begin, NULL);
if (ret < 0) {
dout(0) << __func__ << " gettimeofday error: " << strerror(errno) << dendl;
exit(1);
}

if (m_do_stats) {
if (_diff_tvs(tv_begin, time_elapsed) > (m_stats_show_secs * 1000000)) {
utime_t now = ceph_clock_now(NULL);
utime_t elapsed = now - stats_time;
if (elapsed >= stats_interval) {
m_stats_lock.Lock();
double duration = m_stats_duration / 1000000; // to secs
double throughput = (m_stats_written_data / duration);

dout(0) << __func__ << " written data: " << m_stats_written_data << " duration: " << m_stats_duration << dendl;

string unit;

// this is a bit ugly. an alternative should be pursued.
if (throughput < (1 << 10)) {
unit = "B";
} else if (throughput < (1 << 20)) {
unit = "KB";
throughput /= (1 << 10);
} else {
unit = "MB";
throughput /= (1 << 20);
}

dout(0) << "Throughput " << throughput << " " << unit << "/s" << dendl;
// when cast to double, a utime_t behaves properly
double throughput = (m_stats_written_data / ((double) m_stats_duration));

dout(0) << __func__ << " written data: " << m_stats_written_data
<< " duration: " << m_stats_duration << dendl;
dout(0) << "Throughput " << prettybyte_t(throughput) << "/s" << dendl;

m_stats_written_data = m_stats_duration = 0;
m_stats_written_data = 0;
m_stats_duration = utime_t();

m_stats_lock.Unlock();

gettimeofday(&time_elapsed, NULL);
stats_time = now;
}

stat_state = new C_StatState(this, tv_begin);
stat_state = new C_StatState(this, now);
}

if (create_coll) {
Expand Down
24 changes: 7 additions & 17 deletions src/test/filestore/workload_generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,14 @@ class WorkloadGenerator : public TestFileStoreState {
static const size_t log_append_bytes = 1024;

struct C_StatState {
struct timeval tv_start;
utime_t start;
unsigned int written_data;
WorkloadGenerator *wrkldgen;

C_StatState(WorkloadGenerator *state, struct timeval start)
: tv_start(start), written_data(0), wrkldgen(state) { }
C_StatState(WorkloadGenerator *state, utime_t s)
: start(s), written_data(0), wrkldgen(state) { }
};

static unsigned long long _diff_tvs(struct timeval& a, struct timeval& b) {
return (((a.tv_sec*1000000)+a.tv_usec) - ((b.tv_sec*1000000)+b.tv_usec));
}


protected:
int m_max_in_flight;
Expand All @@ -82,7 +78,7 @@ class WorkloadGenerator : public TestFileStoreState {
bool m_do_stats;

size_t m_stats_written_data;
unsigned long long m_stats_duration;
utime_t m_stats_duration;
Mutex m_stats_lock;
int m_stats_show_secs;

Expand Down Expand Up @@ -165,17 +161,11 @@ class WorkloadGenerator : public TestFileStoreState {
void finish(int r) {
ctx->finish(r);

struct timeval tv_end;
int ret = gettimeofday(&tv_end, NULL);
if (ret < 0) {
cout << "error on gettimeofday" << std::endl;
_exit(1);
}

unsigned long long usec_taken = _diff_tvs(tv_end, stat_state->tv_start);
utime_t end = ceph_clock_now(NULL);
utime_t taken = end - stat_state->start;

stat_state->wrkldgen->m_stats_lock.Lock();
stat_state->wrkldgen->m_stats_duration += usec_taken;
stat_state->wrkldgen->m_stats_duration += taken;
stat_state->wrkldgen->m_stats_written_data += stat_state->written_data;
stat_state->wrkldgen->m_stats_lock.Unlock();
}
Expand Down

0 comments on commit 8bacc51

Please sign in to comment.