Skip to content

Instantly share code, notes, and snippets.

@dmarion
Last active April 13, 2022 09:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmarion/48bb9756eccf27bc53c15461b5d3887d to your computer and use it in GitHub Desktop.
Save dmarion/48bb9756eccf27bc53c15461b5d3887d to your computer and use it in GitHub Desktop.
Sample perf measurement with vppinfra perfmon
#if 0
clang \
-g \
-march=native \
-O3 \
-Isrc \
-Llib/x86_64-linux-gnu \
-Wl,-rpath ./lib/x86_64-linux-gnu \
"$0" \
-lvppinfra \
&& exec ./a.out "$@"
exit
#endif
#define _GNU_SOURCE
#include <vppinfra/format.h>
#include <vppinfra/perfmon/perfmon.h>
#include <vppinfra/format_table.h>
u32 __clib_noinline *
test_fn (clib_perfmon_ctx_t *ctx, u32 *v, u32 x)
{
clib_perfmon_enable (ctx);
vec_add1 (v, x);
clib_perfmon_disable (ctx);
return v;
}
int
main ()
{
clib_perfmon_ctx_t ctx = {};
clib_error_t *err;
u32 *vec = 0;
clib_mem_init (0, 32 << 20);
ctx.debug = 1;
if ((err = clib_perfmon_init_by_bundle_name (&ctx, "default")))
clib_panic ("%U", format_clib_error, err);
clib_perfmon_warmup (&ctx);
for (int i = 1; i < 32; i++)
{
clib_perfmon_reset (&ctx);
vec = test_fn (&ctx, vec, i);
clib_perfmon_capture (&ctx, 1, "%u -> %u (alloc size %lu, grow %u)",
vec_len (vec) - 1, vec_len (vec),
clib_mem_size (vec_header (vec)),
_vec_find (vec)->grow_elts);
}
fformat (stdout, "%U\n", format_perfmon_bundle, &ctx);
clib_perfmon_free (&ctx);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment