~ubuntu-branches/ubuntu/precise/ceph/precise-proposed

« back to all changes in this revision

Viewing changes to src/common/LogType.h

  • Committer: Bazaar Package Importer
  • Author(s): Laszlo Boszormenyi (GCS)
  • Date: 2011-04-25 10:09:05 UTC
  • mfrom: (1.1.3 upstream) (0.1.5 sid)
  • Revision ID: james.westby@ubuntu.com-20110425100905-exm7dfvi2v5ick02
Tags: 0.27-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- 
2
 
// vim: ts=8 sw=2 smarttab
3
 
/*
4
 
 * Ceph - scalable distributed file system
5
 
 *
6
 
 * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
7
 
 *
8
 
 * This is free software; you can redistribute it and/or
9
 
 * modify it under the terms of the GNU Lesser General Public
10
 
 * License version 2.1, as published by the Free Software 
11
 
 * Foundation.  See file COPYING.
12
 
 * 
13
 
 */
14
 
 
15
 
 
16
 
#ifndef CEPH_LOGTYPE_H
17
 
#define CEPH_LOGTYPE_H
18
 
 
19
 
#include "include/types.h"
20
 
 
21
 
#include <vector>
22
 
using std::vector;
23
 
 
24
 
class LogType {
25
 
 protected:
26
 
  int first_key, num_keys;
27
 
  vector<const char*> key_name;
28
 
  vector<bool> inc_keys, avg_keys;
29
 
 
30
 
  friend class Logger;
31
 
 
32
 
 public:
33
 
  LogType(int first, int tail) :
34
 
    first_key(first), num_keys(tail-first - 1),
35
 
    key_name(num_keys), inc_keys(num_keys), avg_keys(num_keys) {
36
 
    for (int i=0; i<num_keys; i++) {
37
 
      key_name[i] = 0;
38
 
      inc_keys[i] = 0;
39
 
      avg_keys[i] = 0;
40
 
    }
41
 
  }
42
 
  int lookup_key(int key, bool isnew=false) {
43
 
    int i = key - first_key - 1;
44
 
    assert(i >= 0 && i < num_keys);
45
 
    assert(isnew || key_name[i]);
46
 
    return i;
47
 
  }
48
 
  void add_key(int key, const char *name, bool is_inc, bool is_avg) {
49
 
    int i = lookup_key(key, true);
50
 
    assert(!key_name[i]);  // only register each type once!
51
 
    key_name[i] = name;
52
 
    inc_keys[i] = is_inc;
53
 
    avg_keys[i] = is_avg;
54
 
  }
55
 
  void add_inc(int key, const char *name) {
56
 
    return add_key(key, name, true, false);
57
 
  }
58
 
  void add_set(int key, const char *name) {
59
 
    return add_key(key, name, false, false);
60
 
  }
61
 
  void add_avg(int key, const char *name) {
62
 
    return add_key(key, name, true, true);
63
 
  }
64
 
  void validate() {
65
 
    for (int i=0; i<num_keys; i++)
66
 
      assert(key_name[i]);
67
 
  }
68
 
};
69
 
 
70
 
#endif