From 6ef81657815892305c8263b33e30f90f2c110bc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20Sandmann=20Pedersen?= Date: Fri, 12 Nov 2004 23:27:52 +0000 Subject: [PATCH] *** empty log message *** --- profile.c | 148 +++++++++++++++++++++++++++++++++++++++++++++++-- sysprof-text.c | 21 +++++++ 2 files changed, 165 insertions(+), 4 deletions(-) create mode 100644 sysprof-text.c diff --git a/profile.c b/profile.c index af394bca..7d4299c9 100644 --- a/profile.c +++ b/profile.c @@ -1,4 +1,6 @@ #include +#include +#include #include "binfile.h" #include "process.h" @@ -101,7 +103,7 @@ serialize_object (gpointer key, gpointer value, gpointer data) SaveContext *context = data; ProfileObject *object = key; - g_string_append_printf (context->str, " \n", + g_string_append_printf (context->str, " \n", get_id (context, object), object->name, object->total, @@ -115,7 +117,7 @@ serialize_call_tree (Node *node, SaveContext *context) return; g_string_append_printf (context->str, - " \n", + " \n", get_id (context, node), get_id (context, node->object), get_id (context, node->siblings), @@ -164,12 +166,150 @@ profile_save (Profile *profile, return FALSE; } +typedef struct LoadContext LoadContext; +struct LoadContext +{ + GHashTable *objects_by_id; + GHashTable *nodes_by_id; + +}; + +static int +get_number (const char *s, GError **err) +{ + char *end; + + int r = strtol (s, &end, 10); + if (*end != '\0') + { + /* FIXME: set error to something appropriate */ + } + + return r; +} + +static Node * +create_node (const char **attribute_names, const char **attribute_values, int *id, GError **error) +{ + int i; + + i = 0; + while (attribute_names[i]) + { + const char *name = attribute_names[i]; + const char *value = attribute_values[i]; + + if (strcmp (name, "id") == 0) + { + } + else if (strcmp (name, "sibling") == 0) + { + + } + + i++; + } + return NULL; +} + +static ProfileObject * +create_object (const char **attribute_names, const char **attribute_values, int *id, GError **err) +{ + int i; + + i = 0; + while (attribute_names[i]) + { + const char *name = attribute_names[i]; + const char *value = attribute_values[i]; + + + + + i++; + } + return NULL; +} + +static void +parse_start_element (GMarkupParseContext *context, + const char *element_name, + const char **attribute_names, + const char **attribute_values, + gpointer user_data, + GError **err) +{ + int id; + LoadContext *lc = user_data; + + + if (strcmp (element_name, "object") == 0) + { + ProfileObject *object = create_object (attribute_names, attribute_values, &id, err); + + if (object) + g_hash_table_insert (lc->objects_by_id, GINT_TO_POINTER (id), object); + } + else if (strcmp (element_name, "node") == 0) + { + Node *node = create_node (attribute_names, attribute_values, &id, err); + + if (node) + g_hash_table_insert (lc->nodes_by_id, GINT_TO_POINTER (id), node); + } + else + { + /* ignore anything but object and node */ + } +} + +static void +parse_end_element (GMarkupParseContext *context, + const char *element_name, + gpointer user_data, + GError **error) +{ + +} + +static void +parse_error (GMarkupParseContext *context, + GError **error, + gpointer user_data) +{ +} + Profile * profile_load (const char *filename, GError **err) { - /* FIXME */ - return NULL; + char *input = NULL; + Profile *result = NULL; + + GMarkupParser parser = { + parse_start_element, parse_end_element, NULL, NULL, NULL, + }; + + LoadContext load_context; + GMarkupParseContext *parse_context; + + if (!g_file_get_contents (filename, &input, NULL, err)) + return NULL; + + parse_context = g_markup_parse_context_new (&parser, 0, NULL, NULL); + + if (!g_markup_parse_context_parse (parse_context, input, -1, err)) + goto out; + + if (!g_markup_parse_context_end_parse (parse_context, err)) + goto out; + + g_markup_parse_context_free (parse_context); + + out: + g_free (input); + + return result; } static void diff --git a/sysprof-text.c b/sysprof-text.c new file mode 100644 index 00000000..1e2d416e --- /dev/null +++ b/sysprof-text.c @@ -0,0 +1,21 @@ +/* + * Plan: + * + * blocking_read() + * + * select (fd); + * if (readable) + * read(); + * + * + * handle SIGUSR1 + * write spam to commandline given file + * + */ + + +int +main () +{ + return 0; +}