From f258ce1a3f92e573f7f3c2dfa2162ee666a38361 Mon Sep 17 00:00:00 2001 From: sears Date: Wed, 3 Mar 2010 23:21:08 +0000 Subject: [PATCH] adding a few overlooked files git-svn-id: svn+ssh://svn.corp.yahoo.com/yahoo/yrl/labs/pnuts/code/logstore@657 8dad8b1f-cf64-0410-95b6-bcf113ffbcfe --- util/histogram.cpp | 54 ++++++++++++++++++++++++++++++++++++++++++++ util/space_usage.cpp | 32 ++++++++++++++++++++++++++ util/util_main.h | 33 +++++++++++++++++++++++++++ 3 files changed, 119 insertions(+) create mode 100644 util/histogram.cpp create mode 100644 util/space_usage.cpp create mode 100644 util/util_main.h diff --git a/util/histogram.cpp b/util/histogram.cpp new file mode 100644 index 0000000..ce457c3 --- /dev/null +++ b/util/histogram.cpp @@ -0,0 +1,54 @@ +/* + * histogram.cpp + * + * Created on: Mar 2, 2010 + * Author: sears + */ + +#include "../tcpclient.h" +#include "../network.h" +#include "../datatuple.h" + +void usage(char * argv[]) { + fprintf(stderr, "usage %s [n] [host [port]]\n", argv[0]); +} +#include "util_main.h" +int main(int argc, char * argv[]) { + unsigned long long count = 3; + if(argc > 1) { + char * end; + unsigned long long n = strtoull(argv[1], &end, 10); + if(argv[1][0] && !*end) { + count = n; + argc--; + argv++; + } + } + logstore_handle_t * l = util_open_conn(argc, argv); + +// datatuple * ret + uint8_t rcode = logstore_client_op_returns_many(l, OP_STAT_HISTOGRAM, NULL, NULL, count); + + if(opiserror(rcode)) { + fprintf(stderr, "Histogram request returned logstore error code %d\n", rcode); + perror("Histogram generation failed."); return 3; + } else { + datatuple *ret; + bool first = true; + while(( ret = logstore_client_next_tuple(l) )) { + if(first) { + assert(ret->keylen() == sizeof(uint64_t)); + uint64_t stride = *(uint64_t*)ret->key(); + printf("Stride: %lld\n", (long long)stride); + first = false; + } else { + assert(ret->key()[ret->keylen()-1] == 0); // check for null terminator. + printf("\t%s\n", (char*)ret->key()); + } + datatuple::freetuple(ret); + } + } + + logstore_client_close(l); + return 0; +} diff --git a/util/space_usage.cpp b/util/space_usage.cpp new file mode 100644 index 0000000..880c1d7 --- /dev/null +++ b/util/space_usage.cpp @@ -0,0 +1,32 @@ +/* + * space_usage.cpp + * + * Created on: Mar 1, 2010 + * Author: sears + */ + +#include "../tcpclient.h" +#include "../network.h" +#include "../datatuple.h" + +void usage(char * argv[]) { + fprintf(stderr, "usage %s [host [port]]\n", argv[0]); +} +#include "util_main.h" +int main(int argc, char * argv[]) { + logstore_handle_t * l = util_open_conn(argc, argv); + + datatuple * ret = logstore_client_op(l, OP_STAT_SPACE_USAGE); + + if(ret == NULL) { + perror("Space usage failed."); return 3; + } + + logstore_client_close(l); + assert(ret->keylen() == sizeof(uint64_t)); + assert(ret->datalen() == sizeof(uint64_t)); + printf("Tree is %lld MB Store file is %lld MB\n", (*(uint64_t*)ret->key()) / (1024*1024), (*(uint64_t*)ret->data()) / (1024*1024)); + datatuple::freetuple(ret); + ; + return 0; +} diff --git a/util/util_main.h b/util/util_main.h new file mode 100644 index 0000000..d408273 --- /dev/null +++ b/util/util_main.h @@ -0,0 +1,33 @@ +/* + * util_open_conn.h + * + * Created on: Mar 1, 2010 + * Author: sears + */ + +#ifndef UTIL_MAIN_H_ +#define UTIL_MAIN_H_ + +logstore_handle_t * util_open_conn(int argc, char * argv[]) { + bool ok = true; + int svrport = 32432; + char * svrname = "localhost"; + if(argc == 3) { + svrport = atoi(argv[2]); + } + if(argc == 2 || argc == 3) { + svrname = argv[1]; + } + if(!ok || argc > 3) { + usage(argv); exit(1); + } + + logstore_handle_t * l = logstore_client_open(svrname, svrport, 100); + + if(l == NULL) { perror("Couldn't open connection"); exit(2); } + + return l; +} + + +#endif /* UTIL_MAIN_H_ */