mirror of
https://github.com/ceph/ceph
synced 2025-02-07 10:53:30 +00:00
workloadgen: time tracking using ceph's utime_t's instead of timevals.
Signed-off-by: Joao Eduardo Luis <joao.luis@inktank.com>
This commit is contained in:
parent
772276cb30
commit
8bacc51b83
@ -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;
|
||||
@ -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;
|
||||
@ -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;
|
||||
// when cast to double, a utime_t behaves properly
|
||||
double throughput = (m_stats_written_data / ((double) m_stats_duration));
|
||||
|
||||
string unit;
|
||||
dout(0) << __func__ << " written data: " << m_stats_written_data
|
||||
<< " duration: " << m_stats_duration << dendl;
|
||||
dout(0) << "Throughput " << prettybyte_t(throughput) << "/s" << dendl;
|
||||
|
||||
// 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;
|
||||
|
||||
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) {
|
||||
|
@ -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;
|
||||
@ -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;
|
||||
|
||||
@ -165,17 +161,11 @@ public:
|
||||
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();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user