benchmark silo added
[c11concurrency-benchmarks.git] / silo / tuple.cc
1 #include "tuple.h"
2 #include "txn.h"
3
4 using namespace std;
5 using namespace util;
6
7 event_avg_counter dbtuple::g_evt_avg_dbtuple_stable_version_spins
8   ("avg_dbtuple_stable_version_spins");
9 event_avg_counter dbtuple::g_evt_avg_dbtuple_lock_acquire_spins
10   ("avg_dbtuple_lock_acquire_spins");
11 event_avg_counter dbtuple::g_evt_avg_dbtuple_read_retries
12   ("avg_dbtuple_read_retries");
13
14 event_counter dbtuple::g_evt_dbtuple_creates("dbtuple_creates");
15 event_counter dbtuple::g_evt_dbtuple_logical_deletes("dbtuple_logical_deletes");
16 event_counter dbtuple::g_evt_dbtuple_physical_deletes("dbtuple_physical_deletes");
17 event_counter dbtuple::g_evt_dbtuple_bytes_allocated("dbtuple_bytes_allocated");
18 event_counter dbtuple::g_evt_dbtuple_bytes_freed("dbtuple_bytes_freed");
19 event_counter dbtuple::g_evt_dbtuple_spills("dbtuple_spills");
20 event_counter dbtuple::g_evt_dbtuple_inplace_buf_insufficient("dbtuple_inplace_buf_insufficient");
21 event_counter dbtuple::g_evt_dbtuple_inplace_buf_insufficient_on_spill("dbtuple_inplace_buf_insufficient_on_spill");
22
23 event_avg_counter dbtuple::g_evt_avg_record_spill_len("avg_record_spill_len");
24 static event_avg_counter evt_avg_dbtuple_chain_length("avg_dbtuple_chain_len");
25
26 dbtuple::~dbtuple()
27 {
28   CheckMagic();
29   INVARIANT(!is_locked());
30   INVARIANT(!is_latest());
31   INVARIANT(!is_write_intent());
32   INVARIANT(!is_modifying());
33
34   VERBOSE(cerr << "dbtuple: " << hexify(intptr_t(this)) << " is being deleted" << endl);
35
36   // only free this instance
37
38   // stats-keeping
39   ++g_evt_dbtuple_physical_deletes;
40   g_evt_dbtuple_bytes_freed += (alloc_size + sizeof(dbtuple));
41
42 }
43
44 void
45 dbtuple::gc_this()
46 {
47   INVARIANT(rcu::s_instance.in_rcu_region());
48   INVARIANT(!is_latest());
49   release(this);
50 }
51
52 string
53 dbtuple::VersionInfoStr(version_t v)
54 {
55   ostringstream buf;
56   buf << "[";
57   buf << (IsLocked(v) ? "LOCKED" : "-") << " | ";
58   buf << (IsDeleting(v) ? "DEL" : "-") << " | ";
59   buf << (IsWriteIntent(v) ? "WR" : "-") << " | ";
60   buf << (IsModifying(v) ? "MOD" : "-") << " | ";
61   buf << (IsLatest(v) ? "LATEST" : "-") << " | ";
62   buf << Version(v);
63   buf << "]";
64   return buf.str();
65 }
66
67 static ostream &
68 format_tuple(ostream &o, const dbtuple &t)
69 {
70   string truncated_contents(
71       (const char *) &t.value_start[0], min(static_cast<size_t>(t.size), 16UL));
72   o << &t << " [tid=" << g_proto_version_str(t.version)
73     << ", size=" << t.size
74     << ", contents=0x" << hexify(truncated_contents) << (t.size > 16 ? "..." : "")
75     << ", next=" << t.next << "]";
76   return o;
77 }
78
79 void
80 dbtuple::print(ostream &o, unsigned len) const
81 {
82   o << "dbtuple:" << endl
83     << "  hdr=" << VersionInfoStr(unstable_version())
84 #ifdef TUPLE_CHECK_KEY
85     << endl << "  key=" << hexify(key)
86     << endl << "  tree=" << tree
87 #endif
88     << endl;
89
90   size_t n = 0;
91   for (const dbtuple *p = this;
92        p && n < len;
93        p = p->get_next(), ++n) {
94     o << "  ";
95     format_tuple(o, *p);
96     o << endl;
97   }
98 }
99
100 ostream &
101 operator<<(ostream &o, const dbtuple &t)
102 {
103   t.print(o, 1);
104   return o;
105 }