mirror of
https://github.com/varun-r-mallya/sysprof.git
synced 2025-12-31 20:36:25 +00:00
libsysprof-profile: use GByteArray for read buffer
That way we aren't relying on the stack for access to buffer data.
This commit is contained in:
@ -180,10 +180,10 @@ find_device_by_name (Record *record,
|
||||
static DexFuture *
|
||||
sysprof_disk_usage_record_fiber (gpointer user_data)
|
||||
{
|
||||
g_autoptr(GByteArray) buf = NULL;
|
||||
Record *record = user_data;
|
||||
SysprofCaptureWriter *writer;
|
||||
g_autofd int stat_fd = -1;
|
||||
char buf[4096*4];
|
||||
LineReader reader;
|
||||
DiskUsage *combined;
|
||||
gint64 combined_reads_total = 0;
|
||||
@ -194,6 +194,9 @@ sysprof_disk_usage_record_fiber (gpointer user_data)
|
||||
g_assert (SYSPROF_IS_RECORDING (record->recording));
|
||||
g_assert (DEX_IS_CANCELLABLE (record->cancellable));
|
||||
|
||||
buf = g_byte_array_new ();
|
||||
g_byte_array_set_size (buf, 4096*4);
|
||||
|
||||
if (-1 == (stat_fd = open ("/proc/diskstats", O_RDONLY|O_CLOEXEC)))
|
||||
return dex_future_new_for_errno (errno);
|
||||
|
||||
@ -212,7 +215,7 @@ sysprof_disk_usage_record_fiber (gpointer user_data)
|
||||
* recording loop. If cancellation future rejects, then
|
||||
* we also break out of our recording loop.
|
||||
*/
|
||||
read_future = dex_aio_read (NULL, stat_fd, buf, sizeof buf-1, 0);
|
||||
read_future = dex_aio_read (NULL, stat_fd, buf->data, buf->len-1, 0);
|
||||
if (!dex_await (dex_future_first (dex_ref (record->cancellable),
|
||||
dex_ref (read_future),
|
||||
NULL),
|
||||
@ -223,7 +226,7 @@ sysprof_disk_usage_record_fiber (gpointer user_data)
|
||||
if (n_read < 0)
|
||||
break;
|
||||
|
||||
line_reader_init (&reader, buf, n_read);
|
||||
line_reader_init (&reader, (char *)buf->data, n_read);
|
||||
while ((line = line_reader_next (&reader, &line_len)))
|
||||
{
|
||||
DiskUsage ds = {0};
|
||||
|
||||
@ -171,18 +171,21 @@ record_free (gpointer data)
|
||||
static DexFuture *
|
||||
sysprof_memory_usage_record_fiber (gpointer user_data)
|
||||
{
|
||||
g_autoptr(GByteArray) buf = NULL;
|
||||
Record *record = user_data;
|
||||
SysprofCaptureWriter *writer;
|
||||
g_autoptr(GError) error = NULL;
|
||||
SysprofCaptureCounter counters[1];
|
||||
MemStat st;
|
||||
char buf[4096];
|
||||
guint counter_id;
|
||||
|
||||
g_assert (record != NULL);
|
||||
g_assert (SYSPROF_IS_RECORDING (record->recording));
|
||||
g_assert (DEX_IS_FUTURE (record->cancellable));
|
||||
|
||||
buf = g_byte_array_new ();
|
||||
g_byte_array_set_size (buf, 4096);
|
||||
|
||||
writer = _sysprof_recording_writer (record->recording);
|
||||
|
||||
if (!mem_stat_open (&st, &error))
|
||||
@ -207,7 +210,7 @@ sysprof_memory_usage_record_fiber (gpointer user_data)
|
||||
|
||||
for (;;)
|
||||
{
|
||||
g_autoptr(DexFuture) read_future = dex_aio_read (NULL, st.stat_fd, buf, sizeof buf-1, 0);
|
||||
g_autoptr(DexFuture) read_future = dex_aio_read (NULL, st.stat_fd, buf->data, buf->len-1, 0);
|
||||
gssize n_read;
|
||||
|
||||
dex_await (dex_future_first (dex_ref (read_future),
|
||||
@ -224,9 +227,9 @@ sysprof_memory_usage_record_fiber (gpointer user_data)
|
||||
|
||||
if (n_read > 0)
|
||||
{
|
||||
buf[n_read] = 0;
|
||||
buf->data[n_read] = 0;
|
||||
|
||||
mem_stat_parse (&st, buf);
|
||||
mem_stat_parse (&st, (char *)buf->data);
|
||||
|
||||
sysprof_capture_writer_set_counters (writer,
|
||||
SYSPROF_CAPTURE_CURRENT_TIME,
|
||||
|
||||
@ -107,7 +107,7 @@ find_device_by_name (GArray *ar,
|
||||
static DexFuture *
|
||||
sysprof_network_usage_record_fiber (gpointer user_data)
|
||||
{
|
||||
char buf[4096*2];
|
||||
g_autoptr(GByteArray) buf = g_byte_array_new ();
|
||||
Record *record = user_data;
|
||||
g_autofree SysprofCaptureCounterValue *values = NULL;
|
||||
g_autofree guint *ids = NULL;
|
||||
@ -128,6 +128,8 @@ sysprof_network_usage_record_fiber (gpointer user_data)
|
||||
g_assert (SYSPROF_IS_RECORDING (record->recording));
|
||||
g_assert (DEX_IS_FUTURE (record->cancellable));
|
||||
|
||||
g_byte_array_set_size (buf, 4096*2);
|
||||
|
||||
writer = _sysprof_recording_writer (record->recording);
|
||||
|
||||
if (-1 == (stat_fd = open ("/proc/net/dev", O_RDONLY|O_CLOEXEC)))
|
||||
@ -158,12 +160,12 @@ sysprof_network_usage_record_fiber (gpointer user_data)
|
||||
-1,
|
||||
ctr, G_N_ELEMENTS (ctr));
|
||||
|
||||
n_read = dex_await_int64 (dex_aio_read (NULL, stat_fd, buf, sizeof buf, 0), &error);
|
||||
n_read = dex_await_int64 (dex_aio_read (NULL, stat_fd, buf->data, buf->len, 0), &error);
|
||||
if (n_read <= 0)
|
||||
return dex_future_new_for_errno (errno);
|
||||
|
||||
lineno = 0;
|
||||
line_reader_init (&reader, buf, n_read);
|
||||
line_reader_init (&reader, (char *)buf->data, n_read);
|
||||
while ((line = line_reader_next (&reader, &line_len)))
|
||||
{
|
||||
DeviceUsage dev = {0};
|
||||
@ -229,12 +231,12 @@ sysprof_network_usage_record_fiber (gpointer user_data)
|
||||
gint64 combined_rx = 0;
|
||||
gint64 combined_tx = 0;
|
||||
|
||||
n_read = dex_await_int64 (dex_aio_read (NULL, stat_fd, buf, sizeof buf, 0), &error);
|
||||
n_read = dex_await_int64 (dex_aio_read (NULL, stat_fd, buf->data, buf->len, 0), &error);
|
||||
if (n_read <= 0)
|
||||
break;
|
||||
|
||||
lineno = 0;
|
||||
line_reader_init (&reader, buf, n_read);
|
||||
line_reader_init (&reader, (char *)buf->data, n_read);
|
||||
while ((line = line_reader_next (&reader, &line_len)))
|
||||
{
|
||||
DeviceUsage *dev;
|
||||
|
||||
Reference in New Issue
Block a user