X-Git-Url: http://git.lttng.org/?a=blobdiff_plain;f=genevent-new%2Fgenevent.c;h=38f9f14aeaa3415e56c6d77a308f22bd1f2d8da9;hb=c7926a2af9383011defbd5a2662295d1d7f54263;hp=ddf8e4ecd7c7e6a59701f0318e541cf1f1ddc3ff;hpb=3261899d4f28b2cd80fc86b05499c986dba7b6e7;p=lttv.git diff --git a/genevent-new/genevent.c b/genevent-new/genevent.c index ddf8e4ec..38f9f14a 100644 --- a/genevent-new/genevent.c +++ b/genevent-new/genevent.c @@ -151,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"); @@ -224,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, "const char *"); - fprintf(fd, " %s", field_name); + 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"); @@ -386,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); @@ -411,7 +413,8 @@ int print_type_declaration(type_descriptor_t * td, FILE *fd, unsigned int tabs, fprintf(fd, " {\n"); for(unsigned int i=0;ilabels.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"); @@ -453,6 +456,7 @@ int print_type_declaration(type_descriptor_t * td, FILE *fd, unsigned int tabs, 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"); @@ -570,7 +574,30 @@ int print_type_alignment(type_descriptor_t * td, FILE *fd, unsigned int tabs, 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; @@ -636,10 +663,12 @@ int print_type_alignment(type_descriptor_t * td, FILE *fd, unsigned int tabs, * (possibly)). */ int print_type_write(type_descriptor_t * td, FILE *fd, unsigned int tabs, - char *nest_name, char *field_name, char *obj_prefix) + char *nest_name, char *field_name, char *obj_prefix, int get_ptr) { char basename[PATH_MAX]; unsigned int basename_len = 0; + char get_ptr_char[2] = ""; + char custom[PATH_MAX] = ""; strncpy(basename, nest_name, PATH_MAX); basename_len = strlen(basename); @@ -660,6 +689,14 @@ int print_type_write(type_descriptor_t * td, FILE *fd, unsigned int tabs, strncat(basename, field_name, PATH_MAX - basename_len); } + if(get_ptr) { + strcpy(get_ptr_char, "&"); + } + + if(td->custom_write) { + strcpy(custom, "_custom"); + } + switch(td->type) { case INT_FIXED: case UINT_FIXED: @@ -678,44 +715,103 @@ int print_type_write(type_descriptor_t * td, FILE *fd, unsigned int tabs, case OFF_T: case ENUM: print_tabs(tabs, fd); - fprintf(fd, "size = "); + 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, "*len += "); fprintf(fd, "sizeof("); if(print_type(td, fd, 0, basename, "")) return 1; fprintf(fd, ");\n"); - print_tabs(tabs, fd); - fprintf(fd, "size += ltt_align(*to+*len, size) + size;\n"); - print_tabs(tabs, fd); - fprintf(fd, "*len += size;"); + break; case STRING: print_tabs(tabs, fd); fprintf(fd, - "lttng_write_string_%s(buffer, to_base, to, from, len, %s%s);\n", - basename, obj_prefix, field_name); + "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(buffer, to_base, to, from, len, &%s%s)", - basename, obj_prefix, field_name); + "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_struct_%s(buffer, to_base, to, from, len, &%s%s)", - basename, obj_prefix, field_name); + "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_union_%s(buffer, to_base, to, from, len, &%s%s)", - basename, obj_prefix, field_name); + "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: print_tabs(tabs, fd); fprintf(fd, - "lttng_write_array_%s(buffer, to_base, to, from, len, %s%s)", - basename, obj_prefix, field_name); + "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; + } + + return 0; +} + +/* 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. + */ + +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: + case STRUCT: + case UNION: + case ARRAY: + return 0; break; case NONE: printf("Error : type NONE unexpected\n"); @@ -742,6 +838,8 @@ int print_type_alignment_fct(type_descriptor_t * td, FILE *fd, 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); @@ -888,6 +986,8 @@ int print_type_write_fct(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); @@ -912,6 +1012,7 @@ int print_type_write_fct(type_descriptor_t * td, FILE *fd, unsigned int tabs, case STRUCT: case UNION: case ARRAY: + case STRING: break; default: dprintf("print_type_write_fct : type has no write function.\n"); @@ -934,6 +1035,9 @@ int print_type_write_fct(type_descriptor_t * td, FILE *fd, unsigned int tabs, 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; @@ -946,7 +1050,7 @@ int print_type_write_fct(type_descriptor_t * td, FILE *fd, unsigned int tabs, print_tabs(2, fd); fprintf(fd, "size_t *to,\n"); print_tabs(2, fd); - fprintf(fd, "void **from,\n"); + fprintf(fd, "const void **from,\n"); print_tabs(2, fd); fprintf(fd, "size_t *len,\n"); print_tabs(2, fd); @@ -965,14 +1069,27 @@ int print_type_write_fct(type_descriptor_t * td, FILE *fd, unsigned int tabs, 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, size;\n"); + fprintf(fd, "size_t align;\n"); fprintf(fd, "\n"); switch(td->type) { @@ -1005,7 +1122,7 @@ int print_type_write_fct(type_descriptor_t * td, FILE *fd, unsigned int tabs, print_tabs(1, fd); fprintf(fd, "align = "); - if(print_type_alignment(td, fd, 0, basename, "", "obj->")) return 1; + if(print_type_alignment(td, fd, 0, basename, "", "obj")) return 1; fprintf(fd, ";\n"); fprintf(fd, "\n"); print_tabs(1, fd); @@ -1027,11 +1144,9 @@ int print_type_write_fct(type_descriptor_t * td, FILE *fd, unsigned int tabs, fprintf(fd, "/* Contains only fixed size fields : use compiler sizeof() */\n"); fprintf(fd, "\n"); print_tabs(1, fd); - fprintf(fd, "size = sizeof("); + fprintf(fd, "*len += sizeof("); if(print_type(td, fd, 0, basename, field_name)) return 1; fprintf(fd, ");\n"); - print_tabs(1, fd); - fprintf(fd, "*len += size;\n"); } else { /* The type contains nested variable size subtypes : * we must write field by field. */ @@ -1046,7 +1161,7 @@ int print_type_write_fct(type_descriptor_t * td, FILE *fd, unsigned int tabs, // 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->")) return 1; + fd, 1, basename, "len", "obj->", 1)) return 1; fprintf(fd, "\n"); // fprintf(fd, ");\n"); // print_tabs(1, fd); @@ -1054,29 +1169,37 @@ int print_type_write_fct(type_descriptor_t * td, FILE *fd, unsigned int tabs, print_tabs(1, fd); fprintf(fd, "if(buffer != NULL)\n"); print_tabs(2, fd); - fprintf(fd, "memcpy(buffer+*to_base+*to, &obj->len, size);\n"); + fprintf(fd, "memcpy(buffer+*to_base+*to, &obj->len, *len);\n"); print_tabs(1, fd); - fprintf(fd, "*to += size;\n"); + 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->")) return 1; + fd, 1, basename, "array[0]", "obj->", 1)) + return 1; // fprintf(fd, ");\n"); -// print_tabs(1, fd); - fprintf(fd, "*to += ltt_align(*to, size);\n"); + fprintf(fd, "\n"); print_tabs(1, fd); - fprintf(fd, "size = obj->len * size;\n"); + 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, size);\n"); + fprintf(fd, "memcpy(buffer+*to_base+*to, obj->array, *len);\n"); print_tabs(1, fd); - fprintf(fd, "*to += size;\n"); + fprintf(fd, "*to += *len;\n"); + print_tabs(1, fd); + fprintf(fd, "*len = 0;\n"); fprintf(fd, "\n"); } else { print_tabs(1, fd); @@ -1084,7 +1207,7 @@ int print_type_write_fct(type_descriptor_t * td, FILE *fd, unsigned int tabs, print_tabs(1, fd); fprintf(fd, "for(unsigned int i=0; ilen; i++) {\n"); if(print_type_write(((field_t*)td->fields.array[1])->type, - fd, 2, basename, "array[i]", "obj->")) return 1; + fd, 2, basename, "array[i]", "obj->", 1)) return 1; print_tabs(1, fd); fprintf(fd, "}\n"); } @@ -1092,17 +1215,19 @@ int print_type_write_fct(type_descriptor_t * td, FILE *fd, unsigned int tabs, 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"); + 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"); @@ -1114,22 +1239,23 @@ int print_type_write_fct(type_descriptor_t * td, FILE *fd, unsigned int tabs, 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"); + 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"); - fprintf(fd, "/* Put source *from just after the C sequence */\n"); print_tabs(1, fd); - fprintf(fd, "*from = obj+1;\n"); + 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;ifields.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->")) return 1; + fd, 1, basename, field->name, "obj->", 1)) return 1; fprintf(fd, "\n"); } break; @@ -1149,7 +1275,7 @@ int print_type_write_fct(type_descriptor_t * td, FILE *fd, unsigned int tabs, print_tabs(1, fd); fprintf(fd, "for(unsigned int i=0; ifields.array[0])->type, - fd, 2, basename, "", "obj->array[i]")) return 1; + fd, 2, basename, "", "obj->array[i]", 1)) return 1; print_tabs(1, fd); fprintf(fd, "}\n"); } @@ -1177,6 +1303,7 @@ int print_event_logging_function(char *basename, facility_t *fac, { 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) { @@ -1230,21 +1357,46 @@ int print_event_logging_function(char *basename, facility_t *fac, print_tabs(1, fd); fprintf(fd, "void *buffer = NULL;\n"); print_tabs(1, fd); - fprintf(fd, "size_t to_base = 0; /* The buffer is allocated on arch_size alignment */\n"); + 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 = 0;\n"); + fprintf(fd, "size_t *to = &real_to;\n"); print_tabs(1, fd); - fprintf(fd, "void *from;"); + fprintf(fd, "size_t real_len = 0;\n"); print_tabs(1, fd); - fprintf(fd, "size_t len = 0;\n"); + 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); - fprintf(fd, "cycles_t tsc;\n"); + + if(event->fields.position > 0) { + for(unsigned int i=0;ifields.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, size_t after_hdr_pad;\n"); + fprintf(fd, "size_t before_hdr_pad, after_hdr_pad, header_size;\n"); fprintf(fd, "\n"); print_tabs(1, fd); @@ -1259,7 +1411,7 @@ int print_event_logging_function(char *basename, facility_t *fac, 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"); + 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); @@ -1269,15 +1421,27 @@ int print_event_logging_function(char *basename, facility_t *fac, for(unsigned int i=0;ifields.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 = <tng_param_%s;\n", field->name); + break; + } + if(print_type_write(type, - fd, 1, basename, field->name, "")) return 1; + 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, "to_base = to = len = 0;\n"); - fprintf(fd, "\n"); + 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). */ @@ -1295,8 +1459,8 @@ int print_event_logging_function(char *basename, facility_t *fac, print_tabs(1, fd); fprintf(fd, "index = ltt_get_index_from_facility(ltt_facility_%s_%X,\n"\ - "\t\t\t\t\t\tevent_%s);\n", - fac->name, fac->checksum, event->name); + "\t\t\t\t\t\tevent_%s_%s);\n", + fac->name, fac->checksum, fac->name, event->name); } fprintf(fd,"\n"); @@ -1315,7 +1479,7 @@ int print_event_logging_function(char *basename, facility_t *fac, 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[channel->rchan->buf->cpu];\n"); + fprintf(fd, "relayfs_buf = channel->rchan->buf[smp_processor_id()];\n"); fprintf(fd, "\n"); @@ -1329,17 +1493,35 @@ int print_event_logging_function(char *basename, facility_t *fac, print_tabs(3, fd); fprintf(fd, "reserve_size, &slot_size, &tsc,\n"); print_tabs(3, fd); - fprintf(fd, "&before_hdr_pad, &after_hdr_pad);\n"); + fprintf(fd, "&before_hdr_pad, &after_hdr_pad, &header_size);\n"); /* If error, return */ print_tabs(2, fd); - fprintf(fd, "if(!buffer) return;\n\n"); + 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 : assume stack alignment is the same as struct alignment. */ + /* write data. */ for(unsigned int i=0;ifields.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) { @@ -1348,31 +1530,31 @@ int print_event_logging_function(char *basename, facility_t *fac, case ARRAY: case STRUCT: case STRING: - fprintf(fd, "from = %s;\n", field->name); + fprintf(fd, "*from = lttng_param_%s;\n", field->name); break; default: - fprintf(fd, "from = &%s;\n", field->name); + fprintf(fd, "*from = <tng_param_%s;\n", field->name); break; } if(print_type_write(type, - fd, 2, basename, field->name, "")) return 1; + 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"); + fprintf(fd, "if(*len != 0) {\n"); print_tabs(3, fd); - fprintf(fd, "memcpy(buffer+to_base+to, from, len);\n"); + fprintf(fd, "memcpy(buffer+*to_base+*to, *from, *len);\n"); print_tabs(3, fd); - fprintf(fd, "to += len;\n"); + fprintf(fd, "*to += *len;\n"); //print_tabs(3, fd); //fprintf(fd, "from += len;\n"); print_tabs(3, fd); - fprintf(fd, "len = 0;\n"); + fprintf(fd, "*len = 0;\n"); print_tabs(2, fd); fprintf(fd, "}\n"); fprintf(fd, "\n"); @@ -1380,6 +1562,8 @@ int print_event_logging_function(char *basename, facility_t *fac, /* 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"); @@ -1407,7 +1591,12 @@ 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 \n"); - fprintf(fd, "#include \n", fac->name); + if(!fac->arch) + fprintf(fd, "#include \n", fac->name); + else + fprintf(fd, "#include \n", + fac->name, + fac->arch); fprintf(fd, "#include \n"); fprintf(fd, "\n"); } @@ -1422,14 +1611,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; + 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; + if(print_type_write_fct(types->array[i], fd, + 0, "", "")) return 1; } return 0; } @@ -1497,6 +1686,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); @@ -1545,6 +1742,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); @@ -1612,6 +1817,14 @@ 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); @@ -1627,8 +1840,13 @@ int print_loader_header(facility_t *fac) fprintf(fd, "#define _LTT_FACILITY_LOADER_%s_H_\n\n", fac->capname); fprintf(fd, "#ifdef CONFIG_LTT\n\n"); fprintf(fd,"#include \n"); - fprintf(fd,"#include \n\n", - fac->name); + if(!fac->arch) + fprintf(fd,"#include \n\n", + fac->name); + else + fprintf(fd,"#include \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); @@ -1664,6 +1882,14 @@ 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); @@ -1676,7 +1902,10 @@ int print_loader_c(facility_t *fac) } fprintf(fd, "/*\n"); - fprintf(fd, " * ltt-facility-loader-%s.c\n", fac->name); + 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"); @@ -1690,7 +1919,11 @@ int print_loader_c(facility_t *fac) fprintf(fd, "#include \n"); fprintf(fd, "#include \n"); fprintf(fd, "#include \n"); - fprintf(fd, "#include \"ltt-facility-loader-%s.h\"\n", fac->name); + 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");