/** * Destroy the DBM wrapper, optionally closing the underlying DB map. */ void dbmw_destroy(dbmw_t *dw, bool close_map) { dbmw_check(dw); if (common_stats) { s_debug("DBMW destroying \"%s\" with %s back-end " "(read cache hits = %.2f%% on %s request%s, " "write cache hits = %.2f%% on %s request%s)", dw->name, dbmw_map_type(dw) == DBMAP_SDBM ? "sdbm" : "map", dw->r_hits * 100.0 / MAX(1, dw->r_access), uint64_to_string(dw->r_access), plural(dw->r_access), dw->w_hits * 100.0 / MAX(1, dw->w_access), uint64_to_string2(dw->w_access), plural(dw->w_access)); } if (dbg_ds_debugging(dw->dbg, 1, DBG_DSF_DESTROY)) { dbg_ds_log(dw->dbg, dw, "%s: with %s back-end " "(read cache hits = %.2f%% on %s request%s, " "write cache hits = %.2f%% on %s request%s)", G_STRFUNC, dbmw_map_type(dw) == DBMAP_SDBM ? "sdbm" : "map", dw->r_hits * 100.0 / MAX(1, dw->r_access), uint64_to_string(dw->r_access), plural(dw->r_access), dw->w_hits * 100.0 / MAX(1, dw->w_access), uint64_to_string2(dw->w_access), plural(dw->w_access)); } /* * If we close the map and we're volatile, there's no need to flush * the cache as the data is going to be gone soon anyway. */ if (!close_map || !dw->is_volatile) { dbmw_sync(dw, DBMW_SYNC_CACHE); } dbmw_clear_cache(dw); hash_list_free(&dw->keys); map_destroy(dw->values); if (dw->mb) pmsg_free(dw->mb); bstr_free(&dw->bs); if (close_map) dbmap_destroy(dw->dm); WFREE_TYPE_NULL(dw->dbmap_dbg); dw->magic = 0; WFREE(dw); }
/** * Destroy the DBM wrapper, optionally closing the underlying DB map. */ void dbmw_destroy(dbmw_t *dw, gboolean close_map) { dbmw_check(dw); if (common_stats) g_debug("DBMW destroying \"%s\" with %s back-end " "(read cache hits = %.2f%% on %s request%s, " "write cache hits = %.2f%% on %s request%s)", dw->name, dbmw_map_type(dw) == DBMAP_SDBM ? "sdbm" : "map", dw->r_hits * 100.0 / MAX(1, dw->r_access), uint64_to_string(dw->r_access), 1 == dw->r_access ? "" : "s", dw->w_hits * 100.0 / MAX(1, dw->w_access), uint64_to_string2(dw->w_access), 1 == dw->w_access ? "" : "s"); /* * If we close the map and we're volatile, there's no need to flush * the cache as the data is going to be gone soon anyway. */ if (!close_map || !dw->is_volatile) { dbmw_sync(dw, DBMW_SYNC_CACHE); } dbmw_clear_cache(dw); hash_list_free(&dw->keys); map_destroy(dw->values); if (dw->mb) pmsg_free(dw->mb); bstr_free(&dw->bs); if (close_map) dbmap_destroy(dw->dm); dw->magic = 0; WFREE(dw); }
void hsep_notify_shared(uint64 own_files, uint64 own_kibibytes) { /* check for change */ if ( own_files != hsep_own[HSEP_IDX_FILES] || own_kibibytes != hsep_own[HSEP_IDX_KIB] ) { if (GNET_PROPERTY(hsep_debug)) { g_debug("HSEP: Shared files changed to %s (%s KiB)", uint64_to_string(own_files), uint64_to_string2(own_kibibytes)); } hsep_own[HSEP_IDX_FILES] = own_files; hsep_own[HSEP_IDX_KIB] = own_kibibytes; /* * We could send a HSEP message to all nodes now, but these changes * will propagate within at most HSEP_MSG_INTERVAL + HSEP_MSG_SKEW * seconds anyway. */ } }
static void print_hsep_table(struct gnutella_shell *sh, hsep_triple *table, int triples, hsep_triple *non_hsep_ptr) { static hsep_triple empty_non_hsep; const char *hops_str = _("Hops"); const char *nodes_str = _("Nodes"); const char *files_str = _("Files"); const char *size_str = _("Size"); hsep_triple non_hsep, *t; char buf[200]; size_t maxlen[4]; size_t i; if (!non_hsep_ptr) { non_hsep_ptr = &empty_non_hsep; } memcpy(non_hsep, non_hsep_ptr, sizeof non_hsep); t = &table[1]; /* * Determine maximum width of each column. */ maxlen[0] = strlen(hops_str); /* length of Hops */ maxlen[1] = strlen(nodes_str); /* length of Nodes */ maxlen[2] = strlen(files_str); /* length of Files */ maxlen[3] = strlen(size_str); /* length of Size */ for (i = 0; i < UNSIGNED(triples) * 4; i++) { size_t n; unsigned m = i % 4; switch (m) { case 0: n = strlen(uint64_to_string(i / 4 + 1)); break; case 1: case 2: case 3: { unsigned j = 0; switch (m) { case 1: j = HSEP_IDX_NODES; break; case 2: j = HSEP_IDX_FILES; break; case 3: j = HSEP_IDX_KIB; break; } n = strlen(uint64_to_string(t[i][j] + non_hsep[j])); } break; default: n = 0; g_assert_not_reached(); } if (n > maxlen[m]) maxlen[m] = n; } str_bprintf(buf, sizeof buf, "%*s %*s %*s %*s\n", (int) maxlen[0], hops_str, (int) maxlen[1], nodes_str, (int) maxlen[2], files_str, (int) maxlen[3], size_str); shell_write(sh, buf); for (i = maxlen[0] + maxlen[1] + maxlen[2] + maxlen[3] + 6; i > 0; i--) shell_write(sh, "-"); shell_write(sh, "\n"); t = &table[1]; for (i = 0; i < UNSIGNED(triples); i++) { const char *s1, *s2, *s3; s1 = uint64_to_string(t[i][HSEP_IDX_NODES] + non_hsep[HSEP_IDX_NODES]); s2 = uint64_to_string2(t[i][HSEP_IDX_FILES] + non_hsep[HSEP_IDX_FILES]); s3 = short_kb_size(t[i][HSEP_IDX_KIB] + non_hsep[HSEP_IDX_KIB], GNET_PROPERTY(display_metric_units)); str_bprintf(buf, sizeof buf, "%*u %*s %*s %*s\n", (int) maxlen[0], (unsigned) (i + 1), (int) maxlen[1], s1, (int) maxlen[2], s2, (int) maxlen[3], s3); shell_write(sh, buf); } }