opd_extended.c

Go to the documentation of this file.
00001 
00012 #include "opd_extended.h"
00013 #include "op_string.h"
00014 
00015 #include <string.h>
00016 #include <stdio.h>
00017 
00018 /* This global variable is >= 0
00019  * if extended feature is enabled */
00020 static int opd_ext_feat_index;
00021 
00022 extern struct opd_ext_handlers ibs_handlers;
00023 
00029 static struct opd_ext_feature ext_feature_table[] = {
00030     {"ibs", &ibs_handlers },
00031     { NULL, NULL }
00032 };
00033 
00034 
00035 static int get_index_for_feature(char const * name)
00036 {
00037     int ret = -1;
00038     unsigned int i;
00039 
00040     if(!name)
00041         return ret;
00042 
00043     for (i = 0 ; ext_feature_table[i].feature != NULL ; i++ ) {
00044         if(!strncmp(name, ext_feature_table[i].feature,
00045             strlen(ext_feature_table[i].feature))) {
00046             ret = i;
00047             break;
00048         }
00049     }
00050 
00051     return ret;
00052 }
00053 
00054 
00055 static inline int is_ext_enabled()
00056 {
00057     if (opd_ext_feat_index >= 0
00058     && ext_feature_table[opd_ext_feat_index].handlers != NULL)
00059         return 1;
00060     else
00061         return 0;
00062 }
00063 
00064 
00065 static inline int is_ext_sfile_enabled()
00066 {
00067     if (opd_ext_feat_index >= 0
00068     && ext_feature_table[opd_ext_feat_index].handlers != NULL
00069     && ext_feature_table[opd_ext_feat_index].handlers->ext_sfile != NULL)
00070         return 1;
00071     else
00072         return 0;
00073 }
00074 
00075 
00083 int opd_ext_initialize(char const * value)
00084 {
00085     int ret = EXIT_FAILURE;
00086     char * tmp = NULL, * name = NULL, * args = NULL;
00087 
00088     if(!value) {
00089         opd_ext_feat_index = -1;
00090         return 0;
00091     }
00092 
00093     tmp = op_xstrndup(value, strlen(value));
00094 
00095     /* Parse feature name*/
00096     if((name = strtok_r(tmp, ":", &args)) == NULL)
00097         goto err_out;
00098 
00099     if((opd_ext_feat_index = get_index_for_feature(name)) < 0)
00100         goto err_out;
00101 
00102     ret = ext_feature_table[opd_ext_feat_index].handlers->ext_init(args);
00103 
00104     return ret;
00105 
00106 err_out:
00107     fprintf(stderr,"opd_ext_initialize: Invalid extended feature option: %s\n", value);
00108     return ret;
00109 }
00110 
00111 
00112 int opd_ext_deinitialize()
00113 {
00114     int ret = EXIT_FAILURE;
00115 
00116     if(opd_ext_feat_index == -1) {
00117         return 0;
00118     }
00119 
00120     ret = ext_feature_table[opd_ext_feat_index].handlers->ext_deinit();
00121 
00122     return ret;
00123 }
00124 
00125 
00126 void opd_ext_print_stats()
00127 {
00128     if (is_ext_enabled()
00129     && ext_feature_table[opd_ext_feat_index].handlers->ext_print_stats != NULL) {
00130         printf("\n-- OProfile Extended-Feature Statistics --\n");
00131         ext_feature_table[opd_ext_feat_index].handlers->ext_print_stats();
00132     }
00133 }
00134 
00135 
00139 void opd_ext_sfile_create(struct sfile * sf)
00140 {
00141     /* Creating ext sfile only if extended feature is enable*/
00142     if (is_ext_sfile_enabled()
00143     && ext_feature_table[opd_ext_feat_index].handlers->ext_sfile->create != NULL)
00144         ext_feature_table[opd_ext_feat_index].handlers->ext_sfile->create(sf);
00145 }
00146 
00147 
00148 void opd_ext_sfile_dup (struct sfile * to, struct sfile * from)
00149 {
00150     /* Duplicate ext sfile only if extended feature is enable*/
00151     if (is_ext_sfile_enabled()
00152     && ext_feature_table[opd_ext_feat_index].handlers->ext_sfile->dup != NULL)
00153         ext_feature_table[opd_ext_feat_index].handlers->ext_sfile->dup(to, from);
00154 }
00155 
00156 
00157 void opd_ext_sfile_close (struct sfile * sf)
00158 {
00159     /* Close ext sfile only if extended feature is enable*/
00160     if (is_ext_sfile_enabled()
00161     && ext_feature_table[opd_ext_feat_index].handlers->ext_sfile->close != NULL)
00162         ext_feature_table[opd_ext_feat_index].handlers->ext_sfile->close(sf);
00163 }
00164 
00165 
00166 void opd_ext_sfile_sync(struct sfile * sf)
00167 {
00168     /* Sync ext sfile only if extended feature is enable*/
00169     if (is_ext_sfile_enabled()
00170     && ext_feature_table[opd_ext_feat_index].handlers->ext_sfile->sync != NULL)
00171         ext_feature_table[opd_ext_feat_index].handlers->ext_sfile->sync(sf);
00172 }
00173 
00174 
00175 odb_t * opd_ext_sfile_get(struct transient const * trans, int is_cg)
00176 {
00177     /* Get ext sfile only if extended feature is enable*/
00178     if (is_ext_sfile_enabled()
00179     && ext_feature_table[opd_ext_feat_index].handlers->ext_sfile->get != NULL)
00180         return  ext_feature_table[opd_ext_feat_index].handlers->ext_sfile->get(trans, is_cg);
00181 
00182     return NULL;
00183 }
00184 
00185 
00186 struct opd_event * opd_ext_find_counter_event(unsigned long counter)
00187 {
00188     /* Only if extended feature is enable*/
00189     if (is_ext_sfile_enabled()
00190     && ext_feature_table[opd_ext_feat_index].handlers->ext_sfile->find_counter_event != NULL)
00191         return  ext_feature_table[opd_ext_feat_index].handlers->ext_sfile->find_counter_event(counter);
00192 
00193     return NULL;
00194 }
00195 

Generated on 8 Nov 2012 for Oprofile by  doxygen 1.6.1