Browse Source

libobs/util: Add compressed profiler snapshot saving

Palana 10 years ago
parent
commit
91ea844333
3 changed files with 31 additions and 0 deletions
  1. 5 0
      libobs/CMakeLists.txt
  2. 24 0
      libobs/util/profiler.c
  3. 2 0
      libobs/util/profiler.h

+ 5 - 0
libobs/CMakeLists.txt

@@ -35,6 +35,10 @@ else()
 		${FFMPEG_AVCODEC_LIBRARIES})
 endif()
 
+find_package(ZLIB REQUIRED)
+
+include_directories(SYSTEM ${ZLIB_INCLUDE_DIR})
+
 add_definitions(-DLIBOBS_EXPORTS)
 
 include_directories(${OBS_JANSSON_INCLUDE_DIRS})
@@ -330,6 +334,7 @@ target_link_libraries(libobs
 		${libobs_image_loading_LIBRARIES}
 		${OBS_JANSSON_IMPORT}
 		${FFMPEG_LIBRARIES}
+		${ZLIB_LIBRARIES}
 	PUBLIC
 		${THREADS_LIBRARIES})
 

+ 24 - 0
libobs/util/profiler.c

@@ -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;

+ 2 - 0
libobs/util/profiler.h

@@ -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,