Skip to content

Commit

Permalink
survey: checkpoint adding pretty output for trees
Browse files Browse the repository at this point in the history
Signed-off-by: Jeff Hostetler <jeffhostetler@github.com>
  • Loading branch information
jeffhostetler committed May 24, 2024
1 parent 6aef006 commit f74a366
Showing 1 changed file with 175 additions and 6 deletions.
181 changes: 175 additions & 6 deletions builtin/survey.c
Original file line number Diff line number Diff line change
Expand Up @@ -1550,6 +1550,98 @@ static void fmt_ref_row(struct strbuf *buf,
strbuf_addch(buf, '\n');
}

static void fmt_qbin_hdr(struct strbuf *buf,
int indent,
const char *bucket,
const char *count,
const char *size,
const char *disk_size)
{
int column0 = 28;

if (indent)
strbuf_addchars(buf, ' ', indent);

strbuf_addf(buf, "%-*s | %14s | %14s | %14s",
column0 - indent, bucket,
count, size, disk_size);

strbuf_addch(buf, '\n');
}

static void fmt_qbin_hr(struct strbuf *buf,
int indent)
{
int column0 = 28;

if (indent)
strbuf_addchars(buf, ' ', indent);

strbuf_addchars(buf, '-', column0 - indent);
strbuf_addstr(buf, "-+-");
strbuf_addchars(buf, '-', 14);
strbuf_addstr(buf, "-+-");
strbuf_addchars(buf, '-', 14);
strbuf_addstr(buf, "-+-");
strbuf_addchars(buf, '-', 14);

strbuf_addch(buf, '\n');
}

static void fmt_qbin_row(struct strbuf *buf,
int indent,
uint64_t lbound,
uint64_t ubound,
uint64_t count,
uint64_t size,
uint64_t disk_size)
{
struct strbuf bucket = STRBUF_INIT;
int column0 = 28;

if (indent)
strbuf_addchars(buf, ' ', indent);

strbuf_addf(&bucket, "%"PRIu64"..%"PRIu64, lbound, ubound);
strbuf_addf(buf, "%-*s | %14"PRIu64" | %14"PRIu64" | %14"PRIu64,
column0 - indent, bucket.buf,
count, size, disk_size);

strbuf_addch(buf, '\n');
strbuf_release(&bucket);
}

static void fmt_qbin(struct strbuf *buf,
int indent, const char *title_caption,
struct obj_hist_bin qbin[QBIN_LEN])
{
uint64_t lower = 0;
uint64_t upper = QBIN_MASK;
int k;

strbuf_addch(buf, '\n');
fmt_txt_line(buf, indent, title_caption);
fmt_qbin_hr(buf, indent);
fmt_qbin_hdr(buf, indent, "Byte Range", "Count", "Size", "Disk Size");
fmt_qbin_hr(buf, indent);

for (k = 0; k < QBIN_LEN; k++) {
struct obj_hist_bin *p = &qbin[k];
uint64_t lower_k = lower;
uint64_t upper_k = upper;

lower = upper+1;
upper = (upper << QBIN_SHIFT) + QBIN_MASK;

if (!p->cnt_seen)
continue;

fmt_qbin_row(buf, indent, lower_k, upper_k,
p->cnt_seen, p->sum_size, p->sum_disk_size);
}
fmt_qbin_hr(buf, indent);
}

static void fmt_hbin_hdr(struct strbuf *buf,
int indent,
const char *bucket,
Expand Down Expand Up @@ -1619,6 +1711,7 @@ static void fmt_hbin(struct strbuf *buf,
uint64_t upper = HBIN_MASK;
int k;

strbuf_addch(buf, '\n');
fmt_txt_line(buf, indent, title_caption);
fmt_hbin_hr(buf, indent);
fmt_hbin_hdr(buf, indent, "Byte Range", "Count", "Size", "Disk Size");
Expand Down Expand Up @@ -1748,7 +1841,7 @@ static void fmt_large_item_vec(struct strbuf *buf,
int indent,
struct large_item_vec *pvec)
{
int name_rev_length = 50;
int name_rev_length = 10;
int k;

for (k = 0; k < pvec->nr_items; k++)
Expand Down Expand Up @@ -1787,6 +1880,46 @@ static void fmt_commit_row(struct strbuf *buf,
strbuf_addch(buf, '\n');
}

static void fmt_tree_row(struct strbuf *buf,
int indent,
const char *label,
uint64_t value,
const char *footnote)
{
int column0 = 40;

if (indent)
strbuf_addchars(buf, ' ', indent);

strbuf_addf(buf, "%-*s : %14"PRIu64,
column0 - indent, label,
value);
if (footnote && *footnote)
strbuf_addf(buf, " : %s", footnote);

strbuf_addch(buf, '\n');
}

static void fmt_blob_row(struct strbuf *buf,
int indent,
const char *label,
uint64_t value,
const char *footnote)
{
int column0 = 40;

if (indent)
strbuf_addchars(buf, ' ', indent);

strbuf_addf(buf, "%-*s : %14"PRIu64,
column0 - indent, label,
value);
if (footnote && *footnote)
strbuf_addf(buf, " : %s", footnote);

strbuf_addch(buf, '\n');
}

static void pretty_print_survey_hdr(void)
{
struct strbuf buf = STRBUF_INIT;
Expand Down Expand Up @@ -2015,8 +2148,12 @@ static void pretty_print_commits(int indent)
fmt_commit_row(&buf, indent1, "Total Size of Commits", base->sum_size, NULL);
fmt_commit_row(&buf, indent1, "Total Disk Size of Commits", base->sum_disk_size, NULL);

fmt_hbin(&buf, indent1, "Commit Histogram by Size in Bytes", base->size_hbin);

fmt_large_item_vec(&buf, indent1, psc->vec_largest_by_size_bytes);

strbuf_addch(&buf, '\n');
fmt_txt_line(&buf, indent1, "Commit Count by Number of Parents");
fmt_txt_line(&buf, indent1, "Commit Histogram by Number of Parents");
fmt_pbin_hr(&buf, indent1);
fmt_pbin_hdr(&buf, indent1, "Parents", "Count");
fmt_pbin_hr(&buf, indent1);
Expand All @@ -2025,11 +2162,7 @@ static void pretty_print_commits(int indent)
fmt_pbin_row(&buf, indent1, k, psc->parent_cnt_pbin[k]);
fmt_pbin_hr(&buf, indent1);

strbuf_addch(&buf, '\n');
fmt_hbin(&buf, indent1, "Commit Histogram by Size", base->size_hbin);

fmt_large_item_vec(&buf, indent1, psc->vec_largest_by_nr_parents);
fmt_large_item_vec(&buf, indent1, psc->vec_largest_by_size_bytes);

/*
* NEEDSWORK: Add footnotes as necessary.
Expand All @@ -2042,13 +2175,21 @@ static void pretty_print_commits(int indent)

static void pretty_print_trees(int indent)
{
struct survey_stats_trees *pst = &survey_stats.trees;
struct survey_stats_base_object *base = &pst->base;
struct strbuf buf = STRBUF_INIT;
int indent1 = indent + 4;
int indent2 = indent + 8;
int indent3 = indent + 12;
int k;

const char *intro[] = {
"",
"TREES",
"-------------------------------------------------------------------------------",
/*
* NEEDSWORK: Any other fixed text for this page?
*/
"",
NULL
};
Expand All @@ -2057,6 +2198,31 @@ static void pretty_print_trees(int indent)
while (intro[k])
fmt_txt_line(&buf, indent, intro[k++]);

fmt_tree_row(&buf, indent1, "Total Number of Trees", base->cnt_seen, NULL);

strbuf_addch(&buf, '\n');
fmt_txt_line(&buf, indent1, "Tree Count by Storage Location");
if (base->cnt_missing)
fmt_commit_row(&buf, indent2, "Missing", base->cnt_missing, NULL);
if (base->cnt_cached)
fmt_commit_row(&buf, indent2, "Cached", base->cnt_cached, NULL);
if (base->cnt_loose)
fmt_commit_row(&buf, indent2, "Loose", base->cnt_loose, NULL);
if (base->cnt_packed)
fmt_commit_row(&buf, indent2, "Packed", base->cnt_packed, NULL);
if (base->cnt_dbcached)
fmt_commit_row(&buf, indent2, "DBCached", base->cnt_dbcached, NULL);

strbuf_addch(&buf, '\n');
fmt_commit_row(&buf, indent1, "Total Size of Trees", base->sum_size, NULL);
fmt_commit_row(&buf, indent1, "Total Disk Size of Trees", base->sum_disk_size, NULL);

fmt_hbin(&buf, indent1, "Tree Histogram by Size in Bytes", base->size_hbin);
fmt_large_item_vec(&buf, indent1, pst->vec_largest_by_size_bytes);

fmt_qbin(&buf, indent1, "Tree Histogram by Number of Entries", pst->entry_qbin);
fmt_large_item_vec(&buf, indent1, pst->vec_largest_by_nr_entries);

/*
* NEEDSWORK: TODO
*/
Expand All @@ -2075,6 +2241,9 @@ static void pretty_print_blobs(int indent)
"",
"BLOBS",
"-------------------------------------------------------------------------------",
/*
* NEEDSWORK: Any other fixed text for this page?
*/
"",
NULL
};
Expand Down

0 comments on commit f74a366

Please sign in to comment.