*** empty log message ***

git-svn-id: https://ceph.svn.sf.net/svnroot/ceph@654 29311d96-e01e-0410-9327-a35deaab8ce9
This commit is contained in:
sage 2006-02-20 01:33:12 +00:00
parent 2e1eff3dcd
commit 73aaf7e688
5 changed files with 95 additions and 55 deletions

View File

@ -28,16 +28,16 @@
#include <fstream>
using namespace std;
#include <ext/hash_map>
#include <ext/hash_set>
using namespace __gnu_cxx;
#include "Mutex.h"
class LogType {
protected:
set<const char*, ltstr> keyset;
hash_map<__uint32_t, int> keymap;
vector<const char*> keys;
vector<const char*> inc_keys;
vector<const char*> set_keys;
set<int> inc_keys;
int version;
@ -47,24 +47,43 @@ class LogType {
LogType() {
version = 1;
}
void add_inc(const char* key) {
if (!have_key(key)) {
keys.push_back(key);
keyset.insert(key);
inc_keys.push_back(key);
version++;
}
int add_key(const char* key, bool is_inc) {
int i = lookup_key(key);
if (i >= 0) return i;
i = keys.size();
keys.push_back(key);
__uint32_t p = (__uint32_t)key;
keymap[p] = i;
if (is_inc) inc_keys.insert(i);
version++;
return i;
}
void add_set(const char* key){
if (!have_key(key)) {
keys.push_back(key);
keyset.insert(key);
set_keys.push_back(key);
version++;
}
int add_inc(const char* key) {
return add_key(key, true);
}
int add_set(const char *key) {
return add_key(key, false);
}
bool have_key(const char* key) {
return keyset.count(key) ? true:false;
return lookup_key(key) < 0;
}
int lookup_key(const char* key) {
__uint32_t p = (__uint32_t)key;
if (keymap.count(p))
return keymap[p];
for (unsigned i=0; i<keys.size(); i++)
if (strcmp(keys[i], key) == 0) {
keymap[p] = i;
return i;
}
return -1;
}
};

View File

@ -68,11 +68,11 @@ long Logger::inc(const char *key, long v)
{
if (!g_conf.log) return 0;
logger_lock.Lock();
if (!type->have_key(key))
type->add_inc(key);
int i = type->lookup_key(key);
if (i < 0) i = type->add_inc(key);
flush();
vals[key] += v;
long r = vals[key];
vals[i] += v;
long r = vals[i];
logger_lock.Unlock();
return r;
}
@ -81,11 +81,11 @@ double Logger::finc(const char *key, double v)
{
if (!g_conf.log) return 0;
logger_lock.Lock();
if (!type->have_key(key))
type->add_inc(key);
int i = type->lookup_key(key);
if (i < 0) i = type->add_inc(key);
flush();
fvals[key] += v;
double r = vals[key];
fvals[i] += v;
double r = fvals[i];
logger_lock.Unlock();
return r;
}
@ -94,26 +94,23 @@ long Logger::set(const char *key, long v)
{
if (!g_conf.log) return 0;
logger_lock.Lock();
if (!type->have_key(key))
type->add_set(key);
int i = type->lookup_key(key);
if (i < 0) i = type->add_set(key);
flush();
vals[key] = v;
long r = vals[key];
long r = vals[i] = v;
logger_lock.Unlock();
return r;
}
double Logger::fset(const char *key, double v)
{
if (!g_conf.log) return 0;
logger_lock.Lock();
if (!type->have_key(key))
type->add_set(key);
int i = type->lookup_key(key);
if (i < 0) i = type->add_set(key);
flush();
fvals[key] = v;
double r = vals[key];
double r = fvals[i] = v;
logger_lock.Unlock();
return r;
}
@ -122,7 +119,10 @@ long Logger::get(const char* key)
{
if (!g_conf.log) return 0;
logger_lock.Lock();
long r = vals[key];
int i = type->lookup_key(key);
long r = 0;
if (i >= 0)
r = vals[i];
logger_lock.Unlock();
return r;
}
@ -132,6 +132,11 @@ void Logger::flush(bool force)
if (!g_conf.log) return;
logger_lock.Lock();
while (type->keys.size() > vals.size())
vals.push_back(0);
while (type->keys.size() > fvals.size())
fvals.push_back(0);
if (!open) {
out.open(filename.c_str(), ofstream::out);
open = true;
@ -158,31 +163,30 @@ void Logger::flush(bool force)
wrote_header_last++;
if (wrote_header != type->version ||
wrote_header_last > 10) {
out << "#";
for (vector<const char*>::iterator it = type->keys.begin(); it != type->keys.end(); it++) {
out << "\t" << *it;
}
out << endl;
out << "#" << type->keymap.size();
for (unsigned i=0; i<type->keys.size(); i++)
out << "\t" << type->keys[i];
out << endl; //out << "\t (" << type->keymap.size() << ")" << endl;
wrote_header = type->version;
wrote_header_last = 0;
}
// write line to log
out << last_logged;
for (vector<const char*>::iterator it = type->keys.begin(); it != type->keys.end(); it++) {
if (fvals.count(*it))
out << "\t" << fvals[*it];
for (unsigned i=0; i<type->keys.size(); i++) {
if (fvals[i] > 0 && vals[i] == 0)
out << "\t" << fvals[i];
else
out << "\t" << vals[*it];
out << "\t" << vals[i];
}
out << endl;
// reset the counters
for (vector<const char*>::iterator it = type->inc_keys.begin(); it != type->inc_keys.end(); it++) {
if (this->vals.count(*it))
this->vals[*it] = 0;
if (this->fvals.count(*it))
this->fvals[*it] = 0;
for (unsigned i=0; i<type->keys.size(); i++) {
if (type->inc_keys.count(i)) {
this->vals[i] = 0;
this->fvals[i] = 0;
}
}
}

View File

@ -40,8 +40,10 @@ using namespace __gnu_cxx;
class Logger {
protected:
hash_map<const char*, long, hash<const char*>, eqstr> vals;
hash_map<const char*, double, hash<const char*>, eqstr> fvals;
//hash_map<const char*, long, hash<const char*>, eqstr> vals;
//hash_map<const char*, double, hash<const char*>, eqstr> fvals;
vector<long> vals;
vector<double> fvals;
//Mutex lock;
LogType *type;

View File

@ -105,6 +105,8 @@ typedef struct {
} active_request_t;
class MDCache {
protected:
// the cache

View File

@ -48,12 +48,25 @@ prepare + commit versions of many of these?
using namespace std;
#include <ext/hash_set>
using namespace __gnu_cxx;
class LogStream;
class LogEvent;
class MDS;
class Logger;
namespace __gnu_cxx {
template<> struct hash<LogEvent*> {
size_t operator()(const LogEvent *p) const {
static hash<unsigned long> H;
return H((unsigned long)p);
}
};
}
class MDLog {
protected:
MDS *mds;
@ -62,8 +75,8 @@ class MDLog {
LogStream *logstream;
set<LogEvent*> trimming; // events currently being trimmed
list<Context*> trim_waiters; // contexts waiting for trim
hash_set<LogEvent*> trimming; // events currently being trimmed
list<Context*> trim_waiters; // contexts waiting for trim
bool trim_reading;
bool waiting_for_read;