00001 00014 #include "op_abi.h" 00015 #include "odb.h" 00016 #include "op_sample_file.h" 00017 00018 #include <stdio.h> 00019 #include <stddef.h> 00020 #include <assert.h> 00021 00022 static struct op_abi_entry const abi_entries[] = { 00023 { "sizeof_double", sizeof(double) }, 00024 { "sizeof_u64", sizeof(u64) }, 00025 { "sizeof_u8", sizeof(u8) }, 00026 { "sizeof_u32", sizeof(u32) }, 00027 { "sizeof_int", sizeof(int) }, 00028 { "sizeof_unsigned_int", sizeof(unsigned int) }, 00029 { "sizeof_odb_key_t", sizeof(odb_key_t) }, 00030 { "sizeof_odb_index_t", sizeof(odb_index_t) }, 00031 { "sizeof_odb_value_t", sizeof(odb_value_t) }, 00032 { "sizeof_odb_node_nr_t", sizeof(odb_node_nr_t) }, 00033 { "sizeof_odb_descr_t", sizeof(odb_descr_t) }, 00034 { "sizeof_odb_node_t", sizeof(odb_node_t) }, 00035 { "sizeof_struct_opd_header", sizeof(struct opd_header) }, 00036 00037 { "offsetof_node_key", offsetof(odb_node_t, key) }, 00038 { "offsetof_node_value", offsetof(odb_node_t, value) }, 00039 { "offsetof_node_next", offsetof(odb_node_t, next) }, 00040 00041 { "offsetof_descr_size", offsetof(odb_descr_t, size) }, 00042 { "offsetof_descr_current_size", offsetof(odb_descr_t, current_size) }, 00043 00044 { "offsetof_header_magic", offsetof(struct opd_header, magic) }, 00045 { "offsetof_header_version", offsetof(struct opd_header, version) }, 00046 { "offsetof_header_cpu_type", offsetof(struct opd_header, cpu_type) }, 00047 { "offsetof_header_ctr_event", offsetof(struct opd_header, ctr_event) }, 00048 { "offsetof_header_ctr_um", offsetof(struct opd_header, ctr_um) }, 00049 { "offsetof_header_ctr_count", offsetof(struct opd_header, ctr_count) }, 00050 { "offsetof_header_is_kernel", offsetof(struct opd_header, is_kernel) }, 00051 { "offsetof_header_cpu_speed", offsetof(struct opd_header, cpu_speed) }, 00052 { "offsetof_header_mtime", offsetof(struct opd_header, mtime) }, 00053 { "offsetof_header_cg_to_is_kernel", offsetof(struct opd_header, cg_to_is_kernel), }, 00054 { "offsetof_header_anon_start", offsetof(struct opd_header, anon_start) }, 00055 { "offsetof_header_cg_to_anon_start", offsetof(struct opd_header, cg_to_anon_start) }, 00056 00057 { NULL, 0 }, 00058 }; 00059 00060 00061 struct op_abi_entry const * get_abi(void) 00062 { 00063 return abi_entries; 00064 } 00065 00066 00067 int op_little_endian(void) 00068 { 00069 unsigned int probe = 0xff; 00070 size_t sz = sizeof(unsigned int); 00071 unsigned char * probe_byte = (unsigned char *)&probe; 00072 00073 assert(probe_byte[0] == 0xff || probe_byte[sz - 1] == 0xff); 00074 00075 return probe_byte[0] == 0xff; 00076 } 00077 00078 00079 int op_write_abi_to_file(char const * abi_file) 00080 { 00081 FILE * fp; 00082 struct op_abi_entry const * abi_entry; 00083 00084 if ((fp = fopen(abi_file, "w")) == NULL) 00085 return 0; 00086 00087 for (abi_entry = get_abi() ; abi_entry->name != NULL; ++abi_entry) 00088 fprintf(fp, "%s %u\n", abi_entry->name, abi_entry->offset); 00089 fprintf(fp, "little_endian %d\n", op_little_endian()); 00090 00091 fclose(fp); 00092 00093 return 1; 00094 }