xml 1.0
[lttv.git] / genevent-new / genevent.c
index 124168d27efc51baeb7d12ef3d2e1ee7a96f6858..7408b7e519beaba19c2d155bd1223cba6e81ac62 100644 (file)
 #define dprintf(...)
 #endif
 
-void preset_field_type_size(event_t *event_type,
-    off_t offset_root, off_t offset_parent,
-    enum field_status *fixed_root, enum field_status *fixed_parent,
-    field_t *field);
-
 /* Code printing */
 
 void print_tabs(unsigned int tabs, FILE *fd)
@@ -99,11 +94,6 @@ void print_tabs(unsigned int tabs, FILE *fd)
                fprintf(fd, "\t");
 }
 
-/* Type size checking */
-/* Uses #error in the generated code to signal error and stop the compiler */
-int print_check(int fd);
-
-
 /* print type.
  *
  * Copied from construct_types_and_fields in LTTV facility.c */
@@ -161,7 +151,7 @@ int print_type(type_descriptor_t * td, FILE *fd, unsigned int tabs,
                        fprintf(fd, "%s", floatOutputTypes[getSizeindex(td->size)]);
                        break;
                case POINTER:
-                       fprintf(fd, "void *");
+                       fprintf(fd, "const void *");
                        break;
                case LONG:
                        fprintf(fd, "long");
@@ -179,7 +169,7 @@ int print_type(type_descriptor_t * td, FILE *fd, unsigned int tabs,
                        fprintf(fd, "off_t");
                        break;
                case STRING:
-                       fprintf(fd, "char *");
+                       fprintf(fd, "const char *");
                        break;
                case ENUM:
                        fprintf(fd, "enum lttng_%s", basename);
@@ -234,87 +224,87 @@ int print_arg(type_descriptor_t * td, FILE *fd, unsigned int tabs,
        switch(td->type) {
                case INT_FIXED:
                        fprintf(fd, "%s", intOutputTypes[getSizeindex(td->size)]);
-                       fprintf(fd, " %s", field_name);
+                       fprintf(fd, "lttng_param_%s", field_name);
                        break;
                case UINT_FIXED:
                        fprintf(fd, "%s", uintOutputTypes[getSizeindex(td->size)]);
-                       fprintf(fd, " %s", field_name);
+                       fprintf(fd, "lttng_param_%s", field_name);
                        break;
                case CHAR:
                        fprintf(fd, "signed char");
-                       fprintf(fd, " %s", field_name);
+                       fprintf(fd, " lttng_param_%s", field_name);
                        break;
                case UCHAR:
                        fprintf(fd, "unsigned char");
-                       fprintf(fd, " %s", field_name);
+                       fprintf(fd, " lttng_param_%s", field_name);
                        break;
                case SHORT:
                        fprintf(fd, "short");
-                       fprintf(fd, " %s", field_name);
+                       fprintf(fd, " lttng_param_%s", field_name);
                        break;
                case USHORT:
                        fprintf(fd, "unsigned short");
-                       fprintf(fd, " %s", field_name);
+                       fprintf(fd, " lttng_param_%s", field_name);
                        break;
                case INT:
                        fprintf(fd, "int");
-                       fprintf(fd, " %s", field_name);
+                       fprintf(fd, " lttng_param_%s", field_name);
                        break;
                case UINT:
                        fprintf(fd, "unsigned int");
-                       fprintf(fd, " %s", field_name);
+                       fprintf(fd, " lttng_param_%s", field_name);
                        break;
                case FLOAT:
                        fprintf(fd, "%s", floatOutputTypes[getSizeindex(td->size)]);
-                       fprintf(fd, " %s", field_name);
+                       fprintf(fd, " lttng_param_%s", field_name);
                        break;
                case POINTER:
-                       fprintf(fd, "void *");
-                       fprintf(fd, " %s", field_name);
+                       fprintf(fd, "const void *");
+                       fprintf(fd, " lttng_param_%s", field_name);
                        break;
                case LONG:
                        fprintf(fd, "long");
-                       fprintf(fd, " %s", field_name);
+                       fprintf(fd, " lttng_param_%s", field_name);
                        break;
                case ULONG:
                        fprintf(fd, "unsigned long");
-                       fprintf(fd, " %s", field_name);
+                       fprintf(fd, " lttng_param_%s", field_name);
                        break;
                case SIZE_T:
                        fprintf(fd, "size_t");
-                       fprintf(fd, " %s", field_name);
+                       fprintf(fd, " lttng_param_%s", field_name);
                        break;
                case SSIZE_T:
                        fprintf(fd, "ssize_t");
-                       fprintf(fd, " %s", field_name);
+                       fprintf(fd, " lttng_param_%s", field_name);
                        break;
                case OFF_T:
                        fprintf(fd, "off_t");
-                       fprintf(fd, " %s", field_name);
+                       fprintf(fd, " lttng_param_%s", field_name);
                        break;
                case STRING:
-                       fprintf(fd, "char *");
-                       fprintf(fd, " %s", field_name);
+                       fprintf(fd, "const char *");
+                       fprintf(fd, " lttng_param_%s", field_name);
                        break;
                case ENUM:
                        fprintf(fd, "enum lttng_%s", basename);
-                       fprintf(fd, " %s", field_name);
+                       fprintf(fd, " lttng_param_%s", field_name);
                        break;
                case ARRAY:
                        fprintf(fd, "lttng_array_%s", basename);
-                       fprintf(fd, " %s", field_name);
+                       fprintf(fd, " lttng_param_%s", field_name);
                        break;
                case SEQUENCE:
                        fprintf(fd, "lttng_sequence_%s *", basename);
-                       fprintf(fd, " %s", field_name);
+                       fprintf(fd, " lttng_param_%s", field_name);
                        break;
        case STRUCT:
                        fprintf(fd, "struct lttng_%s *", basename);
-                       fprintf(fd, " %s", field_name);
+                       fprintf(fd, " lttng_param_%s", field_name);
                        break;
        case UNION:
                        fprintf(fd, "union lttng_%s *", basename);
-                       fprintf(fd, " %s", field_name);
+                       fprintf(fd, " lttng_param_%s", field_name);
                        break;
        default:
                        printf("print_type : unknown type\n");
@@ -325,6 +315,67 @@ int print_arg(type_descriptor_t * td, FILE *fd, unsigned int tabs,
 }
 
 
+/* Does the type has a fixed size ? (as know from the compiler)
+ *
+ * 1 : fixed size
+ * 0 : variable length
+ */
+int has_type_fixed_size(type_descriptor_t *td)
+{
+       switch(td->type) {
+               case INT_FIXED:
+               case UINT_FIXED:
+               case CHAR:
+               case UCHAR:
+               case SHORT:
+               case USHORT:
+               case INT:
+               case UINT:
+               case FLOAT:
+               case POINTER:
+               case LONG:
+               case ULONG:
+               case SIZE_T:
+               case SSIZE_T:
+               case OFF_T:
+               case ENUM:
+               case UNION: /* The union must have fixed size children. Must be checked by
+                                                                        the parser */
+                       return 1;
+                       break;
+               case STRING:
+               case SEQUENCE:
+                       return 0;
+                       break;
+               case STRUCT:
+                       {
+                               int has_type_fixed = 0;
+                               for(unsigned int i=0;i<td->fields.position;i++){
+                                       field_t *field = (field_t*)(td->fields.array[i]);
+                                       type_descriptor_t *type = field->type;
+                                       
+                                       has_type_fixed = has_type_fixed_size(type);
+                                       if(!has_type_fixed) return 0;
+                               }
+                               return 1;
+                       }
+                       break;
+               case ARRAY:
+                       assert(td->size >= 0);
+                       return has_type_fixed_size(((field_t*)td->fields.array[0])->type);
+                       break;
+               case NONE:
+                       printf("There is a type defined to NONE : bad.\n");
+                       assert(0);
+                       break;
+       }
+       return 0; //make gcc happy.
+}
+
+
+
+
+
 /* print type declaration.
  *
  * Copied from construct_types_and_fields in LTTV facility.c */
@@ -335,6 +386,8 @@ int print_type_declaration(type_descriptor_t * td, FILE *fd, unsigned int tabs,
        char basename[PATH_MAX];
        unsigned int basename_len = 0;
        
+       if(td->custom_write) return 0;  /* Does print custom type */
+       
        strncpy(basename, nest_name, PATH_MAX);
        basename_len = strlen(basename);
        
@@ -360,7 +413,8 @@ int print_type_declaration(type_descriptor_t * td, FILE *fd, unsigned int tabs,
                        fprintf(fd, " {\n");
                        for(unsigned int i=0;i<td->labels.position;i++){
                                print_tabs(1, fd);
-                               fprintf(fd, "LTTNG_%s", ((char*)(td->labels.array[i])));
+                               fprintf(fd, "LTTNG_%s = %d", ((char*)td->labels.array[i]),
+            (*(int*)td->labels_values.array[i]));
                                fprintf(fd, ",\n");
                        }
                        fprintf(fd, "};\n");
@@ -375,7 +429,7 @@ int print_type_declaration(type_descriptor_t * td, FILE *fd, unsigned int tabs,
                                if(print_type_declaration(((field_t*)td->fields.array[0])->type,
                                                                                                                                        fd,     0, basename, "")) return 1;
                        }
-                       fprintf(fd, "#define LTTNG_ARRAY_SIZE_%s %llu\n", basename,
+                       fprintf(fd, "#define LTTNG_ARRAY_SIZE_%s %zu\n", basename,
                                        td->size);
                        fprintf(fd, "typedef ");
                        if(print_type(((field_t*)td->fields.array[0])->type,
@@ -398,12 +452,16 @@ int print_type_declaration(type_descriptor_t * td, FILE *fd, unsigned int tabs,
                        fprintf(fd, "struct lttng_sequence_%s", basename);
                        fprintf(fd, " {\n");
                        print_tabs(1, fd);
-                       fprintf(fd, "unsigned int len;\n");
+                       if(print_type(((field_t*)td->fields.array[0])->type,
+                                               fd, tabs, basename, "")) return 1;
+                       fprintf(fd, " len;\n");
                        print_tabs(1, fd);
+                       fprintf(fd, "const ");
                        if(print_type(((field_t*)td->fields.array[1])->type,
                                                fd, tabs, basename, "")) return 1;
                        fprintf(fd, " *array;\n");
-                       fprintf(fd, "};\n");
+                       fprintf(fd, "};\n");    /* We do not LTT_ALIGN, because we never copy
+                                                                                                                        it to the buffer directly. */
                        fprintf(fd, "\n");
                break;
 
@@ -428,11 +486,10 @@ int print_type_declaration(type_descriptor_t * td, FILE *fd, unsigned int tabs,
                                fprintf(fd, "%s", field->name);
                                fprintf(fd, ";\n");
                        }
-                       fprintf(fd, "};\n");
+                       fprintf(fd, "} LTT_ALIGN;\n");
                        fprintf(fd, "\n");
                        break;
        case UNION:
-                       /* TODO : Do not allow variable length fields in a union */
                        for(unsigned int i=0;i<td->fields.position;i++){
                                field_t *field = (field_t*)(td->fields.array[i]);
                                type_descriptor_t *type = field->type;
@@ -453,7 +510,7 @@ int print_type_declaration(type_descriptor_t * td, FILE *fd, unsigned int tabs,
                                fprintf(fd, "%s", field->name);
                                fprintf(fd, ";\n");
                        }
-                       fprintf(fd, "};\n");
+                       fprintf(fd, "} LTT_ALIGN;\n");
                        fprintf(fd, "\n");
                        break;
        default:
@@ -465,358 +522,155 @@ int print_type_declaration(type_descriptor_t * td, FILE *fd, unsigned int tabs,
 }
 
 
+/* print type alignment.
+ *
+ * Copied from construct_types_and_fields in LTTV facility.c
+ *
+ * basename is the name which identifies the type (along with a prefix
+ * (possibly)). */
 
-
-
-/*****************************************************************************
- *Function name
- *    set_named_type_offsets : set the precomputable offset of the named type
- *Input params 
- *    type : the type
- ****************************************************************************/
-void set_named_type_offsets(type_descriptor_t *type)
+int print_type_alignment(type_descriptor_t * td, FILE *fd, unsigned int tabs,
+               char *nest_name, char *field_name, char *obj_prefix)
 {
-  enum field_status    current_child_status = FIELD_FIXED_GENEVENT;
-       off_t current_offset = 0;
-
-       preset_type_size(
-                       current_offset,
-                       &current_child_status,
-                       type);
-       if(current_child_status == FIELD_FIXED_GENEVENT) {
-               current_offset += type->size;
+       char basename[PATH_MAX];
+       unsigned int basename_len = 0;
+       
+       strncpy(basename, nest_name, PATH_MAX);
+       basename_len = strlen(basename);
+       
+       /* For a named type, we use the type_name directly */
+       if(td->type_name != NULL) {
+               strncpy(basename, td->type_name, PATH_MAX);
+               basename_len = strlen(basename);
        } else {
-               current_offset = 0;
+               /* For a unnamed type, there must be a field name, except for
+                * the array. */
+               if((basename_len != 0)
+                               && (basename[basename_len-1] != '_'
+                               && field_name != NULL
+                               && (field_name[0] != '\0'))) {
+                       strncat(basename, "_", PATH_MAX - basename_len);
+                       basename_len = strlen(basename);
+               }
+               if(field_name != NULL)
+                       strncat(basename, field_name, PATH_MAX - basename_len);
        }
-}
-
-
-/*****************************************************************************
- *Function name
- *    set_event_fields_offsets : set the precomputable offset of the fields
- *Input params 
- *    event           : the event
- ****************************************************************************/
-void set_event_fields_offsets(event_t *event)
-{
-  enum field_status current_child_status = FIELD_FIXED;
-       off_t current_offset = 0;
-
-       for(unsigned int i = 0; i < event->type->fields.position; i++) {
-               /* For each field, set the field offset. */
-               field_t *child_field = (field_t*)event->type->fields.array[i];
-               type_descriptor_t *t = f->type;
-               /* Skip named types */
-               if(t->type_name != NULL) continue;
-
-    preset_type_size(
-                               current_offset,
-        &current_child_status,
-        t);
-               if(current_child_status == FIELD_FIXED_GENEVENT) {
-                       current_offset += type->size;
-               } else {
-                       current_offset = 0;
+       
+       if(field_name[0] == '\0') {
+               /* We are in a write function : it's the obj that we must align. */
+               switch(td->type) {
+                       case SEQUENCE:
+                               fprintf(fd, "lttng_get_alignment_sequence_%s(%s)", basename,
+                                               obj_prefix);
+                               break;
+                       case STRUCT:
+                               fprintf(fd, "lttng_get_alignment_struct_%s(%s)", basename,
+                                               obj_prefix);
+                               break;
+                       case UNION:
+                               fprintf(fd, "lttng_get_alignment_union_%s(%s)", basename,
+                                               obj_prefix);
+                               break;
+                       case ARRAY:
+                               fprintf(fd, "lttng_get_alignment_array_%s(%s)", basename,
+                                               obj_prefix);
+                       case STRING:
+                               fprintf(fd, "sizeof(char)");
+                               break;
+                       case INT_FIXED:
+                       case UINT_FIXED:
+                       case CHAR:
+                       case UCHAR:
+                       case SHORT:
+                       case USHORT:
+                       case INT:
+                       case UINT:
+                       case FLOAT:
+                       case POINTER:
+                       case LONG:
+                       case ULONG:
+                       case SIZE_T:
+                       case SSIZE_T:
+                       case OFF_T:
+                       case ENUM:
+                               fprintf(fd, "sizeof(");
+                               if(print_type(td, fd, 0, basename, "")) return 1;
+                               fprintf(fd, ")");
+                               break;
+
+                       default:
+                               printf("error : type unexpected\n");
+                               return 1;
+                               break;
+               }
+       } else {
+               
+               switch(td->type) {
+                       case INT_FIXED:
+                       case UINT_FIXED:
+                       case CHAR:
+                       case UCHAR:
+                       case SHORT:
+                       case USHORT:
+                       case INT:
+                       case UINT:
+                       case FLOAT:
+                       case POINTER:
+                       case LONG:
+                       case ULONG:
+                       case SIZE_T:
+                       case SSIZE_T:
+                       case OFF_T:
+                       case ENUM:
+                               fprintf(fd, "sizeof(");
+                               if(print_type(td, fd, 0, basename, "")) return 1;
+                               fprintf(fd, ")");
+                               break;
+                       case STRING:
+                               fprintf(fd, "sizeof(char)");
+                               break;
+                       case SEQUENCE:
+                               fprintf(fd, "lttng_get_alignment_sequence_%s(&%s%s)", basename,
+                                               obj_prefix, field_name);
+                               break;
+                       case STRUCT:
+                               fprintf(fd, "lttng_get_alignment_struct_%s(&%s%s)", basename,
+                                               obj_prefix, field_name);
+                               break;
+                       case UNION:
+                               fprintf(fd, "lttng_get_alignment_union_%s(&%s%s)", basename,
+                                               obj_prefix, field_name);
+                               break;
+                       case ARRAY:
+                               fprintf(fd, "lttng_get_alignment_array_%s(%s%s)", basename,
+                                               obj_prefix, field_name);
+                               break;
+                       case NONE:
+                               printf("error : type NONE unexpected\n");
+                               return 1;
+                               break;
                }
        }
+       
+       return 0;
 }
 
-
-
-/*****************************************************************************
- *Function name
- *    print_type_size : print the fixed sizes of the field type
- *    taken from LTTV.
+/* print type write.
  *
- *    use offset_parent as offset to calculate alignment.
- *Input params 
- *    offset_parent   : offset from the parent
- *    fixed_parent    : Do we know a fixed offset to the parent ?
- *    type               : type
- ****************************************************************************/
-void print_type_size(
-    off_t offset_parent,
-    enum field_status *fixed_parent,
-    type_descriptor_t *type,
-               FILE *fd,
-               char *size_name)
-{
-  enum field_status local_fixed_parent;
-  guint i;
-  
-  g_assert(type->fixed_size == FIELD_UNKNOWN);
-
-  size_t current_offset;
-  enum field_status current_child_status, final_child_status;
-  size_t max_size;
-
-  switch(type->type) {
-                       /* type sizes known by genevent/compiler */
-               case INT_FIXED:
-               case UINT_FIXED:
-    case FLOAT:
-               case CHAR:
-               case UCHAR:
-               case SHORT:
-               case USHORT:
-                       /* Align */
-                       fprintf(fd, "%s += ltt_align(%s, %s)", size_name);
-                       /* Data */
-      type->fixed_size = FIELD_FIXED_GENEVENT;
-      break;
-                       /* host type sizes unknown by genevent, but known by the compiler */
-    case INT:
-    case UINT:
-    case ENUM:
-                       /* An enum is either : char or int. In gcc, always int. Hope
-                        * it's always like this. */
-                       type->fixed_size = FIELD_FIXED_COMPILER;
-                       type->compiler_size = COMPILER_INT;
-                       break;
-    case LONG:
-    case ULONG:
-                       type->fixed_size = FIELD_FIXED_COMPILER;
-                       type->compiler_size = COMPILER_LONG;
-                       break;
-    case POINTER:
-                       type->fixed_size = FIELD_FIXED_COMPILER;
-                       type->compiler_size = COMPILER_POINTER;
-                       break;
-    case SIZE_T:
-    case SSIZE_T:
-    case OFF_T:
-                       type->fixed_size = FIELD_FIXED_COMPILER;
-                       type->compiler_size = COMPILER_SIZE_T;
-                       break;
-                       /* compound types :
-                        * if all children has fixed size, then the parent size can be
-                        * known directly and the copy can be done efficiently.
-                        * if only part of the children has fixed size, then the contiguous
-                        * elements will be copied in one bulk, but the variable size elements
-                        * will be copied separately. This is necessary because those variable
-                        * size elements are referenced by pointer in C.
-                        */
-    case SEQUENCE:
-      current_offset = 0;
-      local_fixed_parent = FIELD_FIXED_GENEVENT;
-      preset_type_size(
-        0,
-        &local_fixed_parent,
-        ((field_t*)type->fields.array[0])->type);
-      preset_field_type_size(
-        0,
-        &local_fixed_parent,
-        ((field_t*)type->fields.array[1])->type);
-      type->fixed_size = FIELD_VARIABLE;
-      *fixed_parent = FIELD_VARIABLE;
-      break;
-    case LTT_STRING:
-      field->fixed_size = FIELD_VARIABLE;
-      *fixed_parent = FIELD_VARIABLE;
-      break;
-    case LTT_ARRAY:
-      local_fixed_parent = FIELD_FIXED_GENEVENT;
-      preset_type_size(
-        0,
-        &local_fixed_parent,
-        ((field_t*)type->fields.array[0])->type);
-      type->fixed_size = local_fixed_parent;
-      if(type->fixed_size == FIELD_FIXED_GENEVENT) {
-        type->size =
-                                       type->element_number * ((field_t*)type->fields.array[0])->type->size;
-      } else if(type->fixed_size == FIELD_FIXED_COMPILER) {
-        type->size =
-                                       type->element_number;
-      } else {
-        type->size = 0;
-        *fixed_parent = FIELD_VARIABLE;
-      }
-      break;
-    case LTT_STRUCT:
-      current_offset = 0;
-      current_child_status = FIELD_FIXED_GENEVENT;
-      for(i=0;i<type->element_number;i++) {
-        preset_field_type_size(
-          current_offset, 
-          &current_child_status,
-          ((field_t*)type->fields.array[i])->type);
-        if(current_child_status == FIELD_FIXED_GENEVENT) {
-          current_offset += field->child[i]->field_size;
-        } else {
-          current_offset = 0;
-        }
-      }
-      if(current_child_status != FIELD_FIXED_GENEVENT) {
-        *fixed_parent = current_child_status;
-        type->size = 0;
-        type->fixed_size = current_child_status;
-      } else {
-        type->size = current_offset;
-        type->fixed_size = FIELD_FIXED_GENEVENT;
-      }
-      break;
-    case LTT_UNION:
-      current_offset = 0;
-      max_size = 0;
-      final_child_status = FIELD_FIXED_GENEVENT;
-      for(i=0;i<type->element_number;i++) {
-        enum field_status current_child_status = FIELD_FIXED;
-        preset_field_type_size(
-          current_offset, 
-          &current_child_status,
-          ((field_t*)type->fields.array[i])->type);
-        if(current_child_status != FIELD_FIXED_GENEVENT)
-          final_child_status = current_child_status;
-        else
-          max_size =
-                                               max(max_size, ((field_t*)type->fields.array[i])->type->size);
-      }
-      if(final_child_status != FIELD_FIXED_GENEVENT AND COMPILER) {
-                               g_error("LTTV does not support variable size fields in unions.");
-                               /* This will stop the application. */
-        *fixed_parent = final_child_status;
-        type->size = 0;
-        type->fixed_size = current_child_status;
-      } else {
-        type->size = max_size;
-        type->fixed_size = FIELD_FIXED_GENEVENT;
-      }
-      break;
-  }
-
-}
-
-
-size_t get_field_type_size(LttTracefile *tf, LttEventType *event_type,
-    off_t offset_root, off_t offset_parent,
-    LttField *field, void *data)
-{
-  size_t size = 0;
-  guint i;
-  LttType *type;
-  
-  g_assert(field->fixed_root != FIELD_UNKNOWN);
-  g_assert(field->fixed_parent != FIELD_UNKNOWN);
-  g_assert(field->fixed_size != FIELD_UNKNOWN);
-
-  field->offset_root = offset_root;
-  field->offset_parent = offset_parent;
-  
-  type = field->field_type;
-
-  switch(type->type_class) {
-    case LTT_INT:
-    case LTT_UINT:
-    case LTT_FLOAT:
-    case LTT_ENUM:
-    case LTT_POINTER:
-    case LTT_LONG:
-    case LTT_ULONG:
-    case LTT_SIZE_T:
-    case LTT_SSIZE_T:
-    case LTT_OFF_T:
-      g_assert(field->fixed_size == FIELD_FIXED);
-      size = field->field_size;
-      break;
-    case LTT_SEQUENCE:
-      {
-        gint seqnum = ltt_get_uint(LTT_GET_BO(tf),
-                        field->sequ_number_size,
-                        data + offset_root);
-
-        if(field->child[0]->fixed_size == FIELD_FIXED) {
-          size = field->sequ_number_size + 
-            (seqnum * get_field_type_size(tf, event_type,
-                                          offset_root, offset_parent,
-                                          field->child[0], data));
-        } else {
-          size += field->sequ_number_size;
-          for(i=0;i<seqnum;i++) {
-            size_t child_size;
-            child_size = get_field_type_size(tf, event_type,
-                                    offset_root, offset_parent,
-                                    field->child[0], data);
-            offset_root += child_size;
-            offset_parent += child_size;
-            size += child_size;
-          }
-        }
-        field->field_size = size;
-      }
-      break;
-    case LTT_STRING:
-      size = strlen((char*)(data+offset_root)) + 1;// length + \0
-      field->field_size = size;
-      break;
-    case LTT_ARRAY:
-      if(field->fixed_size == FIELD_FIXED)
-        size = field->field_size;
-      else {
-        for(i=0;i<field->field_type->element_number;i++) {
-          size_t child_size;
-          child_size = get_field_type_size(tf, event_type,
-                                  offset_root, offset_parent,
-                                  field->child[0], data);
-          offset_root += child_size;
-          offset_parent += child_size;
-          size += child_size;
-        }
-        field->field_size = size;
-      }
-      break;
-    case LTT_STRUCT:
-      if(field->fixed_size == FIELD_FIXED)
-        size = field->field_size;
-      else {
-        size_t current_root_offset = offset_root;
-        size_t current_offset = 0;
-        size_t child_size = 0;
-        for(i=0;i<type->element_number;i++) {
-          child_size = get_field_type_size(tf,
-                     event_type, current_root_offset, current_offset, 
-                     field->child[i], data);
-          current_offset += child_size;
-          current_root_offset += child_size;
-          
-        }
-        size = current_offset;
-        field->field_size = size;
-      }
-      break;
-    case LTT_UNION:
-      if(field->fixed_size == FIELD_FIXED)
-        size = field->field_size;
-      else {
-        size_t current_root_offset = field->offset_root;
-        size_t current_offset = 0;
-        for(i=0;i<type->element_number;i++) {
-          size = get_field_type_size(tf, event_type,
-                 current_root_offset, current_offset, 
-                 field->child[i], data);
-          size = max(size, field->child[i]->field_size);
-        }
-        field->field_size = size;
-      }
-      break;
-  }
-
-  return size;
-}
-
-
-
-
+ * Copied from construct_types_and_fields in LTTV facility.c
+ *
+ * basename is the name which identifies the type (along with a prefix
+ * (possibly)). */
 
-/* Print the code that calculates the length of an field */
-int print_field_len(type_descriptor_t * td, FILE *fd, unsigned int tabs,
-               char *nest_type_name, char *nest_field_name, char *field_name, 
-               char *output_var, char *member_var)
+int print_type_write(type_descriptor_t * td, FILE *fd, unsigned int tabs,
+               char *nest_name, char *field_name, char *obj_prefix, int get_ptr)
 {
-       /* Type name : basename */
        char basename[PATH_MAX];
        unsigned int basename_len = 0;
-
-       strcpy(basename, nest_type_name);
+       char get_ptr_char[2] = "";
+       char custom[PATH_MAX] = "";
+       
+       strncpy(basename, nest_name, PATH_MAX);
        basename_len = strlen(basename);
        
        /* For a named type, we use the type_name directly */
@@ -824,28 +678,24 @@ int print_field_len(type_descriptor_t * td, FILE *fd, unsigned int tabs,
                strncpy(basename, td->type_name, PATH_MAX);
                basename_len = strlen(basename);
        } else {
-               /* For a unnamed type, there must be a field name */
+               /* For a unnamed type, there must be a field name, except for
+                * the array. */
                if((basename_len != 0)
-                               && (basename[basename_len-1] != '_')
-                               && (field_name[0] != '\0')) {
+                               && (basename[basename_len-1] != '_'
+                               && (field_name[0] != '\0'))) {
                        strncat(basename, "_", PATH_MAX - basename_len);
                        basename_len = strlen(basename);
                }
                strncat(basename, field_name, PATH_MAX - basename_len);
        }
        
-       /* Field name : basefieldname */
-       char basefieldname[PATH_MAX];
-       unsigned int basefieldname_len = 0;
-
-       strcpy(basefieldname, nest_field_name);
-       basefieldname_len = strlen(basefieldname);
-       
-       /* there must be a field name */
-       strncat(basefieldname, field_name, PATH_MAX - basefieldname_len);
-       basefieldname_len = strlen(basefieldname);
+       if(get_ptr) {
+               strcpy(get_ptr_char, "&");
+       }
 
-       print_tabs(tabs, fd);
+       if(td->custom_write) {
+               strcpy(custom, "_custom");
+       }
 
        switch(td->type) {
                case INT_FIXED:
@@ -864,53 +714,109 @@ int print_field_len(type_descriptor_t * td, FILE *fd, unsigned int tabs,
                case SSIZE_T:
                case OFF_T:
                case ENUM:
-                       fprintf(fd, "/* Size of %s */", field_name);
                        print_tabs(tabs, fd);
-                       fprintf(fd, "%s = sizeof(", member_var);
-                       if(print_type(td, fd, tabs, basename, "")) return 1;
-                       fprintf(fd, ");\n");
-                       fprintf(fd, "%s += ltt_align(%s, %s);\n", output_var, member_var);
+                       fprintf(fd, "align = ");
+                       if(print_type_alignment(td, fd, 0, basename, "", "obj")) return 1;
+                       fprintf(fd, ";\n");
+                       fprintf(fd, "\n");
+                       print_tabs(tabs, fd);
+                       fprintf(fd, "if(*len == 0) {\n");
+                       print_tabs(tabs+1, fd);
+                       fprintf(fd, "*to += ltt_align(*to, align); /* align output */\n");
+                       print_tabs(tabs, fd);
+                       fprintf(fd, "} else {\n");
+                       print_tabs(tabs+1, fd);
+                       fprintf(fd, "*len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */\n");
+                       print_tabs(tabs, fd);
+                       fprintf(fd, "}\n");
+                       fprintf(fd, "\n");
+
                        print_tabs(tabs, fd);
-                       fprintf(fd, "%s += %s;\n", output_var, member_var);
+                       fprintf(fd, "*len += ");
+                       fprintf(fd, "sizeof(");
+                       if(print_type(td, fd, 0, basename, "")) return 1;
+                       fprintf(fd, ");\n");
+
                        break;
                case STRING:
-                       /* strings are made of bytes : no alignment. */
-                       fprintf(fd, "/* Size of %s */", basefieldname);
                        print_tabs(tabs, fd);
-                       fprintf(fd, "%s = strlen(%s);", member_var, basefieldname);
+                       fprintf(fd,
+                                       "lttng_write%s_string_%s(buffer, to_base, to, from, len, %s%s);\n",
+                                       custom, basename, obj_prefix, field_name);
+                       break;
+               case SEQUENCE:
+                       print_tabs(tabs, fd);
+                       fprintf(fd,
+                                       "lttng_write%s_sequence_%s(buffer, to_base, to, from, len, %s%s%s);",
+                                       custom, basename, get_ptr_char, obj_prefix, field_name);
+                       break;
+               case STRUCT:
+                       print_tabs(tabs, fd);
+                       fprintf(fd,
+                                       "lttng_write%s_struct_%s(buffer, to_base, to, from, len, %s%s%s);",
+                                       custom, basename, get_ptr_char, obj_prefix, field_name);
+                       break;
+               case UNION:
+                       print_tabs(tabs, fd);
+                       fprintf(fd,
+                                       "lttng_write%s_union_%s(buffer, to_base, to, from, len, %s%s%s);",
+                                       custom, basename, get_ptr_char, obj_prefix, field_name);
                        break;
                case ARRAY:
-                       fprintf(fd, "/* Size of %s */", basefieldname);
                        print_tabs(tabs, fd);
+                       fprintf(fd,
+                                       "lttng_write%s_array_%s(buffer, to_base, to, from, len, %s%s);",
+                                       custom, basename, obj_prefix, field_name);
+                       break;
+               case NONE:
+                       printf("Error : type NONE unexpected\n");
+                       return 1;
+                       break;
+       }
 
-                       strncat(basefieldname, ".", PATH_MAX - basefieldname_len);
-                       basefieldname_len = strlen(basefieldname);
-
-                       if(print_field_len(((field_t*)td->fields.array[0])->type,
-                                               fd, tabs,
-                                               basename, basefieldname,
-                                               output_var, member_var)) return 1;
+       return 0;
+}
 
-                       fprintf(fd, "%s = strlen(%s);", member_var, basefieldname);
+/* print need local vars ?.
+ *
+ * Copied from print_type_write
+ *
+ * Does the type_write call needs local size and from variables ?
+ * return value : 1 yes, 0 no.
+ */
 
-                       fprintf(fd, "lttng_array_%s", basename);
-                       fprintf(fd, " %s", field_name);
+int has_type_local(type_descriptor_t * td)
+{
+       switch(td->type) {
+               case INT_FIXED:
+               case UINT_FIXED:
+               case CHAR:
+               case UCHAR:
+               case SHORT:
+               case USHORT:
+               case INT:
+               case UINT:
+               case FLOAT:
+               case POINTER:
+               case LONG:
+               case ULONG:
+               case SIZE_T:
+               case SSIZE_T:
+               case OFF_T:
+               case ENUM:
+                       return 1;
                        break;
+               case STRING:
                case SEQUENCE:
-                       fprintf(fd, "lttng_sequence_%s *", basename);
-                       fprintf(fd, " %s", field_name);
-                       break;
-       case STRUCT:
-                       fprintf(fd, "struct lttng_%s *", basename);
-                       fprintf(fd, " %s", field_name);
-                       break;
-       case UNION:
-                       fprintf(fd, "union lttng_%s *", basename);
-                       fprintf(fd, " %s", field_name);
+               case STRUCT:
+               case UNION:
+               case ARRAY:
+                       return 0;
                        break;
-       default:
-                       printf("print_type : unknown type\n");
+               case NONE:
+                       printf("Error : type NONE unexpected\n");
                        return 1;
+                       break;
        }
 
        return 0;
@@ -918,76 +824,1267 @@ int print_field_len(type_descriptor_t * td, FILE *fd, unsigned int tabs,
 
 
 
+/* print type alignment function.
+ *
+ * Copied from construct_types_and_fields in LTTV facility.c
+ *
+ * basename is the name which identifies the type (along with a prefix
+ * (possibly)). */
 
-/* Print the logging function of an event. This is the core of genevent */
-int print_event_logging_function(char *basename, event_t *event, FILE *fd)
+int print_type_alignment_fct(type_descriptor_t * td, FILE *fd,
+               unsigned int tabs,
+               char *nest_name, char *field_name)
 {
-       fprintf(fd, "static inline void trace_%s(\n", basename);
-       for(unsigned int j = 0; j < event->fields.position; j++) {
-               /* For each field, print the function argument */
-               field_t *f = (field_t*)event->fields.array[j];
-               type_descriptor_t *t = f->type;
-               if(print_arg(t, fd, 2, basename, f->name)) return 1;
-               if(j < event->fields.position-1) {
-                       fprintf(fd, ",");
-                       fprintf(fd, "\n");
-               }
-       }
-       if(event->fields.position == 0) {
-               print_tabs(2, fd);
-               fprintf(fd, "void");
-       }
-       fprintf(fd,")\n");
-       fprintf(fd, "#ifndef CONFIG_LTT\n");
-       fprintf(fd, "{\n");
-       fprintf(fd, "}\n");
-       fprintf(fd,"#else\n");
-       fprintf(fd, "{\n");
-       /* Print the function variables */
-       print_tabs(1, fd);
-       fprintf(fd, "size_t member_length;");
-       fprintf(fd, "size_t event_length = 0;");
+       char basename[PATH_MAX];
+       unsigned int basename_len = 0;
        
-       /* Calculate event variable len + event data alignment offset.
-        * Assume that the padding for alignment starts at a void*
-        * address.
-        * This excludes the header size and alignment. */
-
+       if(td->custom_write) return 0;  /* Does print custom type */
 
-       for(unsigned int j = 0; j < event->fields.position; j++) {
-               /* For each field, calculate the field size. */
-               field_t *f = (field_t*)event->fields.array[j];
-               type_descriptor_t *t = f->type;
-               if(print_field_len(t, fd, 1, basename, "", 
-                                       f->name,
-                                       "event_length",
-                                       "member_length")) return 1;
-               if(j < event->fields.position-1) {
-                       fprintf(fd, ",");
-                       fprintf(fd, "\n");
+       strncpy(basename, nest_name, PATH_MAX);
+       basename_len = strlen(basename);
+       
+       /* For a named type, we use the type_name directly */
+       if(td->type_name != NULL) {
+               strncpy(basename, td->type_name, PATH_MAX);
+               basename_len = strlen(basename);
+       } else {
+               /* For a unnamed type, there must be a field name, except for
+                * the array. */
+               if((basename_len != 0)
+                               && (basename[basename_len-1] != '_'
+                               && (field_name[0] != '\0'))) {
+                       strncat(basename, "_", PATH_MAX - basename_len);
+                       basename_len = strlen(basename);
                }
+               strncat(basename, field_name, PATH_MAX - basename_len);
        }
-
-       /* Take locks : make sure the trace does not vanish while we write on
-        * it. A simple preemption disabling is enough (using rcu traces). */
-       
-       /* For each trace */
        
-       /* Relay reserve */
-       /* If error, increment counter and return */
-       
-       /* write data */
-               
-       /* commit */
+       switch(td->type) {
+               case SEQUENCE:
+                       /* Function header */
+                       fprintf(fd, "static inline size_t lttng_get_alignment_sequence_%s(\n",
+                                       basename);
+                       print_tabs(2, fd);
+                       if(print_type(td,       fd, 0, basename, "")) return 1;
+                       fprintf(fd, " *obj)\n");
+                       fprintf(fd, "{\n");
+                       print_tabs(1, fd);
+                       fprintf(fd, "size_t align=0, localign;");
+                       fprintf(fd, "\n");
+                       print_tabs(1, fd);
+                       fprintf(fd, "localign = ");
+                       if(print_type_alignment(((field_t*)td->fields.array[0])->type,
+                                               fd, 0, basename, "len", "obj->")) return 1;
+                       fprintf(fd, ";\n");
+                       print_tabs(1, fd);
+                       fprintf(fd, "align = max(align, localign);\n");
+                       fprintf(fd, "\n");
+                       print_tabs(1, fd);
+                       fprintf(fd, "localign = ");
+                       if(print_type_alignment(((field_t*)td->fields.array[1])->type,
+                                               fd, 0, basename, "array[0]", "obj->")) return 1;
+                       fprintf(fd, ";\n");
+                       print_tabs(1, fd);
+                       fprintf(fd, "align = max(align, localign);\n");
+                       fprintf(fd, "\n");
+                       print_tabs(1, fd);
+                       fprintf(fd, "return align;\n");
+                       break;
+               case STRUCT:
+                       /* Function header */
+                       fprintf(fd, "static inline size_t lttng_get_alignment_struct_%s(\n",
+                                       basename);
+                       print_tabs(2, fd);
+                       if(print_type(td,       fd, 0, basename, "")) return 1;
+                       fprintf(fd, " *obj)\n");
+                       fprintf(fd, "{\n");
+                       print_tabs(1, fd);
+                       fprintf(fd, "size_t align=0, localign;");
+                       fprintf(fd, "\n");
+                       for(unsigned int i=0;i<td->fields.position;i++){
+                               field_t *field = (field_t*)(td->fields.array[i]);
+                               type_descriptor_t *type = field->type;
+                               print_tabs(1, fd);
+                               fprintf(fd, "localign = ");
+                               if(print_type_alignment(type, fd, 0, basename, field->name, "obj->"))
+                                       return 1;
+                               fprintf(fd, ";\n");
+                               print_tabs(1, fd);
+                               fprintf(fd, "align = max(align, localign);\n");
+                               fprintf(fd, "\n");
+                       }
+                       print_tabs(1, fd);
+                       fprintf(fd, "return align;\n");
+
+                       break;
+               case UNION:
+                       /* Function header */
+                       fprintf(fd, "static inline size_t lttng_get_alignment_union_%s(\n",
+                                       basename);
+                       print_tabs(2, fd);
+                       if(print_type(td,       fd, 0, basename, "")) return 1;
+                       fprintf(fd, " *obj)\n");
+                       fprintf(fd, "{\n");
+                       print_tabs(1, fd);
+                       fprintf(fd, "size_t align=0, localign;");
+                       fprintf(fd, "\n");
+                       for(unsigned int i=0;i<td->fields.position;i++){
+                               field_t *field = (field_t*)(td->fields.array[i]);
+                               type_descriptor_t *type = field->type;
+                               print_tabs(1, fd);
+                               fprintf(fd, "localign = ");
+                               if(print_type_alignment(type, fd, 0, basename, field->name, "obj->"))
+                                       return 1;
+                               fprintf(fd, ";\n");
+                               print_tabs(1, fd);
+                               fprintf(fd, "align = max(align, localign);\n");
+                               fprintf(fd, "\n");
+                       }
+                       print_tabs(1, fd);
+                       fprintf(fd, "return align;\n");
+
+                       break;
+               case ARRAY:
+                       /* Function header */
+                       fprintf(fd, "static inline size_t lttng_get_alignment_array_%s(\n",
+                                       basename);
+                       print_tabs(2, fd);
+                       if(print_type(td,       fd, 0, basename, "")) return 1;
+                       fprintf(fd, " obj)\n");
+                       fprintf(fd, "{\n");
+                       print_tabs(1, fd);
+                       fprintf(fd, "return \n");
+                       if(print_type_alignment(((field_t*)td->fields.array[0])->type,
+                                               fd, 0, basename, "", "obj[0]"))
+                               return 1;
+                       fprintf(fd, ";\n");
+                       break;
+               default:
+                       dprintf("print_type_alignment_fct : type has no alignment function.\n");
+                       return 0;
+                       break;
+       }
+
+
+       /* Function footer */
+       fprintf(fd, "}\n");
+       fprintf(fd, "\n");
+
+       return 0;
+}
+
+/* print type write function.
+ *
+ * Copied from construct_types_and_fields in LTTV facility.c
+ *
+ * basename is the name which identifies the type (along with a prefix
+ * (possibly)). */
+
+int print_type_write_fct(type_descriptor_t * td, FILE *fd, unsigned int tabs,
+               char *nest_name, char *field_name)
+{
+       char basename[PATH_MAX];
+       unsigned int basename_len = 0;
+       
+       if(td->custom_write) return 0;  /* Does print custom type */
+
+       strncpy(basename, nest_name, PATH_MAX);
+       basename_len = strlen(basename);
+       
+       /* For a named type, we use the type_name directly */
+       if(td->type_name != NULL) {
+               strncpy(basename, td->type_name, PATH_MAX);
+               basename_len = strlen(basename);
+       } else {
+               /* For a unnamed type, there must be a field name, except for
+                * the array. */
+               if((basename_len != 0)
+                               && (basename[basename_len-1] != '_'
+                               && (field_name[0] != '\0'))) {
+                       strncat(basename, "_", PATH_MAX - basename_len);
+                       basename_len = strlen(basename);
+               }
+               strncat(basename, field_name, PATH_MAX - basename_len);
+       }
+       
+       switch(td->type) {
+               case SEQUENCE:
+               case STRUCT:
+               case UNION:
+               case ARRAY:
+               case STRING:
+                       break;
+               default:
+                       dprintf("print_type_write_fct : type has no write function.\n");
+                       return 0;
+                       break;
+       }
+       
+       /* Print header */
+       switch(td->type) {
+               case SEQUENCE:
+                       fprintf(fd, "static inline void lttng_write_sequence_%s(\n",
+                                       basename);
+                       break;
+               case STRUCT:
+                       fprintf(fd, "static inline void lttng_write_struct_%s(\n", basename);
+                       break;
+               case UNION:
+                       fprintf(fd, "static inline void lttng_write_union_%s(\n", basename);
+                       break;
+               case ARRAY:
+                       fprintf(fd, "static inline void lttng_write_array_%s(\n", basename);
+                       break;
+               case STRING:
+                       fprintf(fd, "static inline void lttng_write_string_%s(\n", basename);
+                       break;
+               default:
+                       printf("print_type_write_fct : type has no write function.\n");
+                       break;
+       }
+
+       print_tabs(2, fd);
+       fprintf(fd, "void *buffer,\n");
+       print_tabs(2, fd);
+       fprintf(fd, "size_t *to_base,\n");
+       print_tabs(2, fd);
+       fprintf(fd, "size_t *to,\n");
+       print_tabs(2, fd);
+       fprintf(fd, "const void **from,\n");
+       print_tabs(2, fd);
+       fprintf(fd, "size_t *len,\n");
+       print_tabs(2, fd);
+       if(print_type(td,       fd, 0, basename, "")) return 1;
+
+       switch(td->type) {
+               case SEQUENCE:
+                       fprintf(fd, " *obj)\n");
+                       break;
+               case STRUCT:
+                       fprintf(fd, " *obj)\n");
+                       break;
+               case UNION:
+                       fprintf(fd, " *obj)\n");
+                       break;
+               case ARRAY:
+                       fprintf(fd, " obj)\n");
+                       break;
+               case STRING:
+                       fprintf(fd, " obj)\n");
+                       break;
+               default:
+                       printf("print_type_write_fct : type has no write function.\n");
+                       break;
+       }
+
+       fprintf(fd, "{\n");
+
+       switch(td->type) {
+               case STRING:
+                       print_tabs(1, fd);
+                       fprintf(fd, "size_t size;\n");
+                       break;
+               default:
+                       break;
+       }
+
+       print_tabs(1, fd);
+       fprintf(fd, "size_t align;\n");
+       fprintf(fd, "\n");
+
+       switch(td->type) {
+               case SEQUENCE:
+               case STRING:
+                       print_tabs(1, fd);
+                       fprintf(fd, "/* Flush pending memcpy */\n");
+                       print_tabs(1, fd);
+                       fprintf(fd, "if(*len != 0) {\n");
+                       print_tabs(2, fd);
+                       fprintf(fd, "if(buffer != NULL)\n");
+                       print_tabs(3, fd);
+                       fprintf(fd, "memcpy(buffer+*to_base+*to, *from, *len);\n");
+                       print_tabs(1, fd);
+                       fprintf(fd, "}\n");
+                       print_tabs(1, fd);
+                       fprintf(fd, "*to += *len;\n");
+                       print_tabs(1, fd);
+                       fprintf(fd, "*len = 0;\n");
+                       fprintf(fd, "\n");
+                       break;
+               case STRUCT:
+               case UNION:
+               case ARRAY:
+                       break;
+               default:
+                       printf("print_type_write_fct : type has no write function.\n");
+                       break;
+       }
+       
+       print_tabs(1, fd);
+       fprintf(fd, "align = ");
+       if(print_type_alignment(td, fd, 0, basename, "", "obj")) return 1;
+       fprintf(fd, ";\n");
+       fprintf(fd, "\n");
+       print_tabs(1, fd);
+       fprintf(fd, "if(*len == 0) {\n");
+       print_tabs(2, fd);
+       fprintf(fd, "*to += ltt_align(*to, align); /* align output */\n");
+       print_tabs(1, fd);
+       fprintf(fd, "} else {\n");
+       print_tabs(2, fd);
+       fprintf(fd, "*len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */\n");
+       print_tabs(1, fd);
+       fprintf(fd, "}\n");
+       fprintf(fd, "\n");
+
+       /* First, check if the type has a fixed size. If it is the case, then the size
+        * to write is know by the compiler : simply use a sizeof() */
+       if(has_type_fixed_size(td)) {
+               print_tabs(1, fd);
+               fprintf(fd, "/* Contains only fixed size fields : use compiler sizeof() */\n");
+               fprintf(fd, "\n");
+               print_tabs(1, fd);
+               fprintf(fd, "*len += sizeof(");
+               if(print_type(td, fd, 0, basename, field_name)) return 1;
+               fprintf(fd, ");\n");
+       } else {
+               /* The type contains nested variable size subtypes :
+                * we must write field by field. */
+               print_tabs(1, fd);
+               fprintf(fd, "/* Contains variable sized fields : must explode the structure */\n");
+               fprintf(fd, "\n");
+
+               switch(td->type) {
+                       case SEQUENCE:
+                               print_tabs(1, fd);
+                               fprintf(fd, "/* Copy members */\n");
+//                             print_tabs(1, fd);
+//                             fprintf(fd, "size = sizeof(\n");
+                               if(print_type_write(((field_t*)td->fields.array[0])->type,
+                                               fd, 1, basename, "len", "obj->", 1)) return 1;
+                               fprintf(fd, "\n");
+//                             fprintf(fd, ");\n");
+//                             print_tabs(1, fd);
+//                             fprintf(fd, "*to += ltt_align(*to, size);\n");
+                               print_tabs(1, fd);
+                               fprintf(fd, "if(buffer != NULL)\n");
+                               print_tabs(2, fd);
+                               fprintf(fd, "memcpy(buffer+*to_base+*to, &obj->len, *len);\n");
+                               print_tabs(1, fd);
+                               fprintf(fd, "*to += *len;\n");
+                               print_tabs(1, fd);
+                               fprintf(fd, "*len = 0;\n");
+                               fprintf(fd, "\n");
+
+                               /* Write the child : varlen child or not ? */
+                               if(has_type_fixed_size(((field_t*)td->fields.array[1])->type)) {
+                                       /* Fixed size len child : use a multiplication of its size */
+//                                     print_tabs(1, fd);
+//                                     fprintf(fd, "size = sizeof(\n");
+
+                                       //print_tabs(1, fd);
+                                       /* We know that *len does not contain alignment because of the
+                                        * previous align output. len is always 0 here. */
+                                       if(print_type_write(((field_t*)td->fields.array[1])->type,
+                                                       fd, 1, basename, "array[0]", "obj->", 1))
+                                               return 1;
+//                                     fprintf(fd, ");\n");
+                                       fprintf(fd, "\n");
+                                       print_tabs(1, fd);
+                                       fprintf(fd, "*len = obj->len * (*len);\n");
+                                       print_tabs(1, fd);
+                                       fprintf(fd, "if(buffer != NULL)\n");
+                                       print_tabs(2, fd);
+                                       fprintf(fd, "memcpy(buffer+*to_base+*to, obj->array, *len);\n");
+                                       print_tabs(1, fd);
+                                       fprintf(fd, "*to += *len;\n");
+                                       print_tabs(1, fd);
+                                       fprintf(fd, "*len = 0;\n");
+                                       fprintf(fd, "\n");
+                               } else {
+                                       print_tabs(1, fd);
+                                       fprintf(fd, "/* Variable length child : iter. */\n");
+                                       print_tabs(1, fd);
+                                       fprintf(fd, "for(unsigned int i=0; i<obj->len; i++) {\n");
+                                       if(print_type_write(((field_t*)td->fields.array[1])->type,
+                                                       fd, 2, basename, "array[i]", "obj->", 1)) return 1;
+                                       print_tabs(1, fd);
+                                       fprintf(fd, "}\n");
+                               }
+                               fprintf(fd, "\n");
+                               print_tabs(1, fd);
+                               fprintf(fd, "/* Realign the *to_base on arch size, set *to to 0 */\n");
+                               print_tabs(1, fd);
+                               fprintf(fd, "*to += ltt_align(*to, sizeof(void *));\n");
+                               print_tabs(1, fd);
+                               fprintf(fd, "*to_base = *to_base+*to;\n");
+                               print_tabs(1, fd);
+                               fprintf(fd, "*to = 0;\n");
+                               fprintf(fd, "\n");
+                               print_tabs(1, fd);
+                               fprintf(fd, "/* Put source *from just after the C sequence */\n");
+                               print_tabs(1, fd);
+                               fprintf(fd, "*from = obj+1;\n");
+                               break;
+                       case STRING:
+                               print_tabs(1, fd);
+                               fprintf(fd, "size = strlen(obj) + 1; /* Include final NULL char. */\n");
+                               print_tabs(1, fd);
+                               fprintf(fd, "if(buffer != NULL)\n");
+                               print_tabs(2, fd);
+                               fprintf(fd, "memcpy(buffer+*to_base+*to, obj, size);\n");
+                               print_tabs(1, fd);
+                               fprintf(fd, "*to += size;\n");
+                               fprintf(fd, "\n");
+                               print_tabs(1, fd);
+                               fprintf(fd, "/* Realign the *to_base on arch size, set *to to 0 */\n");
+                               print_tabs(1, fd);
+                               fprintf(fd, "*to += ltt_align(*to, sizeof(void *));\n");
+                               print_tabs(1, fd);
+                               fprintf(fd, "*to_base = *to_base+*to;\n");
+                               print_tabs(1, fd);
+                               fprintf(fd, "*to = 0;\n");
+                               fprintf(fd, "\n");
+                               print_tabs(1, fd);
+                               fprintf(fd, "/* Put source *from just after the C string */\n");
+                               print_tabs(1, fd);
+                               fprintf(fd, "*from += size;\n");
+                               break;
+                       case STRUCT:
+                               for(unsigned int i=0;i<td->fields.position;i++){
+                                       field_t *field = (field_t*)(td->fields.array[i]);
+                                       type_descriptor_t *type = field->type;
+                                       if(print_type_write(type,
+                                                       fd, 1, basename, field->name, "obj->", 1)) return 1;
+                                       fprintf(fd, "\n");
+                               }
+                               break;
+                       case UNION:
+                               printf("ERROR : A union CANNOT contain a variable size child.\n");
+                               return 1;
+                               break;
+                       case ARRAY:
+                               /* Write the child : varlen child or not ? */
+                               if(has_type_fixed_size(((field_t*)td->fields.array[0])->type)) {
+                                       /* Error : if an array has a variable size, then its child must also
+                                        * have a variable size. */
+                                       assert(0);
+                               } else {
+                                       print_tabs(1, fd);
+                                       fprintf(fd, "/* Variable length child : iter. */\n");
+                                       print_tabs(1, fd);
+                                       fprintf(fd, "for(unsigned int i=0; i<LTTNG_ARRAY_SIZE_%s; i++) {\n", basename);
+                                       if(print_type_write(((field_t*)td->fields.array[0])->type,
+                                                       fd, 2, basename, "", "obj->array[i]", 1)) return 1;
+                                       print_tabs(1, fd);
+                                       fprintf(fd, "}\n");
+                               }
+                               break;
+                       default:
+                               printf("print_type_write_fct : type has no write function.\n");
+                               break;
+               }
+
+
+       }
+
+
+       /* Function footer */
+       fprintf(fd, "}\n");
+       fprintf(fd, "\n");
+       return 0;
+}
+
+
+
+/* Print the logging function of an event. This is the core of genevent */
+int print_event_logging_function(char *basename, facility_t *fac,
+               event_t *event, FILE *fd)
+{
+       fprintf(fd, "static inline void trace_%s(\n", basename);
+       int     has_argument = 0;
+       int has_type_fixed = 0;
+
+  /* Does it support per trace tracing ? */
+  if(event->per_trace) {
+               print_tabs(2, fd);
+    fprintf(fd, "struct ltt_trace_struct *dest_trace");
+               has_argument = 1;
+  }
+  
+  /* Does it support per tracefile tracing ? */
+  if(event->per_tracefile) {
+               if(has_argument) {
+                       fprintf(fd, ",");
+                       fprintf(fd, "\n");
+               }
+    fprintf(fd, "unsigned int tracefile_index");
+               has_argument = 1;
+  }
+
+       for(unsigned int j = 0; j < event->fields.position; j++) {
+               /* For each field, print the function argument */
+               field_t *f = (field_t*)event->fields.array[j];
+               type_descriptor_t *t = f->type;
+               if(has_argument) {
+                       fprintf(fd, ",");
+                       fprintf(fd, "\n");
+               }
+               if(print_arg(t, fd, 2, basename, f->name)) return 1;
+               has_argument = 1;
+       }
+       if(!has_argument) {
+               print_tabs(2, fd);
+               fprintf(fd, "void");
+       }
+       fprintf(fd,")\n");
+       fprintf(fd, 
+                       "#if (!defined(CONFIG_LTT) || !defined(CONFIG_LTT_FACILITY_%s))\n",
+                       fac->capname);
+       fprintf(fd, "{\n");
+       fprintf(fd, "}\n");
+       fprintf(fd,"#else\n");
+       fprintf(fd, "{\n");
+       /* Print the function variables */
+       print_tabs(1, fd);
+       fprintf(fd, "unsigned int index;\n");
+       print_tabs(1, fd);
+       fprintf(fd, "struct ltt_channel_struct *channel;\n");
+       print_tabs(1, fd);
+       fprintf(fd, "struct ltt_trace_struct *trace;\n");
+       print_tabs(1, fd);
+       fprintf(fd, "struct rchan_buf *relayfs_buf;\n");
+       print_tabs(1, fd);
+       fprintf(fd, "void *buffer = NULL;\n");
+       print_tabs(1, fd);
+       fprintf(fd, "size_t real_to_base = 0; /* The buffer is allocated on arch_size alignment */\n");
+       print_tabs(1, fd);
+       fprintf(fd, "size_t *to_base = &real_to_base;\n");
+       print_tabs(1, fd);
+       fprintf(fd, "size_t real_to = 0;\n");
+       print_tabs(1, fd);
+       fprintf(fd, "size_t *to = &real_to;\n");
+       print_tabs(1, fd);
+       fprintf(fd, "size_t real_len = 0;\n");
+       print_tabs(1, fd);
+       fprintf(fd, "size_t *len = &real_len;\n");
+       print_tabs(1, fd);
+       fprintf(fd, "size_t reserve_size;\n");
+       print_tabs(1, fd);
+       fprintf(fd, "size_t slot_size;\n");
+       print_tabs(1, fd);
+
+       if(event->fields.position > 0) {
+               for(unsigned int i=0;i<event->fields.position;i++){
+                       /* Search for at least one child with fixed size. It means
+                        * we need local variables.*/
+                       field_t *field = (field_t*)(event->fields.array[i]);
+                       type_descriptor_t *type = field->type;
+                       has_type_fixed = has_type_local(type);
+                       if(has_type_fixed) break;
+               }
+               
+               if(has_type_fixed) {
+                       fprintf(fd, "size_t align;\n");
+                       print_tabs(1, fd);
+               }
+
+               fprintf(fd, "const void *real_from;\n");
+               print_tabs(1, fd);
+               fprintf(fd, "const void **from = &real_from;\n");
+               print_tabs(1, fd);
+       }
+       fprintf(fd, "u64 tsc;\n");
+       print_tabs(1, fd);
+       fprintf(fd, "size_t before_hdr_pad, after_hdr_pad, header_size;\n");
+       fprintf(fd, "\n");
+       
+       print_tabs(1, fd);
+       fprintf(fd, "if(ltt_traces.num_active_traces == 0) return;\n");
+       fprintf(fd, "\n");
+
+       /* Calculate event variable len + event data alignment offset.
+        * Assume that the padding for alignment starts at a void*
+        * address.
+        * This excludes the header size and alignment. */
+
+       print_tabs(1, fd);
+       fprintf(fd, "/* For each field, calculate the field size. */\n");
+       print_tabs(1, fd);
+       fprintf(fd, "/* size = *to_base + *to + *len */\n");
+       print_tabs(1, fd);
+       fprintf(fd, "/* Assume that the padding for alignment starts at a\n");
+       print_tabs(1, fd);
+       fprintf(fd, " * sizeof(void *) address. */\n");
+       fprintf(fd, "\n");
+
+       for(unsigned int i=0;i<event->fields.position;i++){
+               field_t *field = (field_t*)(event->fields.array[i]);
+               type_descriptor_t *type = field->type;
+               /* Set from */
+               print_tabs(1, fd);
+               switch(type->type) {
+                       case SEQUENCE:
+                       case UNION:
+                       case ARRAY:
+                       case STRUCT:
+                       case STRING:
+                               fprintf(fd, "*from = lttng_param_%s;\n", field->name);
+                               break;
+                       default:
+                               fprintf(fd, "*from = &lttng_param_%s;\n", field->name);
+                               break;
+               }
+
+               if(print_type_write(type,
+                               fd, 1, basename, field->name, "lttng_param_", 0)) return 1;
+               fprintf(fd, "\n");
+       }
+       print_tabs(1, fd);
+       fprintf(fd, "reserve_size = *to_base + *to + *len;\n");
+
+       /* Take locks : make sure the trace does not vanish while we write on
+        * it. A simple preemption disabling is enough (using rcu traces). */
+       print_tabs(1, fd);
+       fprintf(fd, "preempt_disable();\n");
+       print_tabs(1, fd);
+       fprintf(fd, "ltt_nesting[smp_processor_id()]++;\n");
+
+       /* Get facility index */
+
+       if(event->per_tracefile) {
+               print_tabs(1, fd);
+               fprintf(fd, "index = tracefile_index;\n");
+       } else {
+               print_tabs(1, fd);
+               fprintf(fd, 
+                       "index = ltt_get_index_from_facility(ltt_facility_%s_%X,\n"\
+                                       "\t\t\t\t\t\tevent_%s_%s);\n",
+                               fac->name, fac->checksum, fac->name, event->name);
+       }
+       fprintf(fd,"\n");
+
+       
+       /* For each trace */
+       print_tabs(1, fd);
+       fprintf(fd, "list_for_each_entry_rcu(trace, &ltt_traces.head, list) {\n");
+       print_tabs(2, fd);
+       fprintf(fd, "if(!trace->active) continue;\n\n");
+
+       if(event->per_trace) {
+               print_tabs(2, fd);
+               fprintf(fd, "if(dest_trace != trace) continue;\n\n");
+       }
+       print_tabs(2, fd);
+       fprintf(fd, "channel = ltt_get_channel_from_index(trace, index);\n");
+       print_tabs(2, fd);
+       fprintf(fd, "relayfs_buf = channel->rchan->buf[smp_processor_id()];\n");
+       fprintf(fd, "\n");
+
+       
+       /* Relay reserve */
+       /* If error, increment event lost counter (done by ltt_reserve_slot) and 
+        * return */
+       print_tabs(2, fd);
+       fprintf(fd, "slot_size = 0;\n");
+       print_tabs(2, fd);
+       fprintf(fd, "buffer = ltt_reserve_slot(trace, relayfs_buf,\n");
+       print_tabs(3, fd);
+       fprintf(fd, "reserve_size, &slot_size, &tsc,\n");
+       print_tabs(3, fd);
+       fprintf(fd, "&before_hdr_pad, &after_hdr_pad, &header_size);\n");
+       /* If error, return */
+       print_tabs(2, fd);
+       fprintf(fd, "if(!buffer) continue; /* buffer full */\n\n");
+       //print_tabs(2, fd);
+       // for DEBUG only 
+       // fprintf(fd, "goto commit; /* DEBUG : never actually write. */\n\n");
+       print_tabs(2, fd);
+       fprintf(fd, "*to_base = *to = *len = 0;\n");
+       fprintf(fd, "\n");
+
+       /* Write event header */
+       print_tabs(2, fd);
+       fprintf(fd, "ltt_write_event_header(trace, channel, buffer,\n");
+       print_tabs(3, fd);
+       fprintf(fd, "ltt_facility_%s_%X, event_%s_%s,\n", fac->name, fac->checksum,
+                                                                       fac->name, event->name);
+       print_tabs(3, fd);
+       fprintf(fd, "reserve_size, before_hdr_pad, tsc);\n");
+       print_tabs(2, fd);
+       fprintf(fd, "*to_base += before_hdr_pad + after_hdr_pad + header_size;\n");
+       fprintf(fd, "\n");
+       
+       /* write data. */
+
+       for(unsigned int i=0;i<event->fields.position;i++){
+               field_t *field = (field_t*)(event->fields.array[i]);
+               type_descriptor_t *type = field->type;
+       
+               /* Set from */
+               print_tabs(2, fd);
+               switch(type->type) {
+                       case SEQUENCE:
+                       case UNION:
+                       case ARRAY:
+                       case STRUCT:
+                       case STRING:
+                               fprintf(fd, "*from = lttng_param_%s;\n", field->name);
+                               break;
+                       default:
+                               fprintf(fd, "*from = &lttng_param_%s;\n", field->name);
+                               break;
+               }
+
+
+               if(print_type_write(type,
+                               fd, 2, basename, field->name, "lttng_param_", 0)) return 1;
+               fprintf(fd, "\n");
+               
+               /* Don't forget to flush pending memcpy */
+               print_tabs(2, fd);
+               fprintf(fd, "/* Flush pending memcpy */\n");
+               print_tabs(2, fd);
+               fprintf(fd, "if(*len != 0) {\n");
+               print_tabs(3, fd);
+               fprintf(fd, "memcpy(buffer+*to_base+*to, *from, *len);\n");
+               print_tabs(3, fd);
+               fprintf(fd, "*to += *len;\n");
+               //print_tabs(3, fd);
+               //fprintf(fd, "from += len;\n");
+               print_tabs(3, fd);
+               fprintf(fd, "*len = 0;\n");
+               print_tabs(2, fd);
+               fprintf(fd, "}\n");
+               fprintf(fd, "\n");
+       }
+
+       
+       /* commit */
+       // for DEBUG only.
+       //fprintf(fd, "commit:\n"); /* DEBUG! */
+       print_tabs(2, fd);
+       fprintf(fd, "ltt_commit_slot(relayfs_buf, buffer, slot_size);\n\n");
+       
+       print_tabs(1, fd);
+       fprintf(fd, "}\n\n");
+
+       /* Release locks */
+       print_tabs(1, fd);
+       fprintf(fd, "ltt_nesting[smp_processor_id()]--;\n");
+       print_tabs(1, fd);
+       fprintf(fd, "preempt_enable_no_resched();\n");
+
+       fprintf(fd, "}\n");
+       fprintf(fd, "#endif //(!defined(CONFIG_LTT) || !defined(CONFIG_LTT_FACILITY_%s))\n\n",
+                       fac->capname);
+       return 0;
+}
+
+/* print_event_logging_function_user_generic
+ * Print the logging function of an event for userspace tracing. This is the
+ * core of genevent */
+int print_event_logging_function_user_generic(char *basename, facility_t *fac,
+               event_t *event, FILE *fd)
+{
+       char *attrib;
+
+       fprintf(fd, "#ifndef LTT_TRACE_FAST\n");
+       
+       if(event->no_instrument_function) {
+               attrib = "__attribute__((no_instrument_function)) ";
+       } else {
+               attrib = "";
+       }
+       if(event->param_buffer) {
+               fprintf(fd, "static inline %sint trace_%s_param_buffer(\n", attrib, basename);
+       } else {
+               fprintf(fd, "static inline %sint trace_%s(\n",attrib, basename);
+       }
+       int     has_argument = 0;
+       int has_type_fixed = 0;
+
+       if(event->param_buffer) {
+               if(has_argument) {
+                               fprintf(fd, ",");
+                               fprintf(fd, "\n");
+               }
+               print_tabs(2, fd);
+               fprintf(fd, "void *buffer");
+               has_argument = 1;
+               fprintf(fd, ",");
+               fprintf(fd, "\n");
+               print_tabs(2, fd);
+               fprintf(fd, "size_t reserve_size");
+       } else {
+               for(unsigned int j = 0; j < event->fields.position; j++) {
+                       /* For each field, print the function argument */
+                       field_t *f = (field_t*)event->fields.array[j];
+                       type_descriptor_t *t = f->type;
+                       if(has_argument) {
+                               fprintf(fd, ",");
+                               fprintf(fd, "\n");
+                       }
+                       if(print_arg(t, fd, 2, basename, f->name)) return 1;
+                       has_argument = 1;
+               }
+       }
+       if(!has_argument) {
+               print_tabs(2, fd);
+               fprintf(fd, "void");
+       }
+       fprintf(fd,")\n");
+       fprintf(fd, 
+                       "#ifndef LTT_TRACE\n");
+       fprintf(fd, "{\n");
+       fprintf(fd, "}\n");
+       fprintf(fd,"#else\n");
+       fprintf(fd, "{\n");
+       /* Print the function variables */
+       print_tabs(1, fd);
+       fprintf(fd, "int ret = 0;\n");
+       if(event->param_buffer) {
+               print_tabs(1, fd);
+               fprintf(fd, "reserve_size = ltt_align(reserve_size, sizeof(void *));\n");
+               print_tabs(1, fd);
+               fprintf(fd, "{\n");
+               goto do_syscall;
+       }
+       print_tabs(1, fd);
+       fprintf(fd, "void *buffer = NULL;\n");
+       print_tabs(1, fd);
+       fprintf(fd, "size_t real_to_base = 0; /* The buffer is allocated on arch_size alignment */\n");
+       print_tabs(1, fd);
+       fprintf(fd, "size_t *to_base = &real_to_base;\n");
+       print_tabs(1, fd);
+       fprintf(fd, "size_t real_to = 0;\n");
+       print_tabs(1, fd);
+       fprintf(fd, "size_t *to = &real_to;\n");
+       print_tabs(1, fd);
+       fprintf(fd, "size_t real_len = 0;\n");
+       print_tabs(1, fd);
+       fprintf(fd, "size_t *len = &real_len;\n");
+       print_tabs(1, fd);
+       fprintf(fd, "size_t reserve_size;\n");
+       print_tabs(1, fd);
+       fprintf(fd, "size_t slot_size;\n");
+       print_tabs(1, fd);
+
+       if(event->fields.position > 0) {
+               for(unsigned int i=0;i<event->fields.position;i++){
+                       /* Search for at least one child with fixed size. It means
+                        * we need local variables.*/
+                       field_t *field = (field_t*)(event->fields.array[i]);
+                       type_descriptor_t *type = field->type;
+                       has_type_fixed = has_type_local(type);
+                       if(has_type_fixed) break;
+               }
+               
+               if(has_type_fixed) {
+                       fprintf(fd, "size_t align;\n");
+                       print_tabs(1, fd);
+               }
+
+               fprintf(fd, "const void *real_from;\n");
+               print_tabs(1, fd);
+               fprintf(fd, "const void **from = &real_from;\n");
+               print_tabs(1, fd);
+       }
+
+       /* Calculate event variable len + event data alignment offset.
+        * Assume that the padding for alignment starts at a void*
+        * address.
+        * This excludes the header size and alignment. */
+
+       print_tabs(1, fd);
+       fprintf(fd, "/* For each field, calculate the field size. */\n");
+       print_tabs(1, fd);
+       fprintf(fd, "/* size = *to_base + *to + *len */\n");
+       print_tabs(1, fd);
+       fprintf(fd, "/* Assume that the padding for alignment starts at a\n");
+       print_tabs(1, fd);
+       fprintf(fd, " * sizeof(void *) address. */\n");
+       fprintf(fd, "\n");
+
+       for(unsigned int i=0;i<event->fields.position;i++){
+               field_t *field = (field_t*)(event->fields.array[i]);
+               type_descriptor_t *type = field->type;
+               /* Set from */
+               print_tabs(1, fd);
+               switch(type->type) {
+                       case SEQUENCE:
+                       case UNION:
+                       case ARRAY:
+                       case STRUCT:
+                       case STRING:
+                               fprintf(fd, "*from = lttng_param_%s;\n", field->name);
+                               break;
+                       default:
+                               fprintf(fd, "*from = &lttng_param_%s;\n", field->name);
+                               break;
+               }
+
+               if(print_type_write(type,
+                               fd, 1, basename, field->name, "lttng_param_", 0)) return 1;
+               fprintf(fd, "\n");
+       }
+       print_tabs(1, fd);
+       fprintf(fd, "reserve_size = *to_base + *to + *len;\n");
+
+       print_tabs(1, fd);
+       fprintf(fd, "{\n");
+       print_tabs(2, fd);
+       fprintf(fd, "char stack_buffer[reserve_size];\n");
+       print_tabs(2, fd);
+       fprintf(fd, "buffer = stack_buffer;\n");
+       fprintf(fd, "\n");
+
+       
+       //print_tabs(2, fd);
+       // for DEBUG only 
+       // fprintf(fd, "goto commit; /* DEBUG : never actually write. */\n\n");
+       print_tabs(2, fd);
+       fprintf(fd, "*to_base = *to = *len = 0;\n");
+       fprintf(fd, "\n");
+
+       /* write data. */
+
+       for(unsigned int i=0;i<event->fields.position;i++){
+               field_t *field = (field_t*)(event->fields.array[i]);
+               type_descriptor_t *type = field->type;
+       
+               /* Set from */
+               print_tabs(2, fd);
+               switch(type->type) {
+                       case SEQUENCE:
+                       case UNION:
+                       case ARRAY:
+                       case STRUCT:
+                       case STRING:
+                               fprintf(fd, "*from = lttng_param_%s;\n", field->name);
+                               break;
+                       default:
+                               fprintf(fd, "*from = &lttng_param_%s;\n", field->name);
+                               break;
+               }
+
+
+               if(print_type_write(type,
+                               fd, 2, basename, field->name, "lttng_param_", 0)) return 1;
+               fprintf(fd, "\n");
+               
+               /* Don't forget to flush pending memcpy */
+               print_tabs(2, fd);
+               fprintf(fd, "/* Flush pending memcpy */\n");
+               print_tabs(2, fd);
+               fprintf(fd, "if(*len != 0) {\n");
+               print_tabs(3, fd);
+               fprintf(fd, "memcpy(buffer+*to_base+*to, *from, *len);\n");
+               print_tabs(3, fd);
+               fprintf(fd, "*to += *len;\n");
+               //print_tabs(3, fd);
+               //fprintf(fd, "from += len;\n");
+               print_tabs(3, fd);
+               fprintf(fd, "*len = 0;\n");
+               print_tabs(2, fd);
+               fprintf(fd, "}\n");
+               fprintf(fd, "\n");
+       }
+
+do_syscall:
+       print_tabs(2, fd);
+       fprintf(fd, "ret = ltt_trace_generic(ltt_facility_%s_%X, event_%s_%s, buffer, reserve_size, LTT_BLOCKING);\n", fac->name, fac->checksum, fac->name, event->name);
+
+       print_tabs(1, fd);
+       fprintf(fd, "}\n\n");
+       
+       print_tabs(1, fd);
+       fprintf(fd, "return ret;\n\n");
+
+       fprintf(fd, "}\n");
+       fprintf(fd, 
+                       "#endif //LTT_TRACE\n");
+       fprintf(fd, "#endif //!LTT_TRACE_FAST\n\n");
+
+       return 0;
+}
+
+/* print_event_logging_function_user_fast
+ * Print the logging function of an event for userspace tracing. This is the
+ * core of genevent */
+int print_event_logging_function_user_fast(char *basename, facility_t *fac,
+               event_t *event, FILE *fd)
+{
+       char *attrib;
+
+       fprintf(fd, "#ifdef LTT_TRACE_FAST\n");
+       
+       if(event->no_instrument_function) {
+               attrib = "__attribute__((no_instrument_function)) ";
+       } else {
+               attrib = "";
+       }
+       fprintf(fd, "static inline %sint trace_%s(\n",attrib, basename);
+
+       int     has_argument = 0;
+       int has_type_fixed = 0;
+
+       for(unsigned int j = 0; j < event->fields.position; j++) {
+               /* For each field, print the function argument */
+               field_t *f = (field_t*)event->fields.array[j];
+               type_descriptor_t *t = f->type;
+               if(has_argument) {
+                       fprintf(fd, ",");
+                       fprintf(fd, "\n");
+               }
+               if(print_arg(t, fd, 2, basename, f->name)) return 1;
+               has_argument = 1;
+       }
+       if(!has_argument) {
+               print_tabs(2, fd);
+               fprintf(fd, "void");
+       }
+       fprintf(fd,")\n");
+       fprintf(fd, 
+                       "#ifndef LTT_TRACE\n");
+       fprintf(fd, "{\n");
+       fprintf(fd, "}\n");
+       fprintf(fd,"#else\n");
+       fprintf(fd, "{\n");
+       /* Print the function variables */
+       print_tabs(1, fd);
+       fprintf(fd, "unsigned int index;\n");
+       print_tabs(1, fd);
+       fprintf(fd, "struct ltt_trace_info *trace = thread_trace_info;\n");
+       print_tabs(1, fd);
+       fprintf(fd, "struct ltt_buf *ltt_buf;\n");
+       print_tabs(1, fd);
+       fprintf(fd, "void *buffer = NULL;\n");
+       print_tabs(1, fd);
+       fprintf(fd, "size_t real_to_base = 0; /* The buffer is allocated on arch_size alignment */\n");
+       print_tabs(1, fd);
+       fprintf(fd, "size_t *to_base = &real_to_base;\n");
+       print_tabs(1, fd);
+       fprintf(fd, "size_t real_to = 0;\n");
+       print_tabs(1, fd);
+       fprintf(fd, "size_t *to = &real_to;\n");
+       print_tabs(1, fd);
+       fprintf(fd, "size_t real_len = 0;\n");
+       print_tabs(1, fd);
+       fprintf(fd, "size_t *len = &real_len;\n");
+       print_tabs(1, fd);
+       fprintf(fd, "size_t reserve_size;\n");
+       print_tabs(1, fd);
+       fprintf(fd, "size_t slot_size;\n");
+       print_tabs(1, fd);
+
+       if(event->fields.position > 0) {
+               for(unsigned int i=0;i<event->fields.position;i++){
+                       /* Search for at least one child with fixed size. It means
+                        * we need local variables.*/
+                       field_t *field = (field_t*)(event->fields.array[i]);
+                       type_descriptor_t *type = field->type;
+                       has_type_fixed = has_type_local(type);
+                       if(has_type_fixed) break;
+               }
+               
+               if(has_type_fixed) {
+                       fprintf(fd, "size_t align;\n");
+                       print_tabs(1, fd);
+               }
+
+               fprintf(fd, "const void *real_from;\n");
+               print_tabs(1, fd);
+               fprintf(fd, "const void **from = &real_from;\n");
+               print_tabs(1, fd);
+       }
+       fprintf(fd, "uint64_t tsc;\n");
+       print_tabs(1, fd);
+       fprintf(fd, "size_t before_hdr_pad, after_hdr_pad, header_size;\n");
+       fprintf(fd, "\n");
+       
+       print_tabs(1, fd);
+       fprintf(fd, "if(!trace) {\n");
+       print_tabs(2, fd);
+       fprintf(fd, "ltt_thread_init();\n");
+       print_tabs(2, fd);
+       fprintf(fd, "trace = thread_trace_info;\n");
+       print_tabs(1, fd);
+       fprintf(fd, "}\n\n");
+       fprintf(fd, "\n");
+
+       /* Calculate event variable len + event data alignment offset.
+        * Assume that the padding for alignment starts at a void*
+        * address.
+        * This excludes the header size and alignment. */
+
+       print_tabs(1, fd);
+       fprintf(fd, "/* For each field, calculate the field size. */\n");
+       print_tabs(1, fd);
+       fprintf(fd, "/* size = *to_base + *to + *len */\n");
+       print_tabs(1, fd);
+       fprintf(fd, "/* Assume that the padding for alignment starts at a\n");
+       print_tabs(1, fd);
+       fprintf(fd, " * sizeof(void *) address. */\n");
+       fprintf(fd, "\n");
+
+       for(unsigned int i=0;i<event->fields.position;i++){
+               field_t *field = (field_t*)(event->fields.array[i]);
+               type_descriptor_t *type = field->type;
+               /* Set from */
+               print_tabs(1, fd);
+               switch(type->type) {
+                       case SEQUENCE:
+                       case UNION:
+                       case ARRAY:
+                       case STRUCT:
+                       case STRING:
+                               fprintf(fd, "*from = lttng_param_%s;\n", field->name);
+                               break;
+                       default:
+                               fprintf(fd, "*from = &lttng_param_%s;\n", field->name);
+                               break;
+               }
+
+               if(print_type_write(type,
+                               fd, 1, basename, field->name, "lttng_param_", 0)) return 1;
+               fprintf(fd, "\n");
+       }
+       print_tabs(1, fd);
+       fprintf(fd, "reserve_size = *to_base + *to + *len;\n");
+
+       print_tabs(1, fd);
+       fprintf(fd, "trace->nesting++;\n");
+
+       /* Get facility index */
+
+       print_tabs(1, fd);
+       fprintf(fd, 
+               "index = ltt_get_index_from_facility(ltt_facility_%s_%X,\n"\
+                               "\t\t\t\t\t\tevent_%s_%s);\n",
+                       fac->name, fac->checksum, fac->name, event->name);
+       fprintf(fd,"\n");
+
+       
+       print_tabs(1, fd);
+       fprintf(fd, "{\n");
+
+       if(event->per_trace) {
+               print_tabs(2, fd);
+               fprintf(fd, "if(dest_trace != trace) continue;\n\n");
+       }
+       print_tabs(2, fd);
+       fprintf(fd, "ltt_buf = ltt_get_channel_from_index(trace, index);\n");
+       print_tabs(2, fd);
+
+       
+       /* Relay reserve */
+       /* If error, increment event lost counter (done by ltt_reserve_slot) and 
+        * return */
+       print_tabs(2, fd);
+       fprintf(fd, "slot_size = 0;\n");
+       print_tabs(2, fd);
+       fprintf(fd, "buffer = ltt_reserve_slot(trace, ltt_buf,\n");
+       print_tabs(3, fd);
+       fprintf(fd, "reserve_size, &slot_size, &tsc,\n");
+       print_tabs(3, fd);
+       fprintf(fd, "&before_hdr_pad, &after_hdr_pad, &header_size);\n");
+       /* If error, return */
+       print_tabs(2, fd);
+       fprintf(fd, "if(!buffer) goto end; /* buffer full */\n\n");
+       //print_tabs(2, fd);
+       // for DEBUG only 
+       // fprintf(fd, "goto commit; /* DEBUG : never actually write. */\n\n");
+       print_tabs(2, fd);
+       fprintf(fd, "*to_base = *to = *len = 0;\n");
+       fprintf(fd, "\n");
+
+       /* Write event header */
+       print_tabs(2, fd);
+       fprintf(fd, "ltt_write_event_header(trace, ltt_buf, buffer,\n");
+       print_tabs(3, fd);
+       fprintf(fd, "ltt_facility_%s_%X, event_%s_%s,\n", fac->name, fac->checksum,
+                                                                       fac->name, event->name);
+       print_tabs(3, fd);
+       fprintf(fd, "reserve_size, before_hdr_pad, tsc);\n");
+       print_tabs(2, fd);
+       fprintf(fd, "*to_base += before_hdr_pad + after_hdr_pad + header_size;\n");
+       fprintf(fd, "\n");
+       
+       /* write data. */
+
+       for(unsigned int i=0;i<event->fields.position;i++){
+               field_t *field = (field_t*)(event->fields.array[i]);
+               type_descriptor_t *type = field->type;
+       
+               /* Set from */
+               print_tabs(2, fd);
+               switch(type->type) {
+                       case SEQUENCE:
+                       case UNION:
+                       case ARRAY:
+                       case STRUCT:
+                       case STRING:
+                               fprintf(fd, "*from = lttng_param_%s;\n", field->name);
+                               break;
+                       default:
+                               fprintf(fd, "*from = &lttng_param_%s;\n", field->name);
+                               break;
+               }
+
+
+               if(print_type_write(type,
+                               fd, 2, basename, field->name, "lttng_param_", 0)) return 1;
+               fprintf(fd, "\n");
+               
+               /* Don't forget to flush pending memcpy */
+               print_tabs(2, fd);
+               fprintf(fd, "/* Flush pending memcpy */\n");
+               print_tabs(2, fd);
+               fprintf(fd, "if(*len != 0) {\n");
+               print_tabs(3, fd);
+               fprintf(fd, "memcpy(buffer+*to_base+*to, *from, *len);\n");
+               print_tabs(3, fd);
+               fprintf(fd, "*to += *len;\n");
+               //print_tabs(3, fd);
+               //fprintf(fd, "from += len;\n");
+               print_tabs(3, fd);
+               fprintf(fd, "*len = 0;\n");
+               print_tabs(2, fd);
+               fprintf(fd, "}\n");
+               fprintf(fd, "\n");
+       }
+
        
+       /* commit */
+       // for DEBUG only.
+       //fprintf(fd, "commit:\n"); /* DEBUG! */
+       print_tabs(2, fd);
+       fprintf(fd, "ltt_commit_slot(ltt_buf, buffer, slot_size);\n\n");
+       
+       fprintf(fd, "}\n\n");
+
+       fprintf(fd, "end:\n");
        /* Release locks */
+       print_tabs(1, fd);
+       fprintf(fd, "trace->nesting--;\n");
+
 
        fprintf(fd, "}\n");
-       fprintf(fd, "#endif //CONFIG_LTT\n\n");
+       fprintf(fd, 
+                       "#endif //LTT_TRACE\n");
+       fprintf(fd, "#endif //LTT_TRACE_FAST\n");
+
        return 0;
 }
 
 
+
+
+
+
 /* ltt-facility-name.h : main logging header.
  * log_header */
 
@@ -995,11 +2092,34 @@ void print_log_header_head(facility_t *fac, FILE *fd)
 {
        fprintf(fd, "#ifndef _LTT_FACILITY_%s_H_\n", fac->capname);
        fprintf(fd, "#define _LTT_FACILITY_%s_H_\n\n", fac->capname);
+  fprintf(fd, "#include <linux/types.h>\n");
+       if(!fac->arch)
+         fprintf(fd, "#include <linux/ltt/ltt-facility-id-%s.h>\n", fac->name);
+       else
+         fprintf(fd, "#include <asm/ltt/ltt-facility-id-%s_%s.h>\n",
+                               fac->name,
+                               fac->arch);
+  fprintf(fd, "#include <linux/ltt-core.h>\n");
        fprintf(fd, "\n");
-       fprintf(fd, "/* Facility activation at compile time. */\n");
-       fprintf(fd, "#ifdef CONFIG_LTT_FACILITY_%s\n\n", fac->capname);
 }
 
+/* ltt-facility-name.h : main logging header.
+ * log_header */
+
+void print_log_header_head_user(facility_t *fac, FILE *fd)
+{
+       fprintf(fd, "#ifndef _LTT_FACILITY_%s_H_\n", fac->capname);
+       fprintf(fd, "#define _LTT_FACILITY_%s_H_\n\n", fac->capname);
+  fprintf(fd, "#include <sys/types.h>\n");
+       if(!fac->arch)
+         fprintf(fd, "#include <ltt/ltt-facility-id-%s.h>\n", fac->name);
+       else
+         fprintf(fd, "#include <asm/ltt/ltt-facility-id-%s_%s.h>\n",
+                               fac->name,
+                               fac->arch);
+  fprintf(fd, "#include <ltt/ltt-generic.h>\n");
+       fprintf(fd, "\n");
+}
 
 
 int print_log_header_types(facility_t *fac, FILE *fd)
@@ -1010,8 +2130,14 @@ int print_log_header_types(facility_t *fac, FILE *fd)
        
        for(unsigned int i = 0; i < types->position; i++) {
                /* For each named type, print the definition */
-               if((print_type_declaration(types->array[i], fd,
-                                               0, "", ""))) return 1;
+               if(print_type_declaration(types->array[i], fd,
+                                               0, "", "")) return 1;
+               /* Print also the align function */
+               if(print_type_alignment_fct(types->array[i], fd,
+                                               0, "", "")) return 1;
+               /* Print also the write function */
+               if(print_type_write_fct(types->array[i], fd,
+                                               0, "", "")) return 1;
        }
        return 0;
 }
@@ -1038,15 +2164,28 @@ int print_log_header_events(facility_t *fac, FILE *fd)
                        /* For each unnamed type, print the definition */
                        field_t *f = (field_t*)event->fields.array[j];
                        type_descriptor_t *t = f->type;
-                       if(t->type_name == NULL)
+                       if(t->type_name == NULL) {
                                if((print_type_declaration(t, fd, 0, basename, f->name))) return 1;
+                               /* Print also the align function */
+                               if((print_type_alignment_fct(t, fd, 0, basename, f->name))) return 1;
+                               /* Print also the write function */
+                               if((print_type_write_fct(t, fd, 0, basename, f->name))) return 1;
+                       }
                }
+
                fprintf(fd, "\n");
 
                fprintf(fd, "/* Event %s logging function */\n",
                                event->name);
-
-               if(print_event_logging_function(basename, event, fd)) return 1;
+               
+               if(!fac->user) {
+                       if(print_event_logging_function(basename, fac, event, fd)) return 1;
+               } else {
+                       if(print_event_logging_function_user_generic(basename, fac, event, fd))
+                               return 1;
+                       if(print_event_logging_function_user_fast(basename, fac, event, fd))
+                               return 1;
+               }
 
                fprintf(fd, "\n");
        }
@@ -1057,7 +2196,11 @@ int print_log_header_events(facility_t *fac, FILE *fd)
 
 void print_log_header_tail(facility_t *fac, FILE *fd)
 {
-       fprintf(fd, "#endif //CONFIG_LTT_FACILITY_%s\n\n", fac->capname);
+       fprintf(fd, "#endif //_LTT_FACILITY_%s_H_\n",fac->capname);
+}
+
+void print_log_header_tail_user(facility_t *fac, FILE *fd)
+{
        fprintf(fd, "#endif //_LTT_FACILITY_%s_H_\n",fac->capname);
 }
        
@@ -1074,6 +2217,14 @@ int print_log_header(facility_t *fac)
        strncat(filename, fac->name, PATH_MAX - filename_size);
        filename_size = strlen(filename);
 
+       if(fac->arch) {
+               strncat(filename, "_", PATH_MAX - filename_size);
+               filename_size = strlen(filename);
+
+               strncat(filename, fac->arch, PATH_MAX - filename_size);
+               filename_size = strlen(filename);
+       }
+
        strncat(filename, ".h", PATH_MAX - filename_size);
        filename_size = strlen(filename);
        
@@ -1086,7 +2237,10 @@ int print_log_header(facility_t *fac)
        }
 
        /* Print file head */
-       print_log_header_head(fac, fd);
+       if(!fac->user)
+               print_log_header_head(fac, fd);
+       else
+               print_log_header_head_user(fac, fd);
 
        /* print named types in declaration order */
        if(print_log_header_types(fac, fd)) return 1;
@@ -1095,7 +2249,11 @@ int print_log_header(facility_t *fac)
        if(print_log_header_events(fac, fd)) return 1;
        
        /* Print file tail */
-       print_log_header_tail(fac, fd);
+       if(!fac->user)
+               print_log_header_tail(fac, fd);
+       else
+               print_log_header_tail_user(fac, fd);
+
 
        
        fclose(fd);
@@ -1111,6 +2269,9 @@ int print_id_header(facility_t *fac)
        char filename[PATH_MAX];
        unsigned int filename_size = 0;
        FILE *fd;
+       char basename[PATH_MAX];
+       char basename_len = 0;
+
        dprintf("%s\n", fac->name);
 
        strcpy(filename, "ltt-facility-id-");
@@ -1119,6 +2280,14 @@ int print_id_header(facility_t *fac)
        strncat(filename, fac->name, PATH_MAX - filename_size);
        filename_size = strlen(filename);
 
+       if(fac->arch) {
+               strncat(filename, "_", PATH_MAX - filename_size);
+               filename_size = strlen(filename);
+
+               strncat(filename, fac->arch, PATH_MAX - filename_size);
+               filename_size = strlen(filename);
+       }
+
        strncat(filename, ".h", PATH_MAX - filename_size);
        filename_size = strlen(filename);
        
@@ -1130,6 +2299,77 @@ int print_id_header(facility_t *fac)
                return errno;
        }
 
+       if(!fac->user) {
+               fprintf(fd, "#ifndef _LTT_FACILITY_ID_%s_H_\n",fac->capname);
+               fprintf(fd, "#define _LTT_FACILITY_ID_%s_H_\n\n",fac->capname);
+               fprintf(fd, "#ifdef CONFIG_LTT\n");
+
+               fprintf(fd,"#include <linux/ltt-facilities.h>\n\n");
+
+               fprintf(fd,"/****  facility handle  ****/\n\n");
+               fprintf(fd,"extern ltt_facility_t ltt_facility_%s_%X;\n",
+                               fac->name, fac->checksum);
+               fprintf(fd,"extern ltt_facility_t ltt_facility_%s;\n\n\n",fac->name);
+
+               strncpy(basename, fac->name, PATH_MAX);
+               basename_len = strlen(basename);
+               strncat(basename, "_", PATH_MAX - basename_len);
+               basename_len++;
+               
+               fprintf(fd,"/****  event index  ****/\n\n");
+               fprintf(fd,"enum %s_event {\n",fac->name);
+               
+               for(unsigned int i = 0; i < fac->events.position; i++) {
+                       event_t *event = (event_t*)fac->events.array[i];
+                       strncpy(basename+basename_len, event->name, PATH_MAX-basename_len);
+                       print_tabs(1, fd);
+                       fprintf(fd, "event_%s,\n", basename);
+               }
+               print_tabs(1, fd);
+               fprintf(fd, "facility_%s_num_events\n", fac->name);
+               fprintf(fd, "};\n");
+               fprintf(fd, "\n");
+
+
+               fprintf(fd, "#endif //CONFIG_LTT\n");
+               fprintf(fd, "#endif //_LTT_FACILITY_ID_%s_H_\n",fac->capname);
+       } else {
+               fprintf(fd, "#ifndef _LTT_FACILITY_ID_%s_H_\n",fac->capname);
+               fprintf(fd, "#define _LTT_FACILITY_ID_%s_H_\n\n",fac->capname);
+               fprintf(fd, "#ifdef LTT_TRACE\n");
+
+               fprintf(fd,"#include <ltt/ltt-generic.h>\n\n");
+
+               fprintf(fd,"/****  facility handle  ****/\n\n");
+               fprintf(fd,"extern ltt_facility_t ltt_facility_%s_%X;\n",
+                               fac->name, fac->checksum);
+               fprintf(fd,"extern ltt_facility_t ltt_facility_%s;\n\n\n",fac->name);
+
+               strncpy(basename, fac->name, PATH_MAX);
+               basename_len = strlen(basename);
+               strncat(basename, "_", PATH_MAX - basename_len);
+               basename_len++;
+               
+               fprintf(fd,"/****  event index  ****/\n\n");
+               fprintf(fd,"enum %s_event {\n",fac->name);
+               
+               for(unsigned int i = 0; i < fac->events.position; i++) {
+                       event_t *event = (event_t*)fac->events.array[i];
+                       strncpy(basename+basename_len, event->name, PATH_MAX-basename_len);
+                       print_tabs(1, fd);
+                       fprintf(fd, "event_%s,\n", basename);
+               }
+               print_tabs(1, fd);
+               fprintf(fd, "facility_%s_num_events\n", fac->name);
+               fprintf(fd, "};\n");
+               fprintf(fd, "\n");
+
+
+               fprintf(fd, "#endif //LTT_TRACE\n");
+               fprintf(fd, "#endif //_LTT_FACILITY_ID_%s_H_\n",fac->capname);
+       }
+
+
        fclose(fd);
 
        return 0;
@@ -1151,6 +2391,77 @@ int print_loader_header(facility_t *fac)
        strncat(filename, fac->name, PATH_MAX - filename_size);
        filename_size = strlen(filename);
 
+       if(fac->arch) {
+               strncat(filename, "_", PATH_MAX - filename_size);
+               filename_size = strlen(filename);
+
+               strncat(filename, fac->arch, PATH_MAX - filename_size);
+               filename_size = strlen(filename);
+       }
+
+       strncat(filename, ".h", PATH_MAX - filename_size);
+       filename_size = strlen(filename);
+       
+
+       fd = fopen(filename, "w");
+       if(fd == NULL) {
+               printf("Error opening file %s for writing : %s\n",
+                               filename, strerror(errno));
+               return errno;
+       }
+
+  fprintf(fd, "#ifndef _LTT_FACILITY_LOADER_%s_H_\n", fac->capname);
+  fprintf(fd, "#define _LTT_FACILITY_LOADER_%s_H_\n\n", fac->capname);
+  fprintf(fd, "#ifdef CONFIG_LTT\n\n");
+  fprintf(fd,"#include <linux/ltt-facilities.h>\n");
+       if(!fac->arch)
+         fprintf(fd,"#include <linux/ltt/ltt-facility-id-%s.h>\n\n",
+                               fac->name);
+       else
+         fprintf(fd,"#include <asm/ltt/ltt-facility-id-%s_%s.h>\n\n",
+                               fac->name,
+                               fac->arch);
+  fprintf(fd,"ltt_facility_t\tltt_facility_%s;\n", fac->name);
+  fprintf(fd,"ltt_facility_t\tltt_facility_%s_%X;\n\n",
+                       fac->name, fac->checksum);
+
+  fprintf(fd,"#define LTT_FACILITY_SYMBOL\t\t\t\t\t\t\tltt_facility_%s\n",
+      fac->name);
+  fprintf(fd,"#define LTT_FACILITY_CHECKSUM_SYMBOL\t\tltt_facility_%s_%X\n",
+      fac->name, fac->checksum);
+  fprintf(fd,"#define LTT_FACILITY_CHECKSUM\t\t\t\t\t\t0x%X\n", fac->checksum);
+  fprintf(fd,"#define LTT_FACILITY_NAME\t\t\t\t\t\t\t\t\"%s\"\n", fac->name);
+  fprintf(fd,"#define LTT_FACILITY_NUM_EVENTS\t\t\t\t\tfacility_%s_num_events\n\n",
+                       fac->name);
+  fprintf(fd, "#endif //CONFIG_LTT\n\n");
+  fprintf(fd, "#endif //_LTT_FACILITY_LOADER_%s_H_\n", fac->capname);
+
+       fclose(fd);
+
+       return 0;
+}
+
+int print_loader_header_user(facility_t *fac)
+{
+       char filename[PATH_MAX];
+       unsigned int filename_size = 0;
+       FILE *fd;
+       dprintf("%s\n", fac->name);
+
+       strcpy(filename, "ltt-facility-loader-");
+       filename_size = strlen(filename);
+       
+       strncat(filename, fac->name, PATH_MAX - filename_size);
+       filename_size = strlen(filename);
+
+       if(fac->arch) {
+               strncat(filename, "_", PATH_MAX - filename_size);
+               filename_size = strlen(filename);
+
+               strncat(filename, fac->arch, PATH_MAX - filename_size);
+               filename_size = strlen(filename);
+       }
+
        strncat(filename, ".h", PATH_MAX - filename_size);
        filename_size = strlen(filename);
        
@@ -1162,12 +2473,38 @@ int print_loader_header(facility_t *fac)
                return errno;
        }
 
+  fprintf(fd, "#ifndef _LTT_FACILITY_LOADER_%s_H_\n", fac->capname);
+  fprintf(fd, "#define _LTT_FACILITY_LOADER_%s_H_\n\n", fac->capname);
+  fprintf(fd,"#include <ltt/ltt-generic.h>\n");
+       if(!fac->arch)
+         fprintf(fd,"#include <ltt/ltt-facility-id-%s.h>\n\n",
+                               fac->name);
+       else
+         fprintf(fd,"#include <asm/ltt/ltt-facility-id-%s_%s.h>\n\n",
+                               fac->name,
+                               fac->arch);
+  fprintf(fd,"ltt_facility_t\tltt_facility_%s;\n", fac->name);
+  fprintf(fd,"ltt_facility_t\tltt_facility_%s_%X;\n\n",
+                       fac->name, fac->checksum);
+
+  fprintf(fd,"#define LTT_FACILITY_SYMBOL\t\t\t\t\t\t\tltt_facility_%s\n",
+      fac->name);
+  fprintf(fd,"#define LTT_FACILITY_CHECKSUM_SYMBOL\t\tltt_facility_%s_%X\n",
+      fac->name, fac->checksum);
+  fprintf(fd,"#define LTT_FACILITY_CHECKSUM\t\t\t\t\t\t0x%X\n", fac->checksum);
+  fprintf(fd,"#define LTT_FACILITY_NAME\t\t\t\t\t\t\t\t\"%s\"\n", fac->name);
+  fprintf(fd,"#define LTT_FACILITY_NUM_EVENTS\t\t\t\t\tfacility_%s_num_events\n\n",
+                       fac->name);
+  fprintf(fd, "#endif //_LTT_FACILITY_LOADER_%s_H_\n", fac->capname);
+
        fclose(fd);
 
        return 0;
 }
 
-/* ltt-facility-loader-name.c : generic faciilty loader
+
+
+/* ltt-facility-loader-name.c : generic facility loader
  * loader_c */
 int print_loader_c(facility_t *fac)
 {
@@ -1182,6 +2519,127 @@ int print_loader_c(facility_t *fac)
        strncat(filename, fac->name, PATH_MAX - filename_size);
        filename_size = strlen(filename);
 
+       if(fac->arch) {
+               strncat(filename, "_", PATH_MAX - filename_size);
+               filename_size = strlen(filename);
+
+               strncat(filename, fac->arch, PATH_MAX - filename_size);
+               filename_size = strlen(filename);
+       }
+
+       strncat(filename, ".c", PATH_MAX - filename_size);
+       filename_size = strlen(filename);
+       
+
+       fd = fopen(filename, "w");
+       if(fd == NULL) {
+               printf("Error opening file %s for writing : %s\n",
+                               filename, strerror(errno));
+               return errno;
+       }
+
+  fprintf(fd, "/*\n");
+       if(!fac->arch)
+         fprintf(fd, " * ltt-facility-loader-%s.c\n", fac->name);
+       else
+         fprintf(fd, " * ltt-facility-loader-%s_%s.c\n", fac->name, fac->arch);
+  fprintf(fd, " *\n");
+  fprintf(fd, " * (C) Copyright  2005 - \n");
+  fprintf(fd, " *          Mathieu Desnoyers (mathieu.desnoyers@polymtl.ca)\n");
+  fprintf(fd, " *\n");
+  fprintf(fd, " * Contains the LTT facility loader.\n");
+  fprintf(fd, " *\n");
+  fprintf(fd, " */\n");
+  fprintf(fd, "\n");
+  fprintf(fd, "\n");
+  fprintf(fd, "#include <linux/ltt-facilities.h>\n");
+  fprintf(fd, "#include <linux/module.h>\n");
+  fprintf(fd, "#include <linux/init.h>\n");
+  fprintf(fd, "#include <linux/config.h>\n");
+       if(!fac->arch)
+       fprintf(fd, "#include \"ltt-facility-loader-%s.h\"\n", fac->name);
+       else
+         fprintf(fd, "#include \"ltt-facility-loader-%s_%s.h\"\n",
+                               fac->name, fac->arch);
+  fprintf(fd, "\n");
+  fprintf(fd, "\n");
+  fprintf(fd, "#ifdef CONFIG_LTT\n");
+  fprintf(fd, "\n");
+  fprintf(fd, "EXPORT_SYMBOL(LTT_FACILITY_SYMBOL);\n");
+  fprintf(fd, "EXPORT_SYMBOL(LTT_FACILITY_CHECKSUM_SYMBOL);\n");
+  fprintf(fd, "\n");
+  fprintf(fd, "static const char ltt_facility_name[] = LTT_FACILITY_NAME;\n");
+  fprintf(fd, "\n");
+  fprintf(fd, "#define SYMBOL_STRING(sym) #sym\n");
+  fprintf(fd, "\n");
+  fprintf(fd, "static struct ltt_facility facility = {\n");
+  fprintf(fd, "\t.name = ltt_facility_name,\n");
+  fprintf(fd, "\t.num_events = LTT_FACILITY_NUM_EVENTS,\n");
+  fprintf(fd, "\t.checksum = LTT_FACILITY_CHECKSUM,\n");
+  fprintf(fd, "\t.symbol = SYMBOL_STRING(LTT_FACILITY_SYMBOL),\n");
+  fprintf(fd, "};\n");
+  fprintf(fd, "\n");
+  fprintf(fd, "static int __init facility_init(void)\n");
+  fprintf(fd, "{\n");
+  fprintf(fd, "\tprintk(KERN_INFO \"LTT : ltt-facility-%s init in kernel\\n\");\n", fac->name);
+  fprintf(fd, "\n");
+  fprintf(fd, "\tLTT_FACILITY_SYMBOL = ltt_facility_kernel_register(&facility);\n");
+  fprintf(fd, "\tLTT_FACILITY_CHECKSUM_SYMBOL = LTT_FACILITY_SYMBOL;\n");
+  fprintf(fd, "\t\n");
+  fprintf(fd, "\treturn LTT_FACILITY_SYMBOL;\n");
+  fprintf(fd, "}\n");
+  fprintf(fd, "__initcall(facility_init);\n");
+  fprintf(fd, "\n");
+  fprintf(fd, "\n");
+  fprintf(fd, "#ifndef MODULE\n");
+  fprintf(fd, "\n");
+  fprintf(fd, "static void __exit facility_exit(void)\n");
+  fprintf(fd, "{\n");
+  fprintf(fd, "\tint err;\n");
+  fprintf(fd, "\n");
+  fprintf(fd, "\terr = ltt_facility_unregister(LTT_FACILITY_SYMBOL);\n");
+  fprintf(fd, "\tif(err != 0)\n");
+  fprintf(fd, "\t\tprintk(KERN_ERR \"LTT : Error in unregistering facility.\\n\");\n");
+  fprintf(fd, "\n");
+  fprintf(fd, "}\n");
+  fprintf(fd, "\n");
+  fprintf(fd, "module_exit(facility_exit)\n");
+  fprintf(fd, "\n");
+  fprintf(fd, "\n");
+  fprintf(fd, "MODULE_LICENSE(\"GPL\");\n");
+  fprintf(fd, "MODULE_AUTHOR(\"Mathieu Desnoyers\");\n");
+  fprintf(fd, "MODULE_DESCRIPTION(\"Linux Trace Toolkit Facility\");\n");
+  fprintf(fd, "\n");
+  fprintf(fd, "#endif //MODULE\n");
+  fprintf(fd, "\n");
+  fprintf(fd, "#endif //CONFIG_LTT\n");
+
+       fclose(fd);
+
+       return 0;
+}
+
+int print_loader_c_user(facility_t *fac)
+{
+       char filename[PATH_MAX];
+       unsigned int filename_size = 0;
+       FILE *fd;
+       dprintf("%s\n", fac->name);
+
+       strcpy(filename, "ltt-facility-loader-");
+       filename_size = strlen(filename);
+       
+       strncat(filename, fac->name, PATH_MAX - filename_size);
+       filename_size = strlen(filename);
+
+       if(fac->arch) {
+               strncat(filename, "_", PATH_MAX - filename_size);
+               filename_size = strlen(filename);
+
+               strncat(filename, fac->arch, PATH_MAX - filename_size);
+               filename_size = strlen(filename);
+       }
+
        strncat(filename, ".c", PATH_MAX - filename_size);
        filename_size = strlen(filename);
        
@@ -1193,6 +2651,62 @@ int print_loader_c(facility_t *fac)
                return errno;
        }
 
+  fprintf(fd, "/*\n");
+       if(!fac->arch)
+         fprintf(fd, " * ltt-facility-loader-%s.c\n", fac->name);
+       else
+         fprintf(fd, " * ltt-facility-loader-%s_%s.c\n", fac->name, fac->arch);
+  fprintf(fd, " *\n");
+  fprintf(fd, " * (C) Copyright  2005 - \n");
+  fprintf(fd, " *          Mathieu Desnoyers (mathieu.desnoyers@polymtl.ca)\n");
+  fprintf(fd, " *\n");
+  fprintf(fd, " * Contains the LTT user space facility loader.\n");
+  fprintf(fd, " *\n");
+  fprintf(fd, " */\n");
+  fprintf(fd, "\n");
+  fprintf(fd, "\n");
+  fprintf(fd, "#define LTT_TRACE\n");
+  fprintf(fd, "#include <error.h>\n");
+  fprintf(fd, "#include <stdio.h>\n");
+  fprintf(fd, "#include <ltt/ltt-generic.h>\n");
+       if(!fac->arch)
+       fprintf(fd, "#include \"ltt-facility-loader-%s.h\"\n", fac->name);
+       else
+         fprintf(fd, "#include \"ltt-facility-loader-%s_%s.h\"\n",
+                               fac->name, fac->arch);
+  fprintf(fd, "\n");
+  fprintf(fd, "static struct user_facility_info facility = {\n");
+  fprintf(fd, "\t.name = LTT_FACILITY_NAME,\n");
+  fprintf(fd, "\t.num_events = LTT_FACILITY_NUM_EVENTS,\n");
+  fprintf(fd, "#ifndef LTT_PACK\n");
+  fprintf(fd, "\t.alignment = sizeof(void*),\n");
+  fprintf(fd, "#else\n");
+  fprintf(fd, "\t.alignment = 0,\n");
+  fprintf(fd, "#endif //LTT_PACK\n");
+  fprintf(fd, "\t.checksum = LTT_FACILITY_CHECKSUM,\n");
+  fprintf(fd, "\t.int_size = sizeof(int),\n");
+  fprintf(fd, "\t.long_size = sizeof(long),\n");
+  fprintf(fd, "\t.pointer_size = sizeof(void*),\n");
+  fprintf(fd, "\t.size_t_size = sizeof(size_t)\n");
+  fprintf(fd, "};\n");
+  fprintf(fd, "\n");
+  fprintf(fd, "static void __attribute__((constructor)) __ltt_user_init(void)\n");
+  fprintf(fd, "{\n");
+  fprintf(fd, "\tint err;\n");
+       fprintf(fd, "#ifdef LTT_SHOW_DEBUG\n");
+  fprintf(fd, "\tprintf(\"LTT : ltt-facility-%s init in userspace\\n\");\n", fac->name);
+       fprintf(fd, "#endif //LTT_SHOW_DEBUG\n");
+  fprintf(fd, "\n");
+  fprintf(fd, "\terr = ltt_register_generic(&LTT_FACILITY_SYMBOL, &facility);\n");
+  fprintf(fd, "\tLTT_FACILITY_CHECKSUM_SYMBOL = LTT_FACILITY_SYMBOL;\n");
+  fprintf(fd, "\t\n");
+  fprintf(fd, "\tif(err) {\n");
+       fprintf(fd, "#ifdef LTT_SHOW_DEBUG\n");
+  fprintf(fd, "\t\tperror(\"Error in ltt_register_generic\");\n");
+       fprintf(fd, "#endif //LTT_SHOW_DEBUG\n");
+  fprintf(fd, "\t}\n");
+  fprintf(fd, "}\n");
+  fprintf(fd, "\n");
 
        fclose(fd);
 
@@ -1220,7 +2734,6 @@ facility_t *ltt_facility_open(char * pathname)
        char *token;
        parse_file_t in;
        facility_t * fac = NULL;
-       unsigned long checksum;
        char buffer[BUFFER_SIZE];
        int generated = FALSE;
 
@@ -1261,7 +2774,7 @@ facility_t *ltt_facility_open(char * pathname)
                        //check if any namedType is not defined
                        checkNamedTypesImplemented(&fac->named_types);
                
-                       generateChecksum(fac->name, &checksum, &fac->events);
+                       generateChecksum(fac->name, &fac->checksum, &fac->events);
                        
                        generated = TRUE;
                }
@@ -1369,12 +2882,18 @@ int main(int argc, char **argv)
        
        /* ltt-facility-loader-name.h : facility specific loader info.
         * loader_header */
-       err = print_loader_header(fac);
+       if(!fac->user)
+               err = print_loader_header(fac);
+       else
+               err = print_loader_header_user(fac);
        if(err) return err;
 
        /* ltt-facility-loader-name.c : generic faciilty loader
         * loader_c */
-       err = print_loader_c(fac);
+       if(!fac->user)
+               err = print_loader_c(fac);
+       else
+               err = print_loader_c_user(fac);
        if(err) return err;
 
        /* close the facility */
This page took 0.052304 seconds and 4 git commands to generate.