[sysprof] Add array resizing code
- From: Søren Sandmann Pedersen <ssp src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [sysprof] Add array resizing code
- Date: Mon, 14 Sep 2009 09:07:21 +0000 (UTC)
commit 4ef449b6dbea0cc7ce726a640e558e72d4059079
Author: Søren Sandmann Pedersen <ssp redhat com>
Date: Mon Sep 7 10:02:58 2009 -0400
Add array resizing code
tracker.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++-------------
1 files changed, 48 insertions(+), 14 deletions(-)
---
diff --git a/tracker.c b/tracker.c
index f460a16..fee8d15 100644
--- a/tracker.c
+++ b/tracker.c
@@ -1,22 +1,32 @@
#include <glib.h>
+#include <string.h>
+
#include "tracker.h"
#include "stackstash.h"
typedef struct new_process_t new_process_t;
typedef struct new_map_t new_map_t;
typedef struct sample_t sample_t;
-typedef union time_line_entry_t time_line_entry_t;
+
+typedef enum
+{
+ NEW_PROCESS,
+ NEW_MAP,
+ SAMPLE
+} event_type;
struct new_process_t
{
- pid_t pid;
- char command_line[64];
+ event_type type;
+ int32_t pid;
+ char command_line[256];
};
struct new_map_t
{
+ event_type type;
+ int32_t pid;
char file_name[PATH_MAX];
- pid_t pid;
uint64_t start;
uint64_t end;
uint64_t offset;
@@ -25,25 +35,49 @@ struct new_map_t
struct sample_t
{
- pid_t pid;
- StackNode *trace;
+ event_type type;
+ int32_t pid;
+ StackNode * trace;
};
-union time_line_entry_t
+struct tracker_t
{
- new_process_t new_process;
- new_map_t new_map;
- sample_t sample;
+ size_t n_event_bytes;
+ size_t n_allocated_bytes;
+ uint8_t *events;
};
-struct tracker_t
+#define DEFAULT_SIZE (1024 * 1024 * 4)
+
+static void
+tracker_append (tracker_t *tracker,
+ void *event,
+ int n_bytes)
{
-
-};
+ if (tracker->n_allocated_bytes - tracker->n_event_bytes < n_bytes)
+ {
+ size_t new_size = tracker->n_allocated_bytes * 2;
+
+ tracker->events = g_realloc (tracker->events, new_size);
+
+ tracker->n_allocated_bytes = new_size;
+ }
+
+ g_assert (tracker->n_allocated_bytes - tracker->n_event_bytes >= n_bytes);
+
+ memcpy (tracker->events + tracker->n_event_bytes, event, n_bytes);
+}
tracker_t *
tracker_new (void)
{
+ tracker_t *tracker = g_new0 (tracker_t, 1);
+
+ tracker->n_event_bytes = 0;
+ tracker->n_allocated_bytes = DEFAULT_SIZE;
+ tracker->events = g_malloc (DEFAULT_SIZE);
+
+ return tracker;
}
void
@@ -73,5 +107,5 @@ tracker_add_sample (tracker_t *tracker,
Profile *
tracker_create_profile (tracker_t *tracker)
{
-
+
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]