Skip to content

Commit

Permalink
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
Show file tree
Hide file tree
Showing 44 changed files with 3,268 additions and 171 deletions.
3 changes: 3 additions & 0 deletions daemon/Android.mk
Expand Up @@ -6,6 +6,9 @@ LOCAL_SRC_FILES:= \
opd_anon.c \
opd_cookie.c \
opd_events.c \
opd_extended.c \
opd_ibs.c \
opd_ibs_trans.c \
opd_kernel.c \
opd_mangling.c \
opd_perfmon.c \
Expand Down
4 changes: 2 additions & 2 deletions daemon/init.c
Expand Up @@ -174,14 +174,14 @@ static void opd_do_jitdumps(void)
sprintf(end_time_str, "%llu", end_time);
sprintf(opjitconv_path, "%s/%s", OP_BINDIR, "opjitconv");
arg_num = 0;
exec_args[arg_num++] = opjitconv_path;
exec_args[arg_num++] = "opjitconv";
if (vmisc)
exec_args[arg_num++] = "-d";
exec_args[arg_num++] = session_dir;
exec_args[arg_num++] = start_time_str;
exec_args[arg_num++] = end_time_str;
exec_args[arg_num] = (char *) NULL;
execvp("opjitconv", exec_args);
execvp(opjitconv_path, exec_args);
fprintf(stderr, "Failed to exec %s: %s\n",
exec_args[0], strerror(errno));
/* We don't want any cleanup in the child */
Expand Down
15 changes: 11 additions & 4 deletions daemon/opd_events.c
Expand Up @@ -13,6 +13,7 @@

#include "opd_events.h"
#include "opd_printf.h"
#include "opd_extended.h"
#include "oprofiled.h"

#include "op_string.h"
Expand All @@ -35,7 +36,7 @@ static double cpu_speed;
static void malformed_events(void)
{
fprintf(stderr, "oprofiled: malformed events passed "
"on the command line\n");
"on the command line\n");
exit(EXIT_FAILURE);
}

Expand Down Expand Up @@ -128,6 +129,12 @@ void opd_parse_events(char const * events)
struct opd_event * find_counter_event(unsigned long counter)
{
size_t i;
struct opd_event * ret = NULL;

if (counter >= OP_MAX_COUNTERS) {
if((ret = opd_ext_find_counter_event(counter)) != NULL)
return ret;
}

for (i = 0; i < op_nr_counters && opd_events[i].name; ++i) {
if (counter == opd_events[i].counter)
Expand All @@ -141,9 +148,9 @@ struct opd_event * find_counter_event(unsigned long counter)


void fill_header(struct opd_header * header, unsigned long counter,
vma_t anon_start, vma_t cg_to_anon_start,
int is_kernel, int cg_to_is_kernel,
int spu_samples, uint64_t embed_offset, time_t mtime)
vma_t anon_start, vma_t cg_to_anon_start,
int is_kernel, int cg_to_is_kernel,
int spu_samples, uint64_t embed_offset, time_t mtime)
{
struct opd_event * event = find_counter_event(counter);

Expand Down
4 changes: 2 additions & 2 deletions daemon/opd_events.h
Expand Up @@ -40,8 +40,8 @@ struct opd_header;

/** fill the sample file header with event info etc. */
void fill_header(struct opd_header * header, unsigned long counter,
vma_t anon_start, vma_t anon_end,
int is_kernel, int cg_to_is_kernel,
vma_t anon_start, vma_t anon_end,
int is_kernel, int cg_to_is_kernel,
int spu_samples, uint64_t embed_offset, time_t mtime);

#endif /* OPD_EVENTS_H */
181 changes: 181 additions & 0 deletions daemon/opd_extended.c
@@ -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;
}

85 changes: 85 additions & 0 deletions daemon/opd_extended.h
@@ -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

0 comments on commit 84862f9

Please sign in to comment.