mirror of
https://github.com/MariaDB/server.git
synced 2025-01-22 14:54:20 +01:00
read the timestamp counter. closes #1012
git-svn-id: file:///svn/tokudb@5018 c7de825b-a66e-492c-adef-691d508d4ae1
This commit is contained in:
parent
3381558927
commit
a68937a031
2 changed files with 56 additions and 0 deletions
|
@ -7,12 +7,30 @@
|
|||
#include <sys/resource.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include "rdtsc.h"
|
||||
|
||||
const char *pname;
|
||||
enum run_mode { RUN_HWC, RUN_LWC, RUN_VERIFY } run_mode = RUN_HWC;
|
||||
int do_txns=1, prelock=0, prelockflag=0;
|
||||
u_int32_t lock_flag = 0;
|
||||
int do_rdtsc = 0;
|
||||
#define NTRACE 1000000
|
||||
int next_trace = 0;
|
||||
unsigned long long tracebuffer[NTRACE];
|
||||
|
||||
static inline void add_trace() {
|
||||
#if USE_RDTSC
|
||||
if (next_trace < NTRACE)
|
||||
tracebuffer[next_trace++] = rdtsc();
|
||||
#endif
|
||||
}
|
||||
|
||||
void print_trace() {
|
||||
if (do_rdtsc == 0) return;
|
||||
int i;
|
||||
for (i=0; i<NTRACE; i++)
|
||||
if (tracebuffer[i]) printf("%llu\n", tracebuffer[i]);
|
||||
}
|
||||
|
||||
void parse_args (int argc, const char *argv[]) {
|
||||
pname=argv[0];
|
||||
|
@ -33,6 +51,7 @@ void parse_args (int argc, const char *argv[]) {
|
|||
else if (strcmp(*argv, "--prelockflag")==0) { prelockflag=1; lock_flag = DB_PRELOCKED; }
|
||||
else if (strcmp(*argv, "--prelockwriteflag")==0) { prelockflag=1; lock_flag = DB_PRELOCKED_WRITE; }
|
||||
else if (strcmp(*argv, "--nox")==0) { do_txns=0; }
|
||||
else if (strcmp(*argv, "--rdtsc")==0) { do_rdtsc=1; }
|
||||
else {
|
||||
fprintf(stderr, "Usage:\n%s [--verify-lwc | --lwc | --nohwc] [--prelock] [--prelockflag] [--prelockwriteflag]\n", pname);
|
||||
fprintf(stderr, " --hwc run heavy weight cursors (this is the default)\n");
|
||||
|
@ -116,7 +135,9 @@ void scanscan_hwc (void) {
|
|||
if (prelockflag && (counter || prelock)) {
|
||||
c_get_flags |= lock_flag;
|
||||
}
|
||||
add_trace();
|
||||
while (0 == (r = dbc->c_get(dbc, &k, &v, c_get_flags))) {
|
||||
add_trace();
|
||||
totalbytes += k.size + v.size;
|
||||
rowcounter++;
|
||||
}
|
||||
|
@ -124,6 +145,7 @@ void scanscan_hwc (void) {
|
|||
double thistime = gettime();
|
||||
double tdiff = thistime-prevtime;
|
||||
printf("Scan %lld bytes (%d rows) in %9.6fs at %9fMB/s\n", totalbytes, rowcounter, tdiff, 1e-6*totalbytes/tdiff);
|
||||
print_trace();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
34
include/rdtsc.h
Normal file
34
include/rdtsc.h
Normal file
|
@ -0,0 +1,34 @@
|
|||
// read the processor time stamp register
|
||||
|
||||
#if defined __i386__
|
||||
|
||||
#define USE_RDTSC 1
|
||||
|
||||
static inline unsigned long long rdtsc() {
|
||||
unsigned long hi, lo;
|
||||
__asm__ __volatile__ ("rdtsc\n"
|
||||
"movl %%edx,%0\n"
|
||||
"movl %%eax,%1" : "=r"(hi), "=r"(lo) : : "edx", "eax");
|
||||
return ((unsigned long long) hi << 32ULL) + (unsigned long long) lo;
|
||||
}
|
||||
|
||||
#else
|
||||
#if defined __x86_64__
|
||||
|
||||
#define USE_RDTSC 1
|
||||
|
||||
static inline unsigned long long rdtsc() {
|
||||
unsigned long long r;
|
||||
__asm__ __volatile__ ("rdtsc\n"
|
||||
"shl $32,%%rdx\n"
|
||||
"or %%rdx,%%rax\n"
|
||||
"movq %%rax,%0" : "=r"(r) : : "edx", "eax", "rdx", "rax");
|
||||
return r;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#define USE_RDTSC 0
|
||||
|
||||
#endif
|
||||
#endif
|
Loading…
Add table
Reference in a new issue