Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
eclair snapshot
- Loading branch information
Jean-Baptiste Queru
committed
Nov 13, 2009
1 parent
10e23ee
commit 84862f9
Showing
44 changed files
with
3,268 additions
and
171 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,181 @@ | ||
/** | ||
* @file opd_extended.c | ||
* OProfile Extended Feature | ||
* | ||
* @remark Copyright 2007-2009 OProfile authors | ||
* @remark Read the file COPYING | ||
* | ||
* @author Suravee Suthikulpanit <suravee.suthikulpanit@amd.com> | ||
* Copyright (c) 2009 Advanced Micro Devices, Inc. | ||
*/ | ||
|
||
#include "opd_extended.h" | ||
#include "op_string.h" | ||
|
||
#include <string.h> | ||
#include <stdio.h> | ||
|
||
/* This global variable is >= 0 | ||
* if extended feature is enabled */ | ||
static int opd_ext_feat_index; | ||
|
||
extern struct opd_ext_handlers ibs_handlers; | ||
|
||
/** | ||
* OProfile Extended Feature Table | ||
* | ||
* This table contains a list of extended features. | ||
*/ | ||
static struct opd_ext_feature ext_feature_table[] = { | ||
{"ibs", &ibs_handlers }, | ||
{ NULL, NULL } | ||
}; | ||
|
||
|
||
static int get_index_for_feature(char const * name) | ||
{ | ||
int ret = -1; | ||
unsigned int i; | ||
|
||
if(!name) | ||
return ret; | ||
|
||
for (i = 0 ; ext_feature_table[i].feature != NULL ; i++ ) { | ||
if(!strncmp(name, ext_feature_table[i].feature, | ||
strlen(ext_feature_table[i].feature))) { | ||
ret = i; | ||
break; | ||
} | ||
} | ||
|
||
return ret; | ||
} | ||
|
||
|
||
static inline int is_ext_enabled() | ||
{ | ||
if (opd_ext_feat_index >= 0 | ||
&& ext_feature_table[opd_ext_feat_index].handlers != NULL) | ||
return 1; | ||
else | ||
return 0; | ||
} | ||
|
||
|
||
static inline int is_ext_sfile_enabled() | ||
{ | ||
if (opd_ext_feat_index >= 0 | ||
&& ext_feature_table[opd_ext_feat_index].handlers != NULL | ||
&& ext_feature_table[opd_ext_feat_index].handlers->ext_sfile != NULL) | ||
return 1; | ||
else | ||
return 0; | ||
} | ||
|
||
|
||
/** | ||
* Param "value" is the input from CML option with the format: | ||
* | ||
* <feature name>:<param1>:<param2>:<param3>:..... | ||
* | ||
* where param1,2.3,..n are optional. | ||
*/ | ||
int opd_ext_initialize(char const * value) | ||
{ | ||
int ret = EXIT_FAILURE; | ||
char * tmp = NULL, * name = NULL, * args = NULL; | ||
|
||
if(!value) { | ||
opd_ext_feat_index = -1; | ||
return 0; | ||
} | ||
|
||
tmp = op_xstrndup(value, strlen(value)); | ||
|
||
/* Parse feature name*/ | ||
if((name = strtok_r(tmp, ":", &args)) == NULL) | ||
goto err_out; | ||
|
||
if((opd_ext_feat_index = get_index_for_feature(name)) < 0) | ||
goto err_out; | ||
|
||
ret = ext_feature_table[opd_ext_feat_index].handlers->ext_init(args); | ||
|
||
return ret; | ||
|
||
err_out: | ||
fprintf(stderr,"opd_ext_initialize: Invalid extended feature option: %s\n", value); | ||
return ret; | ||
} | ||
|
||
|
||
void opd_ext_print_stats() | ||
{ | ||
if (is_ext_enabled() | ||
&& ext_feature_table[opd_ext_feat_index].handlers->ext_print_stats != NULL) { | ||
printf("\n-- OProfile Extended-Feature Statistics --\n"); | ||
ext_feature_table[opd_ext_feat_index].handlers->ext_print_stats(); | ||
} | ||
} | ||
|
||
|
||
/** | ||
* opd_sfile extended APIs | ||
*/ | ||
void opd_ext_sfile_create(struct sfile * sf) | ||
{ | ||
/* Creating ext sfile only if extended feature is enable*/ | ||
if (is_ext_sfile_enabled() | ||
&& ext_feature_table[opd_ext_feat_index].handlers->ext_sfile->create != NULL) | ||
ext_feature_table[opd_ext_feat_index].handlers->ext_sfile->create(sf); | ||
} | ||
|
||
|
||
void opd_ext_sfile_dup (struct sfile * to, struct sfile * from) | ||
{ | ||
/* Duplicate ext sfile only if extended feature is enable*/ | ||
if (is_ext_sfile_enabled() | ||
&& ext_feature_table[opd_ext_feat_index].handlers->ext_sfile->dup != NULL) | ||
ext_feature_table[opd_ext_feat_index].handlers->ext_sfile->dup(to, from); | ||
} | ||
|
||
|
||
void opd_ext_sfile_close (struct sfile * sf) | ||
{ | ||
/* Close ext sfile only if extended feature is enable*/ | ||
if (is_ext_sfile_enabled() | ||
&& ext_feature_table[opd_ext_feat_index].handlers->ext_sfile->close != NULL) | ||
ext_feature_table[opd_ext_feat_index].handlers->ext_sfile->close(sf); | ||
} | ||
|
||
|
||
void opd_ext_sfile_sync(struct sfile * sf) | ||
{ | ||
/* Sync ext sfile only if extended feature is enable*/ | ||
if (is_ext_sfile_enabled() | ||
&& ext_feature_table[opd_ext_feat_index].handlers->ext_sfile->sync != NULL) | ||
ext_feature_table[opd_ext_feat_index].handlers->ext_sfile->sync(sf); | ||
} | ||
|
||
|
||
odb_t * opd_ext_sfile_get(struct transient const * trans, int is_cg) | ||
{ | ||
/* Get ext sfile only if extended feature is enable*/ | ||
if (is_ext_sfile_enabled() | ||
&& ext_feature_table[opd_ext_feat_index].handlers->ext_sfile->get != NULL) | ||
return ext_feature_table[opd_ext_feat_index].handlers->ext_sfile->get(trans, is_cg); | ||
|
||
return NULL; | ||
} | ||
|
||
|
||
struct opd_event * opd_ext_find_counter_event(unsigned long counter) | ||
{ | ||
/* Only if extended feature is enable*/ | ||
if (is_ext_sfile_enabled() | ||
&& ext_feature_table[opd_ext_feat_index].handlers->ext_sfile->find_counter_event != NULL) | ||
return ext_feature_table[opd_ext_feat_index].handlers->ext_sfile->find_counter_event(counter); | ||
|
||
return NULL; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/** | ||
* @file opd_extended.h | ||
* OProfile Extended Feature | ||
* | ||
* @remark Copyright 2007-2009 OProfile authors | ||
* @remark Read the file COPYING | ||
* | ||
* @author Suravee Suthikulpanit <suravee.suthikulpanit@amd.com> | ||
* Copyright (c) 2009 Advanced Micro Devices, Inc. | ||
*/ | ||
|
||
#ifndef OPD_EXTENDED_H | ||
#define OPD_EXTENDED_H | ||
|
||
#include "opd_trans.h" | ||
#include "odb.h" | ||
|
||
#include <stdlib.h> | ||
#include <stdint.h> | ||
|
||
|
||
/** | ||
* OProfile Extended Feature Table Entry | ||
*/ | ||
struct opd_ext_feature { | ||
// Feature name | ||
const char* feature; | ||
// Feature handlers | ||
struct opd_ext_handlers * handlers; | ||
}; | ||
|
||
/** | ||
* OProfile Extended handlers | ||
*/ | ||
struct opd_ext_handlers { | ||
// Extended init | ||
int (*ext_init)(char const *); | ||
// Extended statistics | ||
int (*ext_print_stats)(); | ||
// Extended sfile handlers | ||
struct opd_ext_sfile_handlers * ext_sfile; | ||
}; | ||
|
||
/** | ||
* OProfile Extended sub-handlers (sfile) | ||
*/ | ||
struct opd_ext_sfile_handlers { | ||
int (*create)(struct sfile *); | ||
int (*dup)(struct sfile *, struct sfile *); | ||
int (*close)(struct sfile *); | ||
int (*sync)(struct sfile *); | ||
odb_t * (*get)(struct transient const *, int); | ||
struct opd_event * (*find_counter_event)(unsigned long); | ||
}; | ||
|
||
/** | ||
* @param value: commandline input option string | ||
* | ||
* Parse the specified extended feature | ||
*/ | ||
extern int opd_ext_initialize(char const * value); | ||
|
||
/** | ||
* Print out extended feature statistics in oprofiled.log file | ||
*/ | ||
extern void opd_ext_print_stats(); | ||
|
||
/** | ||
* opd_sfile extended sfile handling functions | ||
*/ | ||
extern void opd_ext_sfile_create(struct sfile * sf); | ||
extern void opd_ext_sfile_dup (struct sfile * to, struct sfile * from); | ||
extern void opd_ext_sfile_close(struct sfile * sf); | ||
extern void opd_ext_sfile_sync(struct sfile * sf); | ||
extern odb_t * opd_ext_sfile_get(struct transient const * trans, int is_cg); | ||
|
||
/** | ||
* @param counter: counter index | ||
* | ||
* Get event struct opd_event from the counter index value. | ||
*/ | ||
extern struct opd_event * opd_ext_find_counter_event(unsigned long counter); | ||
|
||
|
||
#endif |
Oops, something went wrong.