/* * Records a "removal" of a key. */ void stats_prefix_record_removal(const char *key, const size_t nkey, size_t bytes, rel_time_t time, long flags) { PREFIX_STATS *pfs; GLOBAL_STATS_LOCK(); pfs = stats_prefix_find(key, nkey); if (NULL != pfs) { rel_time_t now = current_time; if (flags & UNLINK_IS_EVICT) { pfs->num_evicts ++; } else if (flags & UNLINK_IS_EXPIRED) { pfs->num_expires ++; } if (now != pfs->last_update) { /* * increment total byte-seconds to reflect time elapsed since last * update. */ pfs->total_byte_seconds += pfs->num_bytes * (now - pfs->last_update); pfs->last_update = now; } /* remove the byte count and the lifetime of the object that we're * booting out. */ pfs->num_bytes -= bytes; /* increment item count. */ pfs->num_items --; } GLOBAL_STATS_UNLOCK(); }
/* * Records the change in byte total due to a "set" of a key. */ void stats_prefix_record_byte_total_change(const char *key, const size_t nkey, long bytes, int prefix_stats_flags) { PREFIX_STATS *pfs; GLOBAL_STATS_LOCK(); pfs = stats_prefix_find(key, nkey); if (NULL != pfs) { rel_time_t now = current_time; if (now != pfs->last_update) { /* * increment total byte-seconds to reflect time elapsed since last * update. */ pfs->total_byte_seconds += pfs->num_bytes * (now - pfs->last_update); pfs->last_update = now; } /* add the byte count of the object that we're booting out. */ pfs->num_bytes += bytes; if (prefix_stats_flags & PREFIX_INCR_ITEM_COUNT) { /* increment item count. */ pfs->num_items ++; } if (prefix_stats_flags & PREFIX_IS_OVERWRITE) { /* increment overwrite count. */ pfs->num_overwrites ++; } } GLOBAL_STATS_UNLOCK(); }
void stats_prefix_record_setattr(const char *key, const size_t nkey) { PREFIX_STATS *pfs; STATS_LOCK(); pfs = stats_prefix_find(key, nkey); if (NULL != pfs) { pfs->num_setattrs++; } STATS_UNLOCK(); }
void stats_prefix_record_set(const char *key, const size_t nkey) {//记录某key被设置的次数 PREFIX_STATS *pfs; STATS_LOCK(); pfs = stats_prefix_find(key, nkey); if (NULL != pfs) { pfs->num_sets++; //写操作增加一次 } STATS_UNLOCK(); }
/* * Records a "delete" of a key. */ void stats_prefix_record_delete(const char *key, const size_t nkey) { PREFIX_STATS *pfs; GLOBAL_STATS_LOCK(); pfs = stats_prefix_find(key, nkey); if (NULL != pfs) { pfs->num_deletes++; } GLOBAL_STATS_UNLOCK(); }
static void test_prefix_record_set() { PREFIX_STATS *pfs; stats_prefix_record_set("abc:123"); pfs = stats_prefix_find("abc:123"); test_equals_ull("get count after set #1", 0, pfs->num_gets); test_equals_ull("hit count after set #1", 0, pfs->num_hits); test_equals_ull("delete count after set #1", 0, pfs->num_deletes); test_equals_ull("set count after set #1", 1, pfs->num_sets); stats_prefix_record_delete("def:"); test_equals_ull("set count after set #2", 1, pfs->num_sets); }
/* * Records a "set" of a key. */ void stats_prefix_record_set(const char *key, const size_t nkey) { PREFIX_STATS *pfs; // [branch 002] Replaced STATS_LOCK with relaxed transaction // [branch 012] With oncommit, this becomes atomic __transaction_atomic { pfs = stats_prefix_find(key, nkey); if (NULL != pfs) { pfs->num_sets++; } } }
/* * Records a "set" of a key. */ void stats_prefix_record_set(const char *key, const size_t nkey) { PREFIX_STATS *pfs; GLOBAL_STATS_LOCK(); pfs = stats_prefix_find(key, nkey); if (NULL != pfs) { /* item count cannot be incremented here because the set/add/replace may * yet fail. */ pfs->num_sets++; } GLOBAL_STATS_UNLOCK(); }
void stats_prefix_record_bop_gbp(const char *key, const size_t nkey, const bool is_hit) { PREFIX_STATS *pfs; STATS_LOCK(); pfs = stats_prefix_find(key, nkey); if (NULL != pfs) { pfs->num_bop_gbps++; if (is_hit) { pfs->num_bop_gbp_hits++; } } STATS_UNLOCK(); }
/* * Records a "get" of a key. */ void stats_prefix_record_get(const char *key, const size_t nkey, const size_t nbytes, const bool is_hit) { PREFIX_STATS *pfs; GLOBAL_STATS_LOCK(); pfs = stats_prefix_find(key, nkey); if (NULL != pfs) { pfs->num_gets++; if (is_hit) { pfs->num_hits++; pfs->bytes_txed += nbytes; } } GLOBAL_STATS_UNLOCK(); }
static void test_prefix_record_get() { PREFIX_STATS *pfs; stats_prefix_record_get("abc:123", 0); pfs = stats_prefix_find("abc:123"); test_equals_ull("get count after get #1", 1, pfs->num_gets); test_equals_ull("hit count after get #1", 0, pfs->num_hits); stats_prefix_record_get("abc:456", 0); test_equals_ull("get count after get #2", 2, pfs->num_gets); test_equals_ull("hit count after get #2", 0, pfs->num_hits); stats_prefix_record_get("abc:456", 1); test_equals_ull("get count after get #3", 3, pfs->num_gets); test_equals_ull("hit count after get #3", 1, pfs->num_hits); stats_prefix_record_get("def:", 1); test_equals_ull("get count after get #4", 3, pfs->num_gets); test_equals_ull("hit count after get #4", 1, pfs->num_hits); }
static void test_prefix_find() { PREFIX_STATS *pfs1, *pfs2; pfs1 = stats_prefix_find("abc"); test_notnull_ptr("initial prefix find", pfs1); test_equals_ull("request counts", 0ULL, pfs1->num_gets + pfs1->num_sets + pfs1->num_deletes + pfs1->num_hits); pfs2 = stats_prefix_find("abc"); test_equals_ptr("find of same prefix", pfs1, pfs2); pfs2 = stats_prefix_find("abc:"); test_equals_ptr("find of same prefix, ignoring delimiter", pfs1, pfs2); pfs2 = stats_prefix_find("abc:d"); test_equals_ptr("find of same prefix, ignoring extra chars", pfs1, pfs2); pfs2 = stats_prefix_find("xyz123"); test_notequals_ptr("find of different prefix", pfs1, pfs2); pfs2 = stats_prefix_find("ab:"); test_notequals_ptr("find of shorter prefix", pfs1, pfs2); }