Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
a little program to help determining which memory chunk were modified during model...
authorMartin Quinson <martin.quinson@loria.fr>
Mon, 2 Apr 2012 02:25:37 +0000 (16:25 -1000)
committerMartin Quinson <martin.quinson@loria.fr>
Mon, 2 Apr 2012 02:25:37 +0000 (16:25 -1000)
tools/gras/CMakeLists.txt
tools/gras/s_smx_process_t [new file with mode: 0644]
tools/gras/s_smx_simcall_t [new file with mode: 0644]
tools/gras/struct_diff.c [new file with mode: 0644]

index 632026f..8a5f391 100644 (file)
@@ -3,10 +3,13 @@ cmake_minimum_required(VERSION 2.6)
 set(EXECUTABLE_OUTPUT_PATH "${CMAKE_BINARY_DIR}/bin")
 
 add_executable(gras_stub_generator stub_generator.c unix_stub_generator.c windows_stub_generator.c)
+add_executable(struct_diff struct_diff.c)
 
 ### Add definitions for compile
 if(NOT WIN32)
     target_link_libraries(gras_stub_generator simgrid pthread m)
+    target_link_libraries(struct_diff         simgrid pthread m)
 else(NOT WIN32)
     target_link_libraries(gras_stub_generator simgrid)
+    target_link_libraries(struct_diff         simgrid)
 endif(NOT WIN32)
\ No newline at end of file
diff --git a/tools/gras/s_smx_process_t b/tools/gras/s_smx_process_t
new file mode 100644 (file)
index 0000000..a3526ed
--- /dev/null
@@ -0,0 +1,21 @@
+struct s_smx_process_t {
+  s_xbt_swag_hookup_t process_hookup;
+  s_xbt_swag_hookup_t synchro_hookup;
+  s_xbt_swag_hookup_t host_proc_hookup;
+  s_xbt_swag_hookup_t destroy_hookup;
+
+  unsigned long pid;
+  char *name                XBT_ANNOTE(size,1);
+  smx_host_t smx_host;          
+  smx_context_t context;        
+  xbt_running_ctx_t *running_ctx XBT_ANNOTE(size,1);
+  short int FLAGS;
+  smx_host_t new_host;          
+  smx_action_t waiting_action;  
+  xbt_fifo_t comms;       
+  xbt_dict_t properties;
+  s_smx_simcall_t simcall;
+  
+
+} s_smx_process_t;
+
diff --git a/tools/gras/s_smx_simcall_t b/tools/gras/s_smx_simcall_t
new file mode 100644 (file)
index 0000000..28ae88f
--- /dev/null
@@ -0,0 +1,424 @@
+typedef struct s_smx_simcall {
+  e_smx_simcall_t call;
+  smx_process_t issuer;
+
+  union {
+
+    struct {
+      const char *name;
+      smx_host_t result;
+    } host_get_by_name;
+
+    struct {
+      smx_host_t host;
+      const char* result;
+    } host_get_name;
+
+    struct {
+      smx_host_t host;
+      xbt_dict_t result;
+    } host_get_properties;
+
+    struct {
+      smx_host_t host;
+      double result;
+    } host_get_speed;
+
+    struct {
+      smx_host_t host;
+      double result;
+    } host_get_available_speed;
+
+    struct {
+      smx_host_t host;
+      int result;
+    } host_get_state;
+
+    struct {
+      smx_host_t host;
+      void* result;
+    } host_get_data;
+
+    struct {
+      smx_host_t host;
+      void* data;
+    } host_set_data;
+
+    struct {
+      const char* name;
+      smx_host_t host;
+      double computation_amount;
+      double priority;
+      smx_action_t result;
+    } host_execute;
+
+    struct {
+      const char *name;
+      int host_nb;
+      smx_host_t *host_list;
+      double *computation_amount;
+      double *communication_amount;
+      double amount;
+      double rate;
+      smx_action_t result;
+    } host_parallel_execute;
+
+    struct {
+      smx_action_t execution;
+    } host_execution_destroy;
+
+    struct {
+      smx_action_t execution;
+    } host_execution_cancel;
+
+    struct {
+      smx_action_t execution;
+      double result;
+    } host_execution_get_remains;
+
+    struct {
+      smx_action_t execution;
+      e_smx_state_t result;
+    } host_execution_get_state;
+
+    struct {
+      smx_action_t execution;
+      double priority;
+    } host_execution_set_priority;
+
+    struct {
+      smx_action_t execution;
+      e_smx_state_t result;
+    } host_execution_wait;
+
+    struct {
+      smx_process_t *process;
+      const char *name;
+      xbt_main_func_t code;
+      void *data;
+      const char *hostname;
+      int argc;
+      char **argv;
+      xbt_dict_t properties;
+    } process_create;
+
+    struct {
+      smx_process_t process;
+    } process_kill;
+
+    struct {
+      smx_process_t process;
+    } process_cleanup;
+
+    struct {
+      smx_process_t process;
+      smx_host_t dest;
+    } process_change_host;
+
+    struct {
+      smx_process_t process;
+    } process_suspend;
+
+    struct {
+      smx_process_t process;
+    } process_resume;
+
+    struct {
+      int result;
+    } process_count;
+
+    struct {
+      smx_process_t process;
+      void* result;
+    } process_get_data;
+
+    struct {
+      smx_process_t process;
+      void* data;
+    } process_set_data;
+
+    struct {
+      smx_process_t process;
+      smx_host_t result;
+    } process_get_host;
+
+    struct {
+      smx_process_t process;
+      const char *result;
+    } process_get_name;
+
+    struct {
+      smx_process_t process;
+      int result;
+    } process_is_suspended;
+
+    struct {
+      smx_process_t process;
+      xbt_dict_t result;
+    } process_get_properties;
+
+    struct {
+      double duration;
+      e_smx_state_t result;
+    } process_sleep;
+
+    struct {
+      const char *name;
+      smx_rdv_t result;
+    } rdv_create;
+
+    struct {
+      smx_rdv_t rdv;
+    } rdv_destroy;
+
+    struct {
+      const char* name;
+      smx_rdv_t result;
+    } rdv_get_by_name;
+
+    struct {
+      smx_rdv_t rdv;
+      smx_host_t host;
+      unsigned int result;
+    } rdv_comm_count_by_host;
+
+    struct {
+      smx_rdv_t rdv;
+      smx_action_t result;
+    } rdv_get_head;
+
+    struct {
+      smx_rdv_t rdv;
+      double task_size;
+      double rate;
+      void *src_buff;
+      size_t src_buff_size;
+      int (*match_fun)(void *, void *);
+      void *data;
+      double timeout;
+    } comm_send;
+
+    struct {
+      smx_rdv_t rdv;
+      double task_size;
+      double rate;
+      void *src_buff;
+      size_t src_buff_size;
+      int (*match_fun)(void *, void *);
+      void (*clean_fun)(void *);
+      void *data;
+      int detached;
+      smx_action_t result;
+    } comm_isend;
+
+    struct {
+      smx_rdv_t rdv;
+      void *dst_buff;
+      size_t *dst_buff_size;
+      int (*match_fun)(void *, void *);
+      void *data;
+      double timeout;
+    } comm_recv;
+
+    struct {
+      smx_rdv_t rdv;
+      void *dst_buff;
+      size_t *dst_buff_size;
+      int (*match_fun)(void *, void *);
+          void *data;
+      smx_action_t result;
+    } comm_irecv;
+
+    struct {
+      smx_action_t comm;
+    } comm_destroy;
+
+    struct {
+      smx_action_t comm;
+    } comm_cancel;
+
+    struct {
+      xbt_dynar_t comms;
+      unsigned int result;
+    } comm_waitany;
+
+    struct {
+      smx_action_t comm;
+      double timeout;
+    } comm_wait;
+
+    struct {
+      smx_action_t comm;
+      int result;
+    } comm_test;
+
+    struct {
+      xbt_dynar_t comms;
+      int result;
+    } comm_testany;
+
+    struct {
+      smx_action_t comm;
+      double result;
+    } comm_get_remains;
+
+    struct {
+      smx_action_t comm;
+      e_smx_state_t result;
+    } comm_get_state;
+
+    struct {
+      smx_action_t comm;
+      void *result;
+    } comm_get_src_data;
+
+    struct {
+      smx_action_t comm;
+      void *result;
+    } comm_get_dst_data;
+
+    struct {
+      smx_action_t comm;
+      smx_process_t result;
+    } comm_get_src_proc;
+
+    struct {
+      smx_action_t comm;
+      smx_process_t result;
+    } comm_get_dst_proc;
+
+    struct {
+      smx_action_t comm;
+      int result;
+    } comm_is_latency_bounded;
+
+    struct {
+      smx_action_t action;
+      const char *category;
+    } set_category;
+
+    struct {
+      smx_mutex_t result;
+    } mutex_init;
+
+    struct {
+      smx_mutex_t mutex;
+    } mutex_lock;
+
+    struct {
+      smx_mutex_t mutex;
+      int result;
+    } mutex_trylock;
+
+    struct {
+      smx_mutex_t mutex;
+    } mutex_unlock;
+
+    struct {
+      smx_mutex_t mutex;
+    } mutex_destroy;
+
+    struct {
+      smx_cond_t result;
+    } cond_init;
+
+    struct {
+      smx_cond_t cond;
+    } cond_destroy;
+
+    struct {
+      smx_cond_t cond;
+    } cond_signal;
+
+    struct {
+      smx_cond_t cond;
+      smx_mutex_t mutex;
+    } cond_wait;
+
+    struct {
+      smx_cond_t cond;
+      smx_mutex_t mutex;
+      double timeout;
+    } cond_wait_timeout;
+
+    struct {
+      smx_cond_t cond;
+    } cond_broadcast;
+
+    struct {
+      int capacity;
+      smx_sem_t result;
+    } sem_init;
+
+    struct {
+      smx_sem_t sem;
+    } sem_destroy;
+
+    struct {
+      smx_sem_t sem;
+    } sem_release;
+
+    struct {
+      smx_sem_t sem;
+      int result;
+    } sem_would_block;
+
+    struct {
+      smx_sem_t sem;
+    } sem_acquire;
+
+    struct {
+      smx_sem_t sem;
+      double timeout;
+    } sem_acquire_timeout;
+
+    struct {
+      smx_sem_t sem;
+      int result;
+    } sem_get_capacity;
+
+    struct {
+      const char* storage;
+      void *ptr;
+      size_t size;
+      size_t nmemb;
+      m_file_t stream;
+      size_t result;
+    } file_read;
+
+    struct {
+      const char* storage;
+      const void *ptr;
+      size_t size;
+      size_t nmemb;
+      m_file_t stream;
+      size_t result;
+    } file_write;
+
+    struct {
+      const char* storage;
+      const char* path;
+      const char* mode;
+      m_file_t result;
+    } file_open;
+
+    struct {
+      const char* storage;
+      m_file_t fp;
+      int result;
+    } file_close;
+
+    struct {
+      const char* storage;
+      int fd;
+      //Next should be struct stat* buf
+      void* buf;
+      int result;
+    } file_stat;
+
+  };
+} s_smx_simcall_t, *smx_simcall_t;
+
+
+
+
diff --git a/tools/gras/struct_diff.c b/tools/gras/struct_diff.c
new file mode 100644 (file)
index 0000000..4de4567
--- /dev/null
@@ -0,0 +1,161 @@
+/* struct_diff -- little tool to see which structure's field are modified on mc_diff */
+
+/* Copyright (c) 2012. The SimGrid Team. All rights reserved.               */
+
+/* This program is free software; you can redistribute it and/or modify it
+ * under the terms of the license (GNU LGPL) which comes with this package. */
+
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+#include "xbt.h"
+#include "xbt/datadesc.h"
+#include "../../src/xbt/datadesc/datadesc_private.h" // RAAAAH! ugly relative path, but it's late, I want it to be done NOW.
+#include "simix/datatypes.h"
+#include "../../src/simix/smx_smurf_private.h" // RAAAAH! ugly relative path, but it's even later and it still doesn't work
+
+static void define_types(void) {
+  xbt_datadesc_type_t desc;
+
+  /* typedef struct xbt_swag_hookup {
+   *    void *next;
+   *    void *prev;
+   *  } s_xbt_swag_hookup_t; */
+  desc = xbt_datadesc_struct("s_xbt_swag_hookup_t");
+  xbt_datadesc_struct_append(desc,"next",xbt_datadesc_by_name("data pointer"));
+  xbt_datadesc_struct_append(desc,"prev",xbt_datadesc_by_name("data pointer"));
+  xbt_datadesc_struct_close(desc);
+
+  /* FIXME: maybe we should provide the internal details */
+  xbt_datadesc_copy("smx_host_t",xbt_datadesc_by_name("data pointer"));
+  xbt_datadesc_copy("smx_context_t",xbt_datadesc_by_name("data pointer"));
+  xbt_datadesc_copy("smx_action_t",xbt_datadesc_by_name("data pointer"));
+  xbt_datadesc_copy("xbt_dict_t",xbt_datadesc_by_name("data pointer"));
+  xbt_datadesc_copy("xbt_fifo_t",xbt_datadesc_by_name("data pointer"));
+  xbt_datadesc_copy("smx_process_t",xbt_datadesc_by_name("data pointer"));
+
+  /* typedef struct {
+   *   char *msg;
+   *   xbt_errcat_t category;
+
+   *   int value;
+   *   short int remote;
+   *   char *host;
+   *   char *procname;
+   *
+   *   int pid;
+   *   char *file;
+   *   int line;
+   *   char *func;
+
+   *   int used;
+   *   char **bt_strings;
+   *   void *bt[XBT_BACKTRACE_SIZE];
+   * } xbt_ex_t;   */
+  desc = xbt_datadesc_struct("xbt_ex_t");
+  xbt_datadesc_struct_append(desc,"msg",xbt_datadesc_by_name("string"));
+
+  xbt_assert(sizeof(xbt_errcat_t)==sizeof(int),
+      "I was assuming that xbt_errcat_t is of the same size than integer, but it's not true: it's %zu (int:%zu)\n",
+      sizeof(xbt_errcat_t),sizeof(int));
+  xbt_datadesc_struct_append(desc,"category",xbt_datadesc_by_name("short int"));
+
+  xbt_datadesc_struct_append(desc,"value",xbt_datadesc_by_name("short int"));
+  xbt_datadesc_struct_append(desc,"remote",xbt_datadesc_by_name("short int"));
+  xbt_datadesc_struct_append(desc,"host",xbt_datadesc_by_name("string"));
+  xbt_datadesc_struct_append(desc,"procname",xbt_datadesc_by_name("string"));
+  xbt_datadesc_struct_append(desc,"pid",xbt_datadesc_by_name("int"));
+  xbt_datadesc_struct_append(desc,"file",xbt_datadesc_by_name("string"));
+  xbt_datadesc_struct_append(desc,"line",xbt_datadesc_by_name("int"));
+  xbt_datadesc_struct_append(desc,"func",xbt_datadesc_by_name("string"));
+  xbt_datadesc_struct_append(desc,"used",xbt_datadesc_by_name("int"));
+  xbt_datadesc_struct_append(desc,"bt_strings",xbt_datadesc_by_name("data pointer"));
+  xbt_datadesc_struct_append(desc,"bt",xbt_datadesc_array_fixed("xbt_bt",xbt_datadesc_by_name("data pointer"),XBT_BACKTRACE_SIZE));
+  xbt_datadesc_struct_close(desc);
+
+  /* typedef struct {
+   *   __ex_mctx_t *ctx_mctx;
+   *   volatile int ctx_caught;
+   *   volatile xbt_ex_t exception;
+   * } xbt_running_ctx_t;   */
+  desc = xbt_datadesc_struct("xbt_running_ctx_t");
+  xbt_datadesc_struct_append(desc,"ctx_mctx",xbt_datadesc_by_name("data pointer"));
+  xbt_datadesc_struct_append(desc,"ctx_caught",xbt_datadesc_by_name("int"));
+  xbt_datadesc_struct_append(desc,"exception",xbt_datadesc_by_name("int"));
+  xbt_datadesc_struct_close(desc);
+
+  xbt_assert(sizeof(e_smx_simcall_t)==sizeof(int),
+      "I was assuming that e_smx_simcall_t is of the same size than integer, but it's not true: it's %zu (int:%zu)\n",
+      sizeof(e_smx_simcall_t),sizeof(int));
+  xbt_datadesc_copy("e_smx_simcall_t", xbt_datadesc_by_name("int"));
+}
+
+static void parse_from_file(const char *name){
+  int in=open(name,O_RDONLY);
+  if (in==-1){
+    fprintf(stderr,"Cannot read structure file from %s: %s\n",name,strerror(errno));
+    exit(1);
+  }
+
+  xbt_strbuff_t strbuff = xbt_strbuff_new();
+  int r;
+  do {
+    char buffer[1024];
+    r = read(in,&buffer,1023);
+    buffer[r] = '\0';
+    xbt_strbuff_append(strbuff,buffer);
+  } while (r!=0);
+
+  printf("File %s content:\n%s\n",name,strbuff->data);
+  xbt_datadesc_parse(name,strbuff->data);
+
+}
+
+int main(int argc, char** argv) {
+  xbt_init(&argc, argv);
+  define_types();
+
+  if (argc<3) {
+    fprintf(stderr,"Usage: %s struct-file offset1 offset2 ...\n",argv[0]);
+    exit(1);
+  }
+
+  parse_from_file("s_smx_simcall_t");
+  parse_from_file(argv[1]);
+
+  int cpt;
+  xbt_datadesc_type_t type = xbt_datadesc_by_name(argv[1]);
+  for (cpt=2;cpt<argc;cpt++) {
+    int offset = atoi(argv[cpt]);
+    unsigned int cursor;
+    xbt_dd_cat_field_t field;
+    int found = 0;
+
+    printf ("Offset: %d in struct %s (there is %lu fields)\n",
+        offset, type->name, xbt_dynar_length(type->category.struct_data.fields));
+    xbt_dynar_foreach(type->category.struct_data.fields,cursor,field) {
+      if (field->offset[GRAS_THISARCH]<= offset&&
+          field->offset[GRAS_THISARCH]+field->type->size[GRAS_THISARCH] >= offset) {
+        found = 1;
+        printf("This offset is somewhere in field %s, which starts at offset %zu and is of size %zu\n",
+              field->name,field->offset[GRAS_THISARCH],field->type->size[GRAS_THISARCH]);
+
+      }
+    }
+    if (!found) {
+
+      printf("Damnit, the structure is too short to find the the field (last field %s was at offset %zu, with size %zu). Weird.\n",
+          field->name,field->offset[GRAS_THISARCH],field->type->size[GRAS_THISARCH]);
+    }
+  }
+  return 0;
+}
+
+
+