Browse Source

tdb2: add stats to tdb1 backend.

It's actually quite a good fit; we use compare_wrong_bucket for dead
records, which is kind of correct (they should be in the free list).
Rusty Russell 14 years ago
parent
commit
a3e4ebff2e
4 changed files with 26 additions and 5 deletions
  1. 8 0
      ccan/tdb2/tdb1_freelist.c
  2. 1 0
      ccan/tdb2/tdb1_io.c
  3. 12 5
      ccan/tdb2/tdb1_tdb.c
  4. 5 0
      ccan/tdb2/tdb1_transaction.c

+ 8 - 0
ccan/tdb2/tdb1_freelist.c

@@ -83,6 +83,7 @@ int tdb1_free(struct tdb_context *tdb, tdb1_off_t offset, struct tdb1_record *re
 		goto fail;
 		goto fail;
 	}
 	}
 
 
+	tdb->stats.alloc_coalesce_tried++;
 	/* Look left */
 	/* Look left */
 	if (offset - sizeof(tdb1_off_t) > TDB1_DATA_START(tdb->tdb1.header.hash_size)) {
 	if (offset - sizeof(tdb1_off_t) > TDB1_DATA_START(tdb->tdb1.header.hash_size)) {
 		tdb1_off_t left = offset - sizeof(tdb1_off_t);
 		tdb1_off_t left = offset - sizeof(tdb1_off_t);
@@ -131,6 +132,9 @@ int tdb1_free(struct tdb_context *tdb, tdb1_off_t offset, struct tdb1_record *re
 					   "tdb1_free: update_tailer failed at %u", offset);
 					   "tdb1_free: update_tailer failed at %u", offset);
 				goto fail;
 				goto fail;
 			}
 			}
+			tdb->stats.alloc_coalesce_succeeded++;
+			tdb->stats.alloc_coalesce_num_merged++;
+			tdb->stats.frees++;
 			tdb1_unlock(tdb, -1, F_WRLCK);
 			tdb1_unlock(tdb, -1, F_WRLCK);
 			return 0;
 			return 0;
 		}
 		}
@@ -151,6 +155,7 @@ update:
 	}
 	}
 
 
 	/* And we're done. */
 	/* And we're done. */
+	tdb->stats.frees++;
 	tdb1_unlock(tdb, -1, F_WRLCK);
 	tdb1_unlock(tdb, -1, F_WRLCK);
 	return 0;
 	return 0;
 
 
@@ -188,6 +193,7 @@ static tdb1_off_t tdb1_allocate_ofs(struct tdb_context *tdb,
 		if (tdb1_rec_write(tdb, rec_ptr, rec) == -1) {
 		if (tdb1_rec_write(tdb, rec_ptr, rec) == -1) {
 			return 0;
 			return 0;
 		}
 		}
+		tdb->stats.allocs++;
 		return rec_ptr;
 		return rec_ptr;
 	}
 	}
 
 
@@ -215,6 +221,8 @@ static tdb1_off_t tdb1_allocate_ofs(struct tdb_context *tdb,
 		return 0;
 		return 0;
 	}
 	}
 
 
+	tdb->stats.allocs++;
+	tdb->stats.alloc_leftover++;
 	return rec_ptr;
 	return rec_ptr;
 }
 }
 
 

+ 1 - 0
ccan/tdb2/tdb1_io.c

@@ -307,6 +307,7 @@ static int tdb1_expand_file(struct tdb_context *tdb, tdb1_off_t size, tdb1_off_t
 		addition -= written;
 		addition -= written;
 		size += written;
 		size += written;
 	}
 	}
+	tdb->stats.expands++;
 	return 0;
 	return 0;
 }
 }
 
 

+ 12 - 5
ccan/tdb2/tdb1_tdb.c

@@ -89,11 +89,18 @@ static tdb1_off_t tdb1_find(struct tdb_context *tdb, TDB_DATA key, uint32_t hash
 		if (tdb1_rec_read(tdb, rec_ptr, r) == -1)
 		if (tdb1_rec_read(tdb, rec_ptr, r) == -1)
 			return 0;
 			return 0;
 
 
-		if (!TDB1_DEAD(r) && hash==r->full_hash
-		    && key.dsize==r->key_len
-		    && tdb1_parse_data(tdb, key, rec_ptr + sizeof(*r),
-				      r->key_len, tdb1_key_compare,
-				      NULL) == 0) {
+		tdb->stats.compares++;
+		if (TDB1_DEAD(r)) {
+			tdb->stats.compare_wrong_bucket++;
+		} else if (key.dsize != r->key_len) {
+			tdb->stats.compare_wrong_keylen++;
+		} else if (hash != r->full_hash) {
+			tdb->stats.compare_wrong_rechash++;
+		} else if (tdb1_parse_data(tdb, key, rec_ptr + sizeof(*r),
+					   r->key_len, tdb1_key_compare,
+					   NULL) != 0) {
+			tdb->stats.compare_wrong_keycmp++;
+		} else {
 			return rec_ptr;
 			return rec_ptr;
 		}
 		}
 		/* detect tight infinite loop */
 		/* detect tight infinite loop */

+ 5 - 0
ccan/tdb2/tdb1_transaction.c

@@ -432,6 +432,7 @@ static int _tdb1_transaction_start(struct tdb_context *tdb)
 			tdb->last_error = TDB_ERR_EINVAL;
 			tdb->last_error = TDB_ERR_EINVAL;
 			return -1;
 			return -1;
 		}
 		}
+		tdb->stats.transaction_nest++;
 		tdb->tdb1.transaction->nesting++;
 		tdb->tdb1.transaction->nesting++;
 		return 0;
 		return 0;
 	}
 	}
@@ -511,6 +512,7 @@ static int _tdb1_transaction_start(struct tdb_context *tdb)
 	tdb->tdb1.transaction->io_methods = tdb->tdb1.io;
 	tdb->tdb1.transaction->io_methods = tdb->tdb1.io;
 	tdb->tdb1.io = &transaction1_methods;
 	tdb->tdb1.io = &transaction1_methods;
 
 
+	tdb->stats.transactions++;
 	return 0;
 	return 0;
 
 
 fail:
 fail:
@@ -621,6 +623,7 @@ static int _tdb1_transaction_cancel(struct tdb_context *tdb)
 */
 */
 int tdb1_transaction_cancel(struct tdb_context *tdb)
 int tdb1_transaction_cancel(struct tdb_context *tdb)
 {
 {
+	tdb->stats.transaction_cancel++;
 	return _tdb1_transaction_cancel(tdb);
 	return _tdb1_transaction_cancel(tdb);
 }
 }
 
 
@@ -739,6 +742,7 @@ static int tdb1_recovery_allocate(struct tdb_context *tdb,
 			   " failed to create recovery area");
 			   " failed to create recovery area");
 		return -1;
 		return -1;
 	}
 	}
+	tdb->stats.transaction_expand_file++;
 
 
 	/* remap the file (if using mmap) */
 	/* remap the file (if using mmap) */
 	methods->tdb1_oob(tdb, tdb->file->map_size + 1, 1);
 	methods->tdb1_oob(tdb, tdb->file->map_size + 1, 1);
@@ -1000,6 +1004,7 @@ static int _tdb1_transaction_prepare_commit(struct tdb_context *tdb)
 				   " expansion failed");
 				   " expansion failed");
 			return -1;
 			return -1;
 		}
 		}
+		tdb->stats.transaction_expand_file++;
 		tdb->file->map_size = tdb->tdb1.transaction->old_map_size;
 		tdb->file->map_size = tdb->tdb1.transaction->old_map_size;
 		methods->tdb1_oob(tdb, tdb->file->map_size + 1, 1);
 		methods->tdb1_oob(tdb, tdb->file->map_size + 1, 1);
 	}
 	}