Skip to content

Commit

Permalink
WIP: Split uftrace-script.h from script.h and add version info
Browse files Browse the repository at this point in the history
This patch factor out script_info and script_context from script.h to
uftrace-script.h, which can be included in C/C++ native scripts.

In addtion, it also adds version info to script_info and script_context.

The major version can be changed when the layout of the struct is
changed and the minor version can be changed when a new member is added
at the end.

Signed-off-by: Honggyu Kim <[email protected]>
  • Loading branch information
honggyukim committed Oct 1, 2020
1 parent bde18a6 commit c2c22b8
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 82 deletions.
12 changes: 10 additions & 2 deletions cmds/script.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ static int run_script_for_rstack(struct uftrace_data *handle,
task->timestamp = rstack->time;

if (rstack->type == UFTRACE_ENTRY) {
struct script_context sc_ctx = { 0, };
struct script_context sc_ctx = {
.ver.major = SCRIPT_CONTEXT_MAJOR_VERSION,
.ver.minor = SCRIPT_CONTEXT_MINOR_VERSION,
};
struct fstack *fstack;
int depth;
struct uftrace_trigger tr = {
Expand Down Expand Up @@ -78,7 +81,10 @@ static int run_script_for_rstack(struct uftrace_data *handle,
script_uftrace_entry(&sc_ctx);
}
else if (rstack->type == UFTRACE_EXIT) {
struct script_context sc_ctx = { 0, };
struct script_context sc_ctx = {
.ver.major = SCRIPT_CONTEXT_MAJOR_VERSION,
.ver.minor = SCRIPT_CONTEXT_MINOR_VERSION,
};
struct fstack *fstack;

/* function exit */
Expand Down Expand Up @@ -133,6 +139,8 @@ int command_script(int argc, char *argv[], struct opts *opts)
struct uftrace_data handle;
struct uftrace_task_reader *task;
struct script_info info = {
.ver.major = SCRIPT_INFO_MAJOR_VERSION,
.ver.minor = SCRIPT_INFO_MINOR_VERSION,
.name = opts->script_file,
.version = UFTRACE_VERSION,
};
Expand Down
12 changes: 10 additions & 2 deletions libmcount/mcount.c
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,10 @@ static void script_hook_entry(struct mcount_thread_data *mtdp,
struct mcount_ret_stack *rstack,
struct uftrace_trigger *tr)
{
struct script_context sc_ctx;
struct script_context sc_ctx = {
.ver.major = SCRIPT_CONTEXT_MAJOR_VERSION,
.ver.minor = SCRIPT_CONTEXT_MINOR_VERSION,
};
unsigned long entry_addr = rstack->child_ip;
struct sym *sym = find_symtabs(&symtabs, entry_addr);
char *symname = symbol_getname(sym, entry_addr);
Expand All @@ -931,7 +934,10 @@ static void script_hook_entry(struct mcount_thread_data *mtdp,
static void script_hook_exit(struct mcount_thread_data *mtdp,
struct mcount_ret_stack *rstack)
{
struct script_context sc_ctx;
struct script_context sc_ctx = {
.ver.major = SCRIPT_CONTEXT_MAJOR_VERSION,
.ver.minor = SCRIPT_CONTEXT_MINOR_VERSION,
};
unsigned long entry_addr = rstack->child_ip;
struct sym *sym = find_symtabs(&symtabs, entry_addr);
char *symname = symbol_getname(sym, entry_addr);
Expand Down Expand Up @@ -1628,6 +1634,8 @@ static void atfork_child_handler(void)
static void mcount_script_init(enum uftrace_pattern_type patt_type)
{
struct script_info info = {
.ver.major = SCRIPT_INFO_MAJOR_VERSION,
.ver.minor = SCRIPT_INFO_MINOR_VERSION,
.name = script_str,
.version = UFTRACE_VERSION,
.record = true,
Expand Down
2 changes: 1 addition & 1 deletion scripts/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
script:
gcc -I.. -fPIC -shared -o simple_c.so simple.c
gcc -I.. -fPIC -shared -o simple_cpp.so simple.cpp
g++ -I.. -fPIC -shared -o simple_cpp.so simple.cpp
gcc -I.. -fPIC -shared -o info_c.so info.c

clean:
Expand Down
26 changes: 1 addition & 25 deletions scripts/info.c
Original file line number Diff line number Diff line change
@@ -1,29 +1,5 @@
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>

/* informantion passed during initialization */
struct script_info {
char *name;
char *version;
bool record;
const char *cmds;
};

struct script_context {
int tid;
int depth;
uint64_t timestamp;
uint64_t duration; /* exit only */
unsigned long address;
char *name;
#if 0
/* for arguments and return value */
int arglen;
void *argbuf;
struct list_head *argspec;
#endif
};
#include "utils/uftrace-script.h"

void uftrace_begin(struct script_info *sc_info)
{
Expand Down
16 changes: 1 addition & 15 deletions scripts/simple.c
Original file line number Diff line number Diff line change
@@ -1,20 +1,6 @@
#include <stdio.h>
#include <stdint.h>

struct script_context {
int tid;
int depth;
uint64_t timestamp;
uint64_t duration; /* exit only */
unsigned long address;
char *name;
#if 0
/* for arguments and return value */
int arglen;
void *argbuf;
struct list_head *argspec;
#endif
};
#include "utils/uftrace-script.h"

void uftrace_begin(void)
{
Expand Down
16 changes: 1 addition & 15 deletions scripts/simple.cpp
Original file line number Diff line number Diff line change
@@ -1,20 +1,6 @@
#include <iostream>
#include <cstdint>

struct script_context {
int tid;
int depth;
uint64_t timestamp;
uint64_t duration; /* exit only */
unsigned long address;
char *name;
#if 0
/* for arguments and return value */
int arglen;
void *argbuf;
struct list_head *argspec;
#endif
};
#include "utils/uftrace-script.h"

extern "C"
void uftrace_begin(void)
Expand Down
23 changes: 1 addition & 22 deletions utils/script.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#define UFTRACE_SCRIPT_H

#include "libmcount/mcount.h"
#include "utils/uftrace-script.h"
#include "utils/script-python.h"
#include "utils/script-luajit.h"
#include "utils/script-native.h"
Expand All @@ -25,28 +26,6 @@ enum script_type_t {
SCRIPT_TYPE_COUNT
};

/* informantion passed during initialization */
struct script_info {
char *name;
char *version;
bool record;
const char *cmds;
};

/* context information passed to script */
struct script_context {
int tid;
int depth;
uint64_t timestamp;
uint64_t duration; /* exit only */
unsigned long address;
char *name;
/* for arguments and return value */
int arglen;
void *argbuf;
struct list_head *argspec;
};

union script_arg_val {
char c;
short s;
Expand Down
54 changes: 54 additions & 0 deletions utils/uftrace-script.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#ifndef UFTRACE_UFTRACE_SCRIPT_H
#define UFTRACE_UFTRACE_SCRIPT_H

#ifndef __cplusplus
#include <stdint.h>
#include <stdbool.h>
#include "utils/list.h"
#else
#include <cstdint>
#include <cstdbool>
#endif

/* informantion passed during initialization */
#define SCRIPT_INFO_MAJOR_VERSION 1
#define SCRIPT_INFO_MINOR_VERSION 0
struct script_info {
struct si_version {
uint8_t major;
uint8_t minor;
} ver;
char *name;
char *version;
bool record;
const char *cmds;
};

/* context information passed to script */
#define SCRIPT_CONTEXT_MAJOR_VERSION 1
#define SCRIPT_CONTEXT_MINOR_VERSION 0
struct script_context {
struct sc_version {
uint8_t major;
uint8_t minor;
} ver;
int tid;
int depth;
uint64_t timestamp;
uint64_t duration; /* exit only */
unsigned long address;
char *name;
#ifndef __cplusplus
/* for arguments and return value */
int arglen;
void *argbuf;
struct list_head *argspec;
#else
/*
* struct list_head internally uses 'new' as a variable name so
* it's not possible to use in C++.
*/
#endif
};

#endif /* UFTRACE_UFTRACE_SCRIPT_H */

0 comments on commit c2c22b8

Please sign in to comment.