Skip to content

Commit

Permalink
add clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
eeliu committed Sep 18, 2023
1 parent da8bfcb commit 06aab08
Show file tree
Hide file tree
Showing 24 changed files with 2,431 additions and 3,004 deletions.
6 changes: 3 additions & 3 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ENV TZ=Asia/Shanghai
ENV LC_CTYPE=en_US.UTF-8
ENV LC_ALL=en_US.UTF-8
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN apt update && apt install -y gcc g++ gdb pkg-config libxml2-dev libsqlite3-dev libcurl4-openssl-dev zlib1g-dev make cmake wget autoconf git
RUN apt update && apt install -y gcc g++ gdb pkg-config libxml2-dev libsqlite3-dev libcurl4-openssl-dev zlib1g-dev make cmake wget autoconf git clangd
## enable php-7.4
ENV PHP_VESION=php-7.4.33
RUN cd ~ && wget https://www.php.net/distributions/${PHP_VESION}.tar.gz && tar xvf ${PHP_VESION}.tar.gz && cd ${PHP_VESION} && ./configure --prefix=/opt/${PHP_VESION} --enable-fpm --enable-opcache --enable-debug && make -j && make install
Expand All @@ -13,11 +13,11 @@ COPY php.ini /opt/

### Build php module
### curl
RUN cd ~/${PHP_VESION}/ext/curl && phpize && ./configure && make -j && make install
# RUN cd ~/${PHP_VESION}/ext/curl && phpize && ./configure && make -j && make install
### mysqli
# RUN cd ~/php-7.4.33/ext/mysqli && phpize && ./configure && make -j && make install
### pdo
RUN cd ~/${PHP_VESION}/ext/pdo && phpize && ./configure && make -j && make install
# RUN cd ~/${PHP_VESION}/ext/pdo && phpize && ./configure && make -j && make install

ENV PHP_VESION=php-5.6.30
RUN cd ~ && wget https://www.php.net/distributions/${PHP_VESION}.tar.gz && tar xvf ${PHP_VESION}.tar.gz && cd ${PHP_VESION} && ./configure --prefix=/opt/${PHP_VESION} --enable-fpm --enable-opcache --enable-debug && make -j && make install
Expand Down
7 changes: 4 additions & 3 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,15 @@
// },
// "remoteUser": "vscode",
// "containerUser": "vscode",
// "postCreateCommand": ".devcontainer/setup.sh",
"postCreateCommand": ".devcontainer/setup.sh",
"extensions": [
"github.vscode-pull-request-github",
"zxh404.vscode-proto3",
"bazelbuild.vscode-bazel",
"llvm-vs-code-extensions.vscode-clangd",
"vadimcn.vscode-lldb",
"webfreak.debug",
"ms-python.python"
"ms-python.python",
"xaver.clang-format",
"zxh404.vscode-proto3"
]
}
174 changes: 75 additions & 99 deletions common/include/common.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -34,78 +34,55 @@
#define IN_MSG_BUF_SIZE 4096
#define NAMING_SIZE 128
static const int RECONNECT_TIME_SEC = 5;
typedef enum
{
RESPONSE_AGENT_INFO = 0,
REQ_UPDATE_SPAN = 1
} MSG_TYPE;
typedef enum { RESPONSE_AGENT_INFO = 0, REQ_UPDATE_SPAN = 1 } MSG_TYPE;

typedef enum
{
E_LOGGING = 0x1,
E_DISABLE_GIL = 0x2, // disable gil checking in python
E_UTEST = 0x4
typedef enum {
E_LOGGING = 0x1,
E_DISABLE_GIL = 0x2, // disable gil checking in python
E_UTEST = 0x4
} AGENT_FLAG;

typedef enum
{
E_INVALID_NODE = -1,
E_ROOT_NODE = 0
} NodeID;
typedef enum { E_INVALID_NODE = -1, E_ROOT_NODE = 0 } NodeID;

#pragma pack(1)
typedef struct
{
uint32_t type;
uint32_t length;
typedef struct {
uint32_t type;
uint32_t length;
} Header;
#pragma pack()

typedef struct collector_agent_s
{
uint64_t start_time;
char *appid;
char *appname;
typedef struct collector_agent_s {
uint64_t start_time;
char *appid;
char *appname;
} CollectorAgentInfo;

///
typedef struct trace_store_layer
{
void (*set_cur_trace_cb)(void *);
void *(*get_cur_trace_cb)(void);
typedef struct trace_store_layer {
void (*set_cur_trace_cb)(void *);
void *(*get_cur_trace_cb)(void);
} TraceStoreLayer;

#define LOG_SIZE 4096
#define MAX_ADDRESS_SIZE 256
typedef void (*VOID_FUNC)(void);
typedef struct pp_agent_s
{
char co_host[MAX_ADDRESS_SIZE]; // tcp:ip:port should support dns
long timeout_ms; // always be 0
long trace_limit; // change to long as python need long
int agent_type;
uint8_t inter_flag;
VOID_FUNC get_read_lock;
VOID_FUNC get_write_lock;
VOID_FUNC release_lock;
typedef struct pp_agent_s {
char co_host[MAX_ADDRESS_SIZE]; // tcp:ip:port should support dns
long timeout_ms; // always be 0
long trace_limit; // change to long as python need long
int agent_type;
uint8_t inter_flag;
VOID_FUNC get_read_lock;
VOID_FUNC get_write_lock;
VOID_FUNC release_lock;
} PPAgentT;

typedef enum
{
E_OFFLINE = 0x1,
E_TRACE_PASS = 0x2,
E_TRACE_BLOCK = 0x4,
E_READY = 0x8
} E_AGENT_STATUS;
typedef enum { E_OFFLINE = 0x1, E_TRACE_PASS = 0x2, E_TRACE_BLOCK = 0x4, E_READY = 0x8 } E_AGENT_STATUS;

/**
* @brief at present only root checking
*/
typedef enum
{
E_LOC_CURRENT = 0x0,
E_LOC_ROOT = 0x1
} E_NODE_LOC;
typedef enum { E_LOC_CURRENT = 0x0, E_LOC_ROOT = 0x1 } E_NODE_LOC;

#define PINPOINT_C_AGENT_API_VERSION "@PROJECT_VERSION@"

Expand All @@ -121,31 +98,30 @@ typedef enum
* - add tls
*/
#ifdef __cplusplus
extern "C"
{
extern "C" {
#endif

extern PPAgentT global_agent_info;
extern PPAgentT global_agent_info;

/**
/**
* @brief [tls]
* pinpoint_get_per_thread_id and pinpoint_update_per_thread_id are paired API
* pinpoint_get_per_thread_id get the current trace-id of current thread
* pinpoint_update_per_thread_id update(stores) the current trace-id for pinpoint_get_per_thread_id
* @return NodeID
*/
NodeID pinpoint_get_per_thread_id(void);
void pinpoint_update_per_thread_id(NodeID id);
NodeID pinpoint_get_per_thread_id(void);
void pinpoint_update_per_thread_id(NodeID id);

/**
/**
* @brief [tls] start a trace (span) from parentId. if current span is empty, create a span or else create a spanevent
*
* @param parentId
* @return -1: failed new traceId related to parentId (caller [parentId] -> callee [NodeID] )
*/
NodeID pinpoint_start_trace(NodeID parentId);
NodeID pinpoint_start_trace(NodeID parentId);

/**
/**
* @brief [tls] V1 support trace with optional config
* Not support on root traceNode
* @param parentId
Expand All @@ -156,83 +132,83 @@ extern "C"
* "TraceOnlyException" // only trace exception( only report when call pinpoint_add_exception)
* @return NodeID
*/
NodeID pinpoint_start_traceV1(NodeID parentId, const char *opt, ...);
NodeID pinpoint_start_traceV1(NodeID parentId, const char *opt, ...);

void pinpoint_add_exception(NodeID, const char *exp);
void pinpoint_add_exception(NodeID, const char *exp);

/**[tls]
/**[tls]
* the same as pinpoint_start_trace. BUT, end a span or a spanevent
* Note: pinpoint_end_trace is thread safe, but you should avoid to call it in the multi-thread, it may send duplicate trace span
* @return NodeID is parent node id
*/
NodeID pinpoint_end_trace(NodeID);
NodeID pinpoint_end_trace(NodeID);

/**
/**
* @brief wake a finished trace: this trace get a new startime, so it could be profile again. the end_trace will update the ["e"] by cumulative time (NOTE: root trace not supported)
*
* @param traceId
* @return int 0 if success, -1 if failed
*/
int pinpoint_wake_trace(NodeID traceId);
int pinpoint_wake_trace(NodeID traceId);

/**
/**
* check id->traceNode is root
* @param
* @return 1: is root; 0: not root node;-1: A wrong id
*/
int pinpoint_trace_is_root(NodeID);
int pinpoint_trace_is_root(NodeID);

/**
/**
* force end current trace, only called when callstack leaked
* @return int 0 : means oK
* -1: exception found, check the log
*/
int pinpoint_force_end_trace(NodeID, int32_t timeout);
int pinpoint_force_end_trace(NodeID, int32_t timeout);

/**
/**
* [tls] pinpoint_add_clues, append a value into span[key]
* @param key must be a string
* @param value key must be a string
*/
void pinpoint_add_clues(NodeID _id, const char *key, const char *value, E_NODE_LOC flag);
/**
void pinpoint_add_clues(NodeID _id, const char *key, const char *value, E_NODE_LOC flag);
/**
* [tls] pinpoint_add_clues, add a key-value into span. span[key]=value
* @param key must be a string
* @param value key must be a string
*/
void pinpoint_add_clue(NodeID _id, const char *key, const char *value, E_NODE_LOC flag);
/**
void pinpoint_add_clue(NodeID _id, const char *key, const char *value, E_NODE_LOC flag);
/**
* [tls] add a key value into current trace. IF the trace is end, all data(key-value) will be free
* @param key
* @param value
*/
void pinpoint_set_context_key(NodeID _id, const char *key, const char *value);
/**
void pinpoint_set_context_key(NodeID _id, const char *key, const char *value);
/**
* [tls] get the corresponding value with key(in current trace)
* @param size copy into pbuf, not include '\0'
* @return
*/
int pinpoint_get_context_key(NodeID _id, const char *key, char *pbuf, int buf_size);
int pinpoint_get_context_key(NodeID _id, const char *key, char *pbuf, int buf_size);

void pinpoint_set_context_long(NodeID _id, const char *key, long);
void pinpoint_set_context_long(NodeID _id, const char *key, long);

/**
/**
* @brief the value is a long type
*
* @param _id node id
* @param key string
* @return int 1: failed
* 0: success
*/
int pinpoint_get_context_long(NodeID _id, const char *key, long *);
/**
int pinpoint_get_context_long(NodeID _id, const char *key, long *);
/**
* [tls] if tracelimit enable, check current trace state,
* @param timestamp
* @return 0, sampled or else, not sampled
*/
int check_tracelimit(int64_t);
int check_tracelimit(int64_t);

/**
/**
* @brief [tls] setting current trace status
typedef enum {
E_OFFLINE = 0x1,
Expand All @@ -244,45 +220,45 @@ extern "C"
* @param status
* @return int last status
*/
uint64_t mark_current_trace_status(NodeID _id, int status);
uint64_t mark_current_trace_status(NodeID _id, int status);

/**
/**
* [tls] get an unique auto-increment id
* NOTE: implement by shared memory, only valid in current host.
* @return
*/
int64_t generate_unique_id(void);
int64_t generate_unique_id(void);

/**
/**
* [tls] get the start time of collector-agent.Use to generate transactionID
* @return
*/
uint64_t pinpoint_start_time(void);
uint64_t pinpoint_start_time(void);

/**
/**
* mark current span with error
* @param msg
* @param error_filename
* @param error_lineno
*/
void catch_error(NodeID _id, const char *msg, const char *error_filename, uint32_t error_lineno);
typedef void (*log_msg_cb)(char *);
void register_error_cb(log_msg_cb error_cb);
void catch_error(NodeID _id, const char *msg, const char *error_filename, uint32_t error_lineno);
typedef void (*log_msg_cb)(char *);
void register_error_cb(log_msg_cb error_cb);

/**
/**
* @brief for test-case: not send span to collector-agent, pass to handler
* not tls
* @param handler
*/
void register_span_handler(void (*handler)(const char *));
void register_span_handler(void (*handler)(const char *));

void pp_trace(const char *format, ...);
/**
void pp_trace(const char *format, ...);
/**
* NOTE: only for testcase
*/
void reset_unique_id(void);
const char *pinpoint_agent_version();
void show_status(void);
void reset_unique_id(void);
const char *pinpoint_agent_version();
void show_status(void);
#ifdef __cplusplus
}
#endif
Expand Down
Loading

0 comments on commit 06aab08

Please sign in to comment.