Skip to content

Commit

Permalink
survey: checkpoint add blob pretty print
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 f74a366 commit abe5080
Showing 1 changed file with 83 additions and 14 deletions.
97 changes: 83 additions & 14 deletions builtin/survey.c
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,9 @@ struct large_item {

/*
* For blobs and trees the name field is the pathname of the
* file or directory. Root trees will have a zero-length
* name. The name field is not currenly used for commits.
* file or directory (as reported by the treewalk). Root trees
* are reported with a zero-length name, but we'll fix them up.
* The name field is not currenly used for commits.
*/
struct strbuf *name;

Expand Down Expand Up @@ -387,13 +388,15 @@ struct large_item_vec {
const struct large_item_vec_labels *labels_json;
const struct large_item_vec_labels *labels_pretty;
uint64_t nr_items;
enum object_type type;
struct large_item items[FLEX_ARRAY]; /* nr_items */
};

static struct large_item_vec *alloc_large_item_vec(
const struct large_item_vec_labels *labels_json,
const struct large_item_vec_labels *labels_pretty,
uint64_t nr_items)
uint64_t nr_items,
enum object_type type)
{
struct large_item_vec *vec;
size_t flex_len = nr_items * sizeof(struct large_item);
Expand All @@ -406,6 +409,7 @@ static struct large_item_vec *alloc_large_item_vec(
vec->labels_json = labels_json;
vec->labels_pretty = labels_pretty;
vec->nr_items = nr_items;
vec->type = type;

for (k = 0; k < nr_items; k++) {
struct strbuf *p = xcalloc(1, sizeof(struct strbuf));
Expand Down Expand Up @@ -470,6 +474,15 @@ static void maybe_insert_large_item(struct large_item_vec *vec,
strbuf_reset(pbuf_temp);
if (name && *name)
strbuf_addstr(pbuf_temp, name);
else if (vec->type == OBJ_TREE) {
/*
* NEEDSWORK: Would it be better to wait and create
* a name of the form "<name_rev>^{tree}" after the
* treewalk is finished?
*/
strbuf_addf(pbuf_temp, "%s^{tree}",
oid_to_hex(containing_commit_oid));
}

/* push items[k..] down one and insert data for this item here */

Expand Down Expand Up @@ -654,7 +667,8 @@ static void alloc_commit_by_parents(void)
if (survey_opts.show_largest_commits_by_nr_parents)
survey_stats.commits.vec_largest_by_nr_parents =
alloc_large_item_vec(&json, &pretty,
survey_opts.show_largest_commits_by_nr_parents);
survey_opts.show_largest_commits_by_nr_parents,
OBJ_COMMIT);
}

static void alloc_commit_by_size(void) {
Expand All @@ -670,7 +684,8 @@ static void alloc_commit_by_size(void) {
if (survey_opts.show_largest_commits_by_size_bytes)
survey_stats.commits.vec_largest_by_size_bytes =
alloc_large_item_vec(&json, &pretty,
survey_opts.show_largest_commits_by_size_bytes);
survey_opts.show_largest_commits_by_size_bytes,
OBJ_COMMIT);
};

Check failure on line 689 in builtin/survey.c

View workflow job for this annotation

GitHub Actions / linux-leaks (ubuntu-latest)

builtin/survey.c:689:2: ISO C does not allow extra ‘;’ outside of a function [-Werror=pedantic]

Check failure on line 689 in builtin/survey.c

View workflow job for this annotation

GitHub Actions / linux-reftable-leaks (ubuntu-latest)

builtin/survey.c:689:2: ISO C does not allow extra ‘;’ outside of a function [-Werror=pedantic]

Check failure on line 689 in builtin/survey.c

View workflow job for this annotation

GitHub Actions / linux-gcc (ubuntu-20.04)

builtin/survey.c:689:2: ISO C does not allow extra ‘;’ outside of a function [-Werror=pedantic]

Check failure on line 689 in builtin/survey.c

View workflow job for this annotation

GitHub Actions / linux-gcc-default (ubuntu-latest)

builtin/survey.c:689:2: ISO C does not allow extra ‘;’ outside of a function [-Werror=pedantic]

Check failure on line 689 in builtin/survey.c

View workflow job for this annotation

GitHub Actions / linux-TEST-vars (ubuntu-20.04)

builtin/survey.c:689:2: ISO C does not allow extra ‘;’ outside of a function [-Werror=pedantic]

Check failure on line 689 in builtin/survey.c

View workflow job for this annotation

GitHub Actions / linux-reftable (ubuntu-latest)

builtin/survey.c:689:2: extra ';' outside of a function [-Werror,-Wextra-semi]

Check failure on line 689 in builtin/survey.c

View workflow job for this annotation

GitHub Actions / linux-musl (alpine)

builtin/survey.c:689:2: ISO C does not allow extra ';' outside of a function [-Werror=pedantic]

Check failure on line 689 in builtin/survey.c

View workflow job for this annotation

GitHub Actions / pedantic (fedora)

builtin/survey.c:689:2: ISO C does not allow extra ';' outside of a function [-Werror=pedantic]

Check failure on line 689 in builtin/survey.c

View workflow job for this annotation

GitHub Actions / linux32 (daald/ubuntu32:xenial)

builtin/survey.c:689:2: ISO C does not allow extra ';' outside of a function [-Werror=pedantic]

Check failure on line 689 in builtin/survey.c

View workflow job for this annotation

GitHub Actions / linux-asan-ubsan (ubuntu-latest)

builtin/survey.c:689:2: extra ';' outside of a function [-Werror,-Wextra-semi]

static void alloc_tree_by_entries(void)
Expand All @@ -687,7 +702,8 @@ static void alloc_tree_by_entries(void)
if (survey_opts.show_largest_trees_by_nr_entries)
survey_stats.trees.vec_largest_by_nr_entries =
alloc_large_item_vec(&json, &pretty,
survey_opts.show_largest_trees_by_nr_entries);
survey_opts.show_largest_trees_by_nr_entries,
OBJ_TREE);
}

static void alloc_tree_by_size(void)
Expand All @@ -704,7 +720,8 @@ static void alloc_tree_by_size(void)
if (survey_opts.show_largest_trees_by_size_bytes)
survey_stats.trees.vec_largest_by_size_bytes =
alloc_large_item_vec(&json, &pretty,
survey_opts.show_largest_trees_by_size_bytes);
survey_opts.show_largest_trees_by_size_bytes,
OBJ_TREE);
}

static void alloc_blob_by_size(void)
Expand All @@ -721,7 +738,8 @@ static void alloc_blob_by_size(void)
if (survey_opts.show_largest_blobs_by_size_bytes)
survey_stats.blobs.vec_largest_by_size_bytes =
alloc_large_item_vec(&json, &pretty,
survey_opts.show_largest_blobs_by_size_bytes);
survey_opts.show_largest_blobs_by_size_bytes,
OBJ_BLOB);
}

static void do_load_refs(struct ref_array *ref_array)
Expand Down Expand Up @@ -1788,6 +1806,7 @@ static void fmt_pbin_row(struct strbuf *buf,

static void fmt_large_item_hdr(struct strbuf *buf,
int indent,
int name_length,
int name_rev_length,
const char *item_hdr_label)
{
Expand All @@ -1797,13 +1816,16 @@ static void fmt_large_item_hdr(struct strbuf *buf,
strbuf_addchars(buf, ' ', indent);

strbuf_addf(buf, "%-*s | %14s", column0, "OID", item_hdr_label);
if (name_length)
strbuf_addf(buf, " | %-*s", name_length, "Name");
strbuf_addf(buf, " | %-*s", name_rev_length, "Name Rev");

strbuf_addch(buf, '\n');
}

static void fmt_large_item_hr(struct strbuf *buf,
int indent,
int name_length,
int name_rev_length)
{
int column0 = the_hash_algo->hexsz;
Expand All @@ -1814,6 +1836,10 @@ static void fmt_large_item_hr(struct strbuf *buf,
strbuf_addchars(buf, '-', column0);
strbuf_addstr(buf, "-+-");
strbuf_addchars(buf, '-', 14);
if (name_length) {
strbuf_addstr(buf, "-+-");
strbuf_addchars(buf, '-', name_length);
}
strbuf_addstr(buf, "-+-");
strbuf_addchars(buf, '-', name_rev_length);

Expand All @@ -1822,6 +1848,8 @@ static void fmt_large_item_hr(struct strbuf *buf,

static void fmt_large_item_row(struct strbuf *buf,
int indent,
int name_length,
int name_rev_length,
struct large_item *pitem)
{
int column0 = the_hash_algo->hexsz;
Expand All @@ -1832,7 +1860,10 @@ static void fmt_large_item_row(struct strbuf *buf,
strbuf_addf(buf, "%-*s | %14"PRIu64,
column0, oid_to_hex(&pitem->oid),
pitem->size);
strbuf_addf(buf, " | %-s", pitem->name_rev->buf);
if (name_length)
strbuf_addf(buf, " | %-*s", name_length,
(pitem->name ? pitem->name->buf: ""));
strbuf_addf(buf, " | %-*s", name_rev_length, pitem->name_rev->buf);

strbuf_addch(buf, '\n');
}
Expand All @@ -1841,23 +1872,34 @@ static void fmt_large_item_vec(struct strbuf *buf,
int indent,
struct large_item_vec *pvec)
{
int name_length = 0;
int name_rev_length = 10;
int k;

if (pvec->type != OBJ_COMMIT) {
/* Add "Name" column for trees and blobs. */
for (k = 0; k < pvec->nr_items; k++)
if (pvec->items[k].name && pvec->items[k].name->len > name_length)
name_length = pvec->items[k].name->len;
if (name_length)
if (name_length < 4) /* strlen("Name") */
name_length = 4;
}

for (k = 0; k < pvec->nr_items; k++)
if (pvec->items[k].name_rev->len > name_rev_length)
name_rev_length = pvec->items[k].name_rev->len;

strbuf_addch(buf, '\n');
fmt_txt_line(buf, indent, pvec->labels_pretty->dimension);
fmt_large_item_hr(buf, indent, name_rev_length);
fmt_large_item_hdr(buf, indent, name_rev_length, pvec->labels_pretty->item);
fmt_large_item_hr(buf, indent, name_rev_length);
fmt_large_item_hr(buf, indent, name_length, name_rev_length);
fmt_large_item_hdr(buf, indent, name_length, name_rev_length, pvec->labels_pretty->item);
fmt_large_item_hr(buf, indent, name_length, name_rev_length);

for (k = 0; k < pvec->nr_items; k++)
fmt_large_item_row(buf, indent, &pvec->items[k]);
fmt_large_item_row(buf, indent, name_length, name_rev_length, &pvec->items[k]);

fmt_large_item_hr(buf, indent, name_rev_length);
fmt_large_item_hr(buf, indent, name_length, name_rev_length);
}

static void fmt_commit_row(struct strbuf *buf,
Expand Down Expand Up @@ -2234,7 +2276,12 @@ static void pretty_print_trees(int indent)

static void pretty_print_blobs(int indent)
{
struct survey_stats_blobs *psb = &survey_stats.blobs;
struct survey_stats_base_object *base = &psb->base;
struct strbuf buf = STRBUF_INIT;
int indent1 = indent + 4;
int indent2 = indent + 8;
int indent3 = indent + 12;

Check failure on line 2284 in builtin/survey.c

View workflow job for this annotation

GitHub Actions / linux-leaks (ubuntu-latest)

builtin/survey.c:2284:13: unused variable ‘indent3’ [-Werror=unused-variable]

Check failure on line 2284 in builtin/survey.c

View workflow job for this annotation

GitHub Actions / linux-reftable-leaks (ubuntu-latest)

builtin/survey.c:2284:13: unused variable ‘indent3’ [-Werror=unused-variable]

Check failure on line 2284 in builtin/survey.c

View workflow job for this annotation

GitHub Actions / linux-gcc (ubuntu-20.04)

builtin/survey.c:2284:6: unused variable ‘indent3’ [-Werror=unused-variable]

Check failure on line 2284 in builtin/survey.c

View workflow job for this annotation

GitHub Actions / linux-gcc-default (ubuntu-latest)

builtin/survey.c:2284:13: unused variable ‘indent3’ [-Werror=unused-variable]

Check failure on line 2284 in builtin/survey.c

View workflow job for this annotation

GitHub Actions / linux-TEST-vars (ubuntu-20.04)

builtin/survey.c:2284:6: unused variable ‘indent3’ [-Werror=unused-variable]

Check failure on line 2284 in builtin/survey.c

View workflow job for this annotation

GitHub Actions / linux-sha256 (ubuntu-latest)

builtin/survey.c:2284:6: unused variable 'indent3' [-Werror,-Wunused-variable]

Check failure on line 2284 in builtin/survey.c

View workflow job for this annotation

GitHub Actions / linux-reftable (ubuntu-latest)

builtin/survey.c:2284:6: unused variable 'indent3' [-Werror,-Wunused-variable]

Check failure on line 2284 in builtin/survey.c

View workflow job for this annotation

GitHub Actions / linux-musl (alpine)

builtin/survey.c:2284:13: unused variable 'indent3' [-Werror=unused-variable]

Check failure on line 2284 in builtin/survey.c

View workflow job for this annotation

GitHub Actions / pedantic (fedora)

builtin/survey.c:2284:13: unused variable 'indent3' [-Werror=unused-variable]

Check failure on line 2284 in builtin/survey.c

View workflow job for this annotation

GitHub Actions / linux32 (daald/ubuntu32:xenial)

builtin/survey.c:2284:6: unused variable 'indent3' [-Werror=unused-variable]

Check failure on line 2284 in builtin/survey.c

View workflow job for this annotation

GitHub Actions / linux-asan-ubsan (ubuntu-latest)

builtin/survey.c:2284:6: unused variable 'indent3' [-Werror,-Wunused-variable]
int k;

const char *intro[] = {
Expand All @@ -2252,6 +2299,28 @@ static void pretty_print_blobs(int indent)
while (intro[k])
fmt_txt_line(&buf, indent, intro[k++]);

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

strbuf_addch(&buf, '\n');
fmt_txt_line(&buf, indent1, "Blob 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 Blobs", base->sum_size, NULL);
fmt_commit_row(&buf, indent1, "Total Disk Size of Blobs", base->sum_disk_size, NULL);

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

/*
* NEEDSWORK: TODO
*/
Expand Down

0 comments on commit abe5080

Please sign in to comment.