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
This commit is contained in:
sears 2010-03-03 23:21:08 +00:00
parent 1243d999a5
commit f258ce1a3f
3 changed files with 119 additions and 0 deletions

54
util/histogram.cpp Normal file
View file

@ -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;
}

32
util/space_usage.cpp Normal file
View file

@ -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;
}

33
util/util_main.h Normal file
View file

@ -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_ */