Author: sandervanderburg
Date: Tue Sep 14 12:25:27 2010
New Revision: 23785
URL: https://svn.nixos.org/websvn/nix/?rev=23785&sc=1
Log:
Separated cluster/edges table in seperate files. Updated documentation a bit so
that I still understand what I wrote
Added:
disnix/disnix/trunk/src/visualize/clustertable.c
disnix/disnix/trunk/src/visualize/clustertable.h
disnix/disnix/trunk/src/visualize/edgestable.c
disnix/disnix/trunk/src/visualize/edgestable.h
Modified:
disnix/disnix/trunk/src/visualize/Makefile.am
disnix/disnix/trunk/src/visualize/main.c
Modified: disnix/disnix/trunk/src/visualize/Makefile.am
==============================================================================
--- disnix/disnix/trunk/src/visualize/Makefile.am Tue Sep 14 12:15:06
2010 (r23784)
+++ disnix/disnix/trunk/src/visualize/Makefile.am Tue Sep 14 12:25:27
2010 (r23785)
@@ -2,6 +2,6 @@
bin_PROGRAMS = disnix-visualize
-disnix_visualize_SOURCES = main.c
+disnix_visualize_SOURCES = main.c clustertable.c edgestable.c
disnix_visualize_LDADD = ../libmanifest/libmanifest.la
disnix_visualize_CFLAGS = -I../libmanifest
Added: disnix/disnix/trunk/src/visualize/clustertable.c
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ disnix/disnix/trunk/src/visualize/clustertable.c Tue Sep 14 12:25:27
2010 (r23785)
@@ -0,0 +1,74 @@
+/*
+ * Disnix - A distributed application layer for Nix
+ * Copyright (C) 2008-2010 Sander van der Burg
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
USA
+ */
+
+#include "clustertable.h"
+#include <activationmapping.h>
+
+GHashTable *generate_cluster_table(GArray *activation_array)
+{
+ unsigned int i;
+
+ /* Create empty hash table */
+ GHashTable *cluster_table = g_hash_table_new(g_str_hash, g_str_equal);
+
+ /* Check all activtion mappings */
+ for(i = 0; i < activation_array->len; i++)
+ {
+ /* Get current mapping item */
+ ActivationMapping *mapping = g_array_index(activation_array,
ActivationMapping*, i);
+
+ /* Get target property of the current mapping item */
+ gchar *target = get_target_interface(mapping);
+
+ /* See whether the target already exists in the table */
+ GArray *services_array = g_hash_table_lookup(cluster_table, target);
+
+ /*
+ * If the target is not yet in the table, create a new empty array
+ * of services and add it to a new entry in the hash table
+ */
+ if(services_array == NULL)
+ {
+ services_array = g_array_new(FALSE, FALSE, sizeof(gchar*));
+ g_hash_table_insert(cluster_table, target, services_array);
+ }
+
+ /* Append service to the array */
+ g_array_append_val(services_array, mapping->service);
+ }
+
+ /* Return the generated cluster table */
+ return cluster_table;
+}
+
+void destroy_cluster_table(GHashTable *cluster_table)
+{
+ GHashTableIter iter;
+ gpointer *key;
+ gpointer *value;
+
+ g_hash_table_iter_init(&iter, cluster_table);
+ while(g_hash_table_iter_next(&iter, (gpointer*)&key, (gpointer*)&value))
+ {
+ GArray *services_array = (GArray*)value;
+ g_array_free(services_array, TRUE);
+ }
+
+ g_hash_table_destroy(cluster_table);
+}
Added: disnix/disnix/trunk/src/visualize/clustertable.h
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ disnix/disnix/trunk/src/visualize/clustertable.h Tue Sep 14 12:25:27
2010 (r23785)
@@ -0,0 +1,41 @@
+/*
+ * Disnix - A distributed application layer for Nix
+ * Copyright (C) 2008-2010 Sander van der Burg
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
USA
+ */
+
+#ifndef __CLUSTERTABLE_H
+#define __CLUSTERTABLE_H
+#include <glib.h>
+
+/**
+ * Generates a cluster table, which contains for each target property
+ * of a machine the deployed services.
+ *
+ * @param activation_array Array with activation mappings
+ * @return Generated cluster table
+ */
+GHashTable *generate_cluster_table(GArray *activation_array);
+
+/**
+ * Removes a clustered table including all its contents from memory
+ *
+ * @param Clustered table to destroy
+ */
+void destroy_cluster_table(GHashTable *cluster_table);
+
+
+#endif
Added: disnix/disnix/trunk/src/visualize/edgestable.c
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ disnix/disnix/trunk/src/visualize/edgestable.c Tue Sep 14 12:25:27
2010 (r23785)
@@ -0,0 +1,115 @@
+/*
+ * Disnix - A distributed application layer for Nix
+ * Copyright (C) 2008-2010 Sander van der Burg
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
USA
+ */
+
+#include "edgestable.h"
+#include <activationmapping.h>
+
+GHashTable *generate_edges_table(GArray *activation_array)
+{
+ unsigned int i;
+
+ /* Create empty hash table */
+ GHashTable *edges_table = g_hash_table_new(g_str_hash, g_str_equal);
+
+ for(i = 0; i < activation_array->len; i++)
+ {
+ /* Retrieve the current mapping from the array */
+ ActivationMapping *mapping = g_array_index(activation_array,
ActivationMapping*, i);
+
+ /* Retrieve the target property */
+ gchar *target = get_target_interface(mapping);
+
+ /* Generate an edge table key, which consist of Nix store
component:targetProperty */
+ gchar *mapping_key = g_strconcat(mapping->service, ":", target, NULL);
+
+ /* Retrieve the dependency array of the mapping from the edges table */
+ GArray *dependency_array = g_hash_table_lookup(edges_table,
mapping_key);
+
+ /* If the dependency array does not exists, create one and add it to
the table */
+ if(dependency_array == NULL)
+ {
+ unsigned int j;
+ GArray *depends_on = mapping->depends_on;
+
+ /* Create new dependency array */
+ dependency_array = g_array_new(FALSE, FALSE, sizeof(gchar*));
+
+ /* Create a list of mapping values for each dependency */
+ for(j = 0; j < depends_on->len; j++)
+ {
+ ActivationMapping lookup;
+ ActivationMapping *actual_mapping;
+ gchar *mapping_value, *target;
+ int actual_mapping_index;
+
+ /* Retrieve current dependency from the array */
+ Dependency *dependency = g_array_index(depends_on, Dependency*,
j);
+
+ /* Find the activation mapping in the activation array */
+ lookup.service = dependency->service;
+ lookup.target = dependency->target;
+ actual_mapping_index =
activation_mapping_index(activation_array, &lookup);
+
+ /* Retrieve the actual mapping */
+ actual_mapping = g_array_index(activation_array,
ActivationMapping*, actual_mapping_index);
+
+ /* Get the target interface */
+ target = get_target_interface(actual_mapping);
+
+ /* Generate mapping value from the service and target property
*/
+ mapping_value = g_strconcat(actual_mapping->service, ":",
target, NULL);
+
+ /* Add mapping value to the dependency array */
+ g_array_append_val(dependency_array, mapping_value);
+ }
+
+ /* Associate the dependency array to the given mapping */
+ g_hash_table_insert(edges_table, mapping_key, dependency_array);
+ }
+ }
+
+ /* Return the generated egdes table */
+ return edges_table;
+}
+
+void destroy_edges_table(GHashTable *edges_table)
+{
+ GHashTableIter iter;
+ gpointer *key;
+ gpointer *value;
+
+ g_hash_table_iter_init(&iter, edges_table);
+ while(g_hash_table_iter_next(&iter, (gpointer*)&key, (gpointer*)&value))
+ {
+ gchar *mapping_key = (gchar*)key;
+ GArray *dependency_array = (GArray*)value;
+ unsigned int i;
+
+ for(i = 0; i < dependency_array->len; i++)
+ {
+ gchar *dep = g_array_index(dependency_array, gchar*, i);
+ g_free(dep);
+ }
+
+ g_array_free(dependency_array, TRUE);
+ g_free(mapping_key);
+ }
+
+ g_hash_table_destroy(edges_table);
+}
Added: disnix/disnix/trunk/src/visualize/edgestable.h
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ disnix/disnix/trunk/src/visualize/edgestable.h Tue Sep 14 12:25:27
2010 (r23785)
@@ -0,0 +1,40 @@
+/*
+ * Disnix - A distributed application layer for Nix
+ * Copyright (C) 2008-2010 Sander van der Burg
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
USA
+ */
+
+#ifndef __EDGESTABLE_H
+#define __EDGESTABLE_H
+#include <glib.h>
+
+/**
+ * Generates a table which associates each activation mapping of
+ * a manifest to a list of its inter-dependencies
+ *
+ * @param activation_array
+ * @return Generated edges table
+ */
+GHashTable *generate_edges_table(GArray *activation_array);
+
+/**
+ * Removes an edges table including all its contents from memory.
+ *
+ * @param edges_table Edges table to remove
+ */
+void destroy_edges_table(GHashTable *edges_table);
+
+#endif
Modified: disnix/disnix/trunk/src/visualize/main.c
==============================================================================
--- disnix/disnix/trunk/src/visualize/main.c Tue Sep 14 12:15:06 2010
(r23784)
+++ disnix/disnix/trunk/src/visualize/main.c Tue Sep 14 12:25:27 2010
(r23785)
@@ -1,8 +1,29 @@
+/*
+ * Disnix - A distributed application layer for Nix
+ * Copyright (C) 2008-2010 Sander van der Burg
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
USA
+ */
+
#include <stdio.h>
#define _GNU_SOURCE
#include <getopt.h>
#include <activationmapping.h>
#include <glib.h>
+#include "clustertable.h"
+#include "edgestable.h"
static void print_usage()
{
@@ -11,128 +32,21 @@
fprintf(stderr, "disnix-visualize {-h | --help}\n");
}
-static GHashTable *generate_cluster_table(GArray *activation_array)
-{
- GHashTable *cluster_table = g_hash_table_new(g_str_hash, g_str_equal);
- unsigned int i;
-
- for(i = 0; i < activation_array->len; i++)
- {
- ActivationMapping *mapping = g_array_index(activation_array,
ActivationMapping*, i);
- gchar *target = get_target_interface(mapping);
- GArray *services_array = g_hash_table_lookup(cluster_table, target);
-
- if(services_array == NULL)
- {
- services_array = g_array_new(FALSE, FALSE, sizeof(gchar*));
- g_hash_table_insert(cluster_table, target, services_array);
- }
-
- g_array_append_val(services_array, mapping->service);
- }
-
- return cluster_table;
-}
-
-static void destroy_cluster_table(GHashTable *cluster_table)
-{
- GHashTableIter iter;
- gpointer *key;
- gpointer *value;
-
- g_hash_table_iter_init(&iter, cluster_table);
- while(g_hash_table_iter_next(&iter, (gpointer*)&key, (gpointer*)&value))
- {
- GArray *services_array = (GArray*)value;
- g_array_free(services_array, TRUE);
- }
-
- g_hash_table_destroy(cluster_table);
-}
-
-static GHashTable *generate_edges_table(GArray *activation_array)
-{
- GHashTable *edges_table = g_hash_table_new(g_str_hash, g_str_equal);
- unsigned int i;
-
- for(i = 0; i < activation_array->len; i++)
- {
- ActivationMapping *mapping = g_array_index(activation_array,
ActivationMapping*, i);
- gchar *target = get_target_interface(mapping);
- gchar *mapping_key = g_strconcat(mapping->service, ":", target, NULL);
- GArray *dependency_array = g_hash_table_lookup(edges_table,
mapping_key);
-
- if(dependency_array == NULL)
- {
- unsigned int j;
- GArray *depends_on = mapping->depends_on;
-
- dependency_array = g_array_new(FALSE, FALSE, sizeof(gchar*));
-
- for(j = 0; j < depends_on->len; j++)
- {
- Dependency *dependency = g_array_index(depends_on, Dependency*,
j);
- ActivationMapping lookup;
- ActivationMapping *actual_mapping;
- gchar *mapping_value, *target;
- int actual_mapping_index;
-
- /* Find the activation mapping in the activation array */
- lookup.service = dependency->service;
- lookup.target = dependency->target;
- actual_mapping_index =
activation_mapping_index(activation_array, &lookup);
-
- /* Retrieve the actual mapping */
- actual_mapping = g_array_index(activation_array,
ActivationMapping*, actual_mapping_index);
-
- /* Get the target interface */
- target = get_target_interface(actual_mapping);
-
- /* Generate mapping value from the service and target property
*/
- mapping_value = g_strconcat(actual_mapping->service, ":",
target, NULL);
-
- g_array_append_val(dependency_array, mapping_value);
- }
-
- g_hash_table_insert(edges_table, mapping_key, dependency_array);
- }
- }
-
-
- return edges_table;
-}
-
-static void destroy_edges_table(GHashTable *edges_table)
-{
- GHashTableIter iter;
- gpointer *key;
- gpointer *value;
-
- g_hash_table_iter_init(&iter, edges_table);
- while(g_hash_table_iter_next(&iter, (gpointer*)&key, (gpointer*)&value))
- {
- gchar *mapping_key = (gchar*)key;
- GArray *dependency_array = (GArray*)value;
- unsigned int i;
-
- for(i = 0; i < dependency_array->len; i++)
- {
- gchar *dep = g_array_index(dependency_array, gchar*, i);
- g_free(dep);
- }
-
- g_array_free(dependency_array, TRUE);
- g_free(mapping_key);
- }
-
- g_hash_table_destroy(edges_table);
-}
-
+/**
+ * Prints a clustered graph in dot format from a manifest file to
+ * the standard output.
+ *
+ * @param manifest_file Manifest file to visualize
+ */
static void generate_graph(char *manifest_file)
{
+ /* Creates an array with activation items from the manifest */
GArray *activation_array = create_activation_array(manifest_file);
+ /* Creates a table which maps each target onto a list of mappings */
GHashTable *cluster_table = generate_cluster_table(activation_array);
+
+ /* Creates a table which associates each mapping to its dependencies */
GHashTable *edges_table = generate_edges_table(activation_array);
GHashTableIter iter;
@@ -142,7 +56,7 @@
g_print("digraph G {\n");
- /* Generate clusters with nodes */
+ /* Generate clusters with nodes from the cluster table */
g_hash_table_iter_init(&iter, cluster_table);
while(g_hash_table_iter_next(&iter, (gpointer*)&key, (gpointer*)&value))
@@ -167,7 +81,7 @@
count++;
}
- /* Generate edges */
+ /* Generate edges from the edges table */
g_hash_table_iter_init(&iter, edges_table);
while(g_hash_table_iter_next(&iter, (gpointer*)&key, (gpointer*)&value))
@@ -184,6 +98,7 @@
g_print("}\n");
+ /* Cleanup */
destroy_cluster_table(cluster_table);
destroy_edges_table(edges_table);
delete_activation_array(activation_array);
_______________________________________________
nix-commits mailing list
[email protected]
http://mail.cs.uu.nl/mailman/listinfo/nix-commits