Skip to content

Commit

Permalink
ndb/stat: include totals in stat output
Browse files Browse the repository at this point in the history
  • Loading branch information
jb55 committed Nov 14, 2023
1 parent 4646498 commit 56952c8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
14 changes: 12 additions & 2 deletions ndb.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,26 @@ static void print_stats(struct ndb_stat *stat)
const char *name;
struct ndb_stat_counts *c;

struct ndb_stat_counts total;
ndb_stat_counts_init(&total);

printf("name\tcount\tkey_bytes\tvalue_bytes\ttotal_bytes\n");
printf("dbs\n---\n");
printf("---\ndbs\n---\n");
for (i = 0; i < NDB_DBS; i++) {
name = ndb_db_name(i);

total.count += stat->dbs[i].count;
total.key_size += stat->dbs[i].key_size;
total.value_size += stat->dbs[i].value_size;

printf("%s\t", name);
print_stat_counts(&stat->dbs[i]);
}

printf("kinds\n-----\n");
printf("total\t");
print_stat_counts(&total);

printf("-----\nkinds\n-----\n");
for (i = 0; i < NDB_CKIND_COUNT; i++) {
c = &stat->common_kinds[i];
if (c->count == 0)
Expand Down
2 changes: 1 addition & 1 deletion nostrdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -2909,7 +2909,7 @@ int ndb_builder_new_tag(struct ndb_builder *builder)
return cursor_push_tag(&builder->note_cur, &tag);
}

static void ndb_stat_counts_init(struct ndb_stat_counts *counts)
void ndb_stat_counts_init(struct ndb_stat_counts *counts)
{
counts->count = 0;
counts->key_size = 0;
Expand Down
1 change: 1 addition & 0 deletions nostrdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ int ndb_builder_push_tag_str(struct ndb_builder *builder, const char *str, int l

// stats
int ndb_stat(struct ndb *ndb, struct ndb_stat *stat);
void ndb_stat_counts_init(struct ndb_stat_counts *counts);

static inline struct ndb_str ndb_note_str(struct ndb_note *note,
union ndb_packed_str *pstr)
Expand Down

0 comments on commit 56952c8

Please sign in to comment.