libobs/util: Add compressed profiler snapshot saving

This commit is contained in:
Palana
2015-08-01 09:28:49 +02:00
parent 5dd030882d
commit 91ea844333
3 changed files with 31 additions and 0 deletions

View File

@@ -7,6 +7,8 @@
#include <math.h>
#include <zlib.h>
//#define TRACK_OVERHEAD
struct profiler_snapshot {
@@ -1022,6 +1024,28 @@ bool profiler_snapshot_dump_csv(const profiler_snapshot_t *snap,
return true;
}
static void dump_csv_gzwrite(void *data, struct dstr *buffer)
{
gzwrite(data, buffer->array, (unsigned)buffer->len);
}
bool profiler_snapshot_dump_csv_gz(const profiler_snapshot_t *snap,
const char *filename)
{
FILE *f = os_fopen(filename, "wb");
if (!f)
return false;
gzFile gz = gzdopen(fileno(f), "wb");
if (!gz)
return false;
profiler_snapshot_dump(snap, dump_csv_gzwrite, gz);
gzclose_w(gz);
return true;
}
size_t profiler_snapshot_num_roots(profiler_snapshot_t *snap)
{
return snap ? snap->roots.num : 0;

View File

@@ -71,6 +71,8 @@ EXPORT void profile_snapshot_free(profiler_snapshot_t *snap);
EXPORT bool profiler_snapshot_dump_csv(const profiler_snapshot_t *snap,
const char *filename);
EXPORT bool profiler_snapshot_dump_csv_gz(const profiler_snapshot_t *snap,
const char *filename);
EXPORT size_t profiler_snapshot_num_roots(profiler_snapshot_t *snap);
EXPORT void profiler_snapshot_enumerate_roots(profiler_snapshot_t *snap,