mirror of
https://github.com/varun-r-mallya/sysprof.git
synced 2025-12-31 20:36:25 +00:00
libsysprof: add API to add compressed file from data
This commit is contained in:
@ -211,7 +211,7 @@ add_process_info (SysprofRecording *recording,
|
|||||||
* in resolving symbols later on.
|
* in resolving symbols later on.
|
||||||
*/
|
*/
|
||||||
mount_path = g_strdup_printf ("/proc/%u/mountinfo", pid);
|
mount_path = g_strdup_printf ("/proc/%u/mountinfo", pid);
|
||||||
_sysprof_recording_add_file_data (recording, mount_path, mountinfo, -1);
|
_sysprof_recording_add_file_data (recording, mount_path, mountinfo, -1, FALSE);
|
||||||
|
|
||||||
/* Ignore inodes from podman/toolbox because they appear to always be
|
/* Ignore inodes from podman/toolbox because they appear to always be
|
||||||
* wrong. We'll have to rely on CRC/build-id instead.
|
* wrong. We'll have to rely on CRC/build-id instead.
|
||||||
|
|||||||
@ -41,7 +41,8 @@ DexFuture *_sysprof_recording_add_file (SysprofRecording *s
|
|||||||
void _sysprof_recording_add_file_data (SysprofRecording *self,
|
void _sysprof_recording_add_file_data (SysprofRecording *self,
|
||||||
const char *path,
|
const char *path,
|
||||||
const char *contents,
|
const char *contents,
|
||||||
gssize length);
|
gssize length,
|
||||||
|
gboolean compress);
|
||||||
void _sysprof_recording_diagnostic (SysprofRecording *self,
|
void _sysprof_recording_diagnostic (SysprofRecording *self,
|
||||||
const char *domain,
|
const char *domain,
|
||||||
const char *format,
|
const char *format,
|
||||||
|
|||||||
@ -712,12 +712,43 @@ _sysprof_recording_add_file (SysprofRecording *self,
|
|||||||
(GDestroyNotify)add_file_free);
|
(GDestroyNotify)add_file_free);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char *
|
||||||
|
do_compress (const char *data,
|
||||||
|
gsize length,
|
||||||
|
gsize *out_length)
|
||||||
|
{
|
||||||
|
g_autoptr(GZlibCompressor) compressor = g_zlib_compressor_new (G_ZLIB_COMPRESSOR_FORMAT_GZIP, 6);
|
||||||
|
g_autofree char *compressed = g_malloc (length);
|
||||||
|
GConverterResult res;
|
||||||
|
gsize n_read;
|
||||||
|
gsize n_written;
|
||||||
|
|
||||||
|
*out_length = 0;
|
||||||
|
|
||||||
|
res = g_converter_convert (G_CONVERTER (compressor), data, length, compressed, length,
|
||||||
|
G_CONVERTER_INPUT_AT_END | G_CONVERTER_FLUSH,
|
||||||
|
&n_read, &n_written, NULL);
|
||||||
|
|
||||||
|
if (res == G_CONVERTER_FINISHED)
|
||||||
|
{
|
||||||
|
*out_length = n_written;
|
||||||
|
return g_steal_pointer (&compressed);
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
_sysprof_recording_add_file_data (SysprofRecording *self,
|
_sysprof_recording_add_file_data (SysprofRecording *self,
|
||||||
const char *path,
|
const char *path,
|
||||||
const char *contents,
|
const char *contents,
|
||||||
gssize length)
|
gssize length,
|
||||||
|
gboolean compress)
|
||||||
{
|
{
|
||||||
|
g_autofree char *compress_filename = NULL;
|
||||||
|
g_autofree char *compress_bytes = NULL;
|
||||||
|
gsize compress_len = 0;
|
||||||
|
|
||||||
g_return_if_fail (SYSPROF_IS_RECORDING (self));
|
g_return_if_fail (SYSPROF_IS_RECORDING (self));
|
||||||
g_return_if_fail (path != NULL);
|
g_return_if_fail (path != NULL);
|
||||||
g_return_if_fail (contents != NULL);
|
g_return_if_fail (contents != NULL);
|
||||||
@ -725,6 +756,19 @@ _sysprof_recording_add_file_data (SysprofRecording *self,
|
|||||||
if (length < 0)
|
if (length < 0)
|
||||||
length = strlen (contents);
|
length = strlen (contents);
|
||||||
|
|
||||||
|
if (compress)
|
||||||
|
{
|
||||||
|
compress_bytes = do_compress (contents, length, &compress_len);
|
||||||
|
|
||||||
|
if (compress_bytes)
|
||||||
|
{
|
||||||
|
compress_filename = g_strdup_printf ("%s.gz", path);
|
||||||
|
path = compress_filename;
|
||||||
|
contents = compress_bytes;
|
||||||
|
length = compress_len;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
while (length > 0)
|
while (length > 0)
|
||||||
{
|
{
|
||||||
gsize to_write = MIN (length, ((4096*8)-sizeof (SysprofCaptureFileChunk)));
|
gsize to_write = MIN (length, ((4096*8)-sizeof (SysprofCaptureFileChunk)));
|
||||||
|
|||||||
@ -91,7 +91,8 @@ sysprof_symbols_bundle_augment_fiber (gpointer user_data)
|
|||||||
_sysprof_recording_add_file_data (recording,
|
_sysprof_recording_add_file_data (recording,
|
||||||
"__symbols__",
|
"__symbols__",
|
||||||
g_bytes_get_data (bytes, NULL),
|
g_bytes_get_data (bytes, NULL),
|
||||||
g_bytes_get_size (bytes));
|
g_bytes_get_size (bytes),
|
||||||
|
TRUE);
|
||||||
|
|
||||||
return dex_future_new_for_boolean (TRUE);
|
return dex_future_new_for_boolean (TRUE);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user