*/
ltt_write_commit_counter(buf, ltt_buf, endidx,
buf_offset, commit_count, data_size);
-
- DBG("commited slot. now commit count is %ld", commit_count);
}
/* Out-of-order commit */
ltt_commit_slot(channel, &transport_data, buf_offset,
data_size, slot_size);
- DBG("just commited event at offset %ld and size %zd\n", buf_offset, slot_size);
+ DBG("just commited event at offset %ld and size %zd", buf_offset, slot_size);
}
//ust// __get_cpu_var(ltt_nesting)--;
ltt_nesting--;
continue;
}
- DBG("received a message! it's: %s\n", recvbuf);
+ DBG("received a message! it's: %s", recvbuf);
len = strlen(recvbuf);
if(!strcmp(recvbuf, "print_markers")) {
if(autoprobe_val) {
struct marker_iter iter;
- DBG("Autoprobe enabled.\n");
+ DBG("Autoprobe enabled.");
/* Ensure markers are initialized */
//init_markers();
marker_iter_reset(&iter);
marker_iter_start(&iter);
- DBG("now iterating on markers already registered\n");
+ DBG("now iterating on markers already registered");
while(iter.marker) {
- DBG("now iterating on marker %s\n", iter.marker->name);
+ DBG("now iterating on marker %s", iter.marker->name);
auto_probe_connect(iter.marker);
marker_iter_next(&iter);
}
#include "ustcomm.h"
#include "ustcmd.h"
-#define _GNU_SOURCE
-
-pid_t* ustcmd_get_online_pids(void)
+pid_t *ustcmd_get_online_pids(void)
{
- struct dirent* dirent;
- DIR* dir;
+ struct dirent *dirent;
+ DIR *dir;
unsigned int ret_size = 1 * sizeof(pid_t), i = 0;
dir = opendir(SOCK_DIR);
return NULL;
}
- pid_t* ret = (pid_t*) malloc(ret_size);
+ pid_t *ret = (pid_t *) malloc(ret_size);
while ((dirent = readdir(dir))) {
if (!strcmp(dirent->d_name, ".") ||
if (dirent->d_type != DT_DIR &&
!!strcmp(dirent->d_name, "ustd")) {
- sscanf(dirent->d_name, "%u", (unsigned int*) &ret[i]);
+ sscanf(dirent->d_name, "%u", (unsigned int *) &ret[i]);
if (pid_is_online(ret[i])) {
ret_size += sizeof(pid_t);
- ret = (pid_t*) realloc(ret, ret_size);
+ ret = (pid_t *) realloc(ret, ret_size);
++i;
}
}
ret[i] = 0; /* Array end */
- if (ret[0] == 0) { /* No PID at all.. */
+ if (ret[0] == 0) {
+ /* No PID at all */
free(ret);
return NULL;
}
* @param pid Traced process ID
* @return 0 if successful, or errors {USTCMD_ERR_GEN, USTCMD_ERR_ARG}
*/
-int ustcmd_set_marker_state(const char* mn, int state, pid_t pid)
+int ustcmd_set_marker_state(const char *mn, int state, pid_t pid)
{
- char* cmd_str [] = {"disable_marker", "enable_marker"};
- char* cmd;
+ char *cmd_str [] = {"disable_marker", "enable_marker"};
+ char *cmd;
int result;
if (mn == NULL) {
asprintf(&cmd, "%s %s", cmd_str[state], mn);
- result = ustcmd_shoot(cmd, pid, NULL);
+ result = ustcmd_send_cmd(cmd, pid, NULL);
if (result) {
free(cmd);
return USTCMD_ERR_GEN;
{
int result;
- result = ustcmd_shoot("destroy", pid, NULL);
+ result = ustcmd_send_cmd("destroy", pid, NULL);
if (result) {
return USTCMD_ERR_GEN;
}
{
int result;
- result = ustcmd_shoot("start", pid, NULL);
+ result = ustcmd_send_cmd("start", pid, NULL);
if (result) {
return USTCMD_ERR_GEN;
}
{
int result;
- result = ustcmd_shoot("trace_start", pid, NULL);
+ result = ustcmd_send_cmd("trace_start", pid, NULL);
if (result) {
return USTCMD_ERR_GEN;
}
{
int result;
- result = ustcmd_shoot("trace_stop", pid, NULL);
+ result = ustcmd_send_cmd("trace_stop", pid, NULL);
if (result) {
return USTCMD_ERR_GEN;
}
* @param str String to search in
* @return Total newlines count
*/
-unsigned int ustcmd_count_nl(const char* str)
+unsigned int ustcmd_count_nl(const char *str)
{
unsigned int i = 0, tot = 0;
* @param cmsf CMSF array to free
* @return 0 if successful, or error USTCMD_ERR_ARG
*/
-int ustcmd_free_cmsf(struct USTcmd_cmsf* cmsf)
+int ustcmd_free_cmsf(struct marker_status *cmsf)
{
if (cmsf == NULL) {
return USTCMD_ERR_ARG;
* @param pid Targeted PID
* @return 0 if successful, or errors {USTCMD_ERR_ARG, USTCMD_ERR_GEN}
*/
-int ustcmd_get_cmsf(struct USTcmd_cmsf** cmsf, const pid_t pid)
+int ustcmd_get_cmsf(struct marker_status **cmsf, const pid_t pid)
{
- char* big_str = NULL;
+ char *big_str = NULL;
int result;
- struct USTcmd_cmsf* tmp_cmsf = NULL;
+ struct marker_status *tmp_cmsf = NULL;
unsigned int i = 0, cmsf_ind = 0;
if (cmsf == NULL) {
return USTCMD_ERR_ARG;
}
- result = ustcmd_shoot("list_markers", pid, &big_str);
+ result = ustcmd_send_cmd("list_markers", pid, &big_str);
if (result) {
return USTCMD_ERR_GEN;
}
return USTCMD_ERR_GEN;
}
- tmp_cmsf = (struct USTcmd_cmsf*) malloc(sizeof(struct USTcmd_cmsf) *
+ tmp_cmsf = (struct marker_status *) malloc(sizeof(struct marker_status) *
(ustcmd_count_nl(big_str) + 1));
if (tmp_cmsf == NULL) {
return USTCMD_ERR_GEN;
* @return 0 if successful, or errors {USTCMD_ERR_ARG, USTCMD_ERR_CONN}
*/
-int ustcmd_shoot(const char* cmd, const pid_t pid, char** reply)
+int ustcmd_send_cmd(const char *cmd, const pid_t pid, char **reply)
{
struct ustcomm_connection conn;
}
if (ustcomm_connect_app(pid, &conn)) {
- fprintf(stderr, "ustcmd_shoot: could not connect to PID %u\n",
+ fprintf(stderr, "ustcmd_send_cmd: could not connect to PID %u\n",
(unsigned int) pid);
return USTCMD_ERR_CONN;
}
#define USTCMD_SOCK_PATH "/tmp/socks/"
/* Channel/marker/state/format string (cmsf) info. structure */
-struct USTcmd_cmsf {
- char* channel; /* Channel name (end of USTcmd_cmsf array if NULL) */
- char* marker; /* Marker name (end of USTcmd_cmsf array if NULL) */
+struct marker_status {
+ char *channel; /* Channel name (end of marker_status array if NULL) */
+ char *marker; /* Marker name (end of marker_status array if NULL) */
int state; /* State (0 := marker disabled, 1 := marker enabled) */
- char* fs; /* Format string (end of USTcmd_cmsf array if NULL) */
+ char *fs; /* Format string (end of marker_status array if NULL) */
};
-pid_t* ustcmd_get_online_pids(void);
-int ustcmd_set_marker_state(const char*, int, pid_t);
-int ustcmd_destroy_trace(pid_t);
-int ustcmd_setup_and_start(pid_t);
-int ustcmd_stop_trace(pid_t);
-int ustcmd_start_trace(pid_t);
-int ustcmd_free_cmsf(struct USTcmd_cmsf*);
-unsigned int ustcmd_count_nl(const char*);
-int ustcmd_shoot(const char*, pid_t, char**);
-int ustcmd_get_cmsf(struct USTcmd_cmsf**, pid_t);
+extern pid_t *ustcmd_get_online_pids(void);
+extern int ustcmd_set_marker_state(const char *, int, pid_t);
+extern int ustcmd_destroy_trace(pid_t);
+extern int ustcmd_setup_and_start(pid_t);
+extern int ustcmd_stop_trace(pid_t);
+extern int ustcmd_start_trace(pid_t);
+extern int ustcmd_free_cmsf(struct marker_status *);
+extern unsigned int ustcmd_count_nl(const char *);
+extern int ustcmd_send_cmd(const char *, pid_t, char **);
+extern int ustcmd_get_cmsf(struct marker_status **, pid_t);
#endif /* _USTCMD_H */
}
return 1;
-
-// *reply = (char *) malloc(MSG_MAX+1);
-// result = recv(fd, *reply, MSG_MAX, 0);
-// if(result == -1) {
-// PERROR("recv");
-// return -1;
-// }
-// else if(result == 0) {
-// return 0;
-// }
-//
-// (*reply)[result] = '\0';
-//
-// return 1;
}
-static int send_message_path(const char *path, const char *msg, int signalpid)
-{
- int fd;
- int result;
- struct sockaddr_un addr;
-
- result = fd = socket(PF_UNIX, SOCK_STREAM, 0);
- if(result == -1) {
- PERROR("socket");
- return -1;
- }
-
- addr.sun_family = AF_UNIX;
-
- result = snprintf(addr.sun_path, UNIX_PATH_MAX, "%s", path);
- if(result >= UNIX_PATH_MAX) {
- ERR("string overflow allocating socket name");
- return -1;
- }
-
- if(signalpid >= 0) {
- result = signal_process(signalpid);
- if(result == -1) {
- ERR("could not signal process");
- return -1;
- }
- }
-
- result = connect(fd, (struct sockaddr *)&addr, sizeof(addr));
- if(result == -1) {
- PERROR("connect");
- return -1;
- }
-
- return send_message_fd(fd, msg);
-}
-
-///* pid: the pid of the trace process that must receive the msg
-// msg: pointer to a null-terminated message to send
-// reply: location where to put the null-terminated string of the reply;
-// it must be free'd after usage
-// */
-//
-//int send_message_pid(pid_t pid, const char *msg, char **reply)
-//{
-// int result;
-// char path[UNIX_PATH_MAX];
-//
-// result = snprintf(path, UNIX_PATH_MAX, "%s/%d", SOCK_DIR, pid);
-// if(result >= UNIX_PATH_MAX) {
-// fprintf(stderr, "string overflow allocating socket name");
-// return -1;
-// }
-//
-// send_message_path(path, msg, reply, pid);
-//
-// return 0;
-//}
-
/* Called by an app to ask the consumer daemon to connect to it. */
int ustcomm_request_consumer(pid_t pid, const char *channel)
{
char path[UNIX_PATH_MAX];
int result;
- char *msg;
+ char *msg=NULL;
+ int retval = 0;
+ struct ustcomm_connection conn;
result = snprintf(path, UNIX_PATH_MAX, "%s/ustd", SOCK_DIR);
if(result >= UNIX_PATH_MAX) {
- fprintf(stderr, "string overflow allocating socket name");
+ ERR("string overflow allocating socket name");
return -1;
}
asprintf(&msg, "collect %d %s", pid, channel);
- send_message_path(path, msg, -1);
+ /* don't signal it because it's the daemon */
+ result = ustcomm_connect_path(path, &conn, -1);
+ if(result == -1) {
+ WARN("ustcomm_connect_path failed");
+ retval = -1;
+ goto del_string;
+ }
+
+ result = ustcomm_send_request(&conn, msg, NULL);
+ if(result == -1) {
+ WARN("ustcomm_send_request failed");
+ retval = -1;
+ goto disconnect;
+ }
+
+ disconnect:
+ ustcomm_disconnect(&conn);
+ del_string:
free(msg);
- return 0;
+ return retval;
}
/* returns 1 to indicate a message was received
return src->fd;
}
-static int init_named_socket(char *name, char **path_out)
+static int init_named_socket(const char *name, char **path_out)
{
int result;
int fd;
return 1;
}
-int ustcomm_connect_path(char *path, struct ustcomm_connection *conn, pid_t signalpid)
+int ustcomm_connect_path(const char *path, struct ustcomm_connection *conn, pid_t signalpid)
{
int fd;
int result;
result = snprintf(path, UNIX_PATH_MAX, "%s/%d", SOCK_DIR, pid);
if(result >= UNIX_PATH_MAX) {
- fprintf(stderr, "string overflow allocating socket name");
+ ERR("string overflow allocating socket name");
return -1;
}
return ustcomm_connect_path(path, conn, pid);
}
-int ustcomm_disconnect_app(struct ustcomm_connection *conn)
-{
- close(conn->fd);
- return 0;
-}
+/* Called by an application to initialize its server so daemons can
+ * connect to it.
+ */
int ustcomm_init_app(pid_t pid, struct ustcomm_app *handle)
{
return -1;
}
+/* Used by the daemon to initialize its server so applications
+ * can connect to it.
+ */
+
int ustcomm_init_ustd(struct ustcomm_ustd *handle)
{
int result;
void *priv;
};
-char *strdup_malloc(const char *s);
+extern char *strdup_malloc(const char *s);
//int send_message_pid(pid_t pid, const char *msg, char **reply);
-int ustcomm_request_consumer(pid_t pid, const char *channel);
+extern int ustcomm_request_consumer(pid_t pid, const char *channel);
-int ustcomm_ustd_recv_message(struct ustcomm_ustd *ustd, char **msg, struct ustcomm_source *src, int timeout);
-int ustcomm_app_recv_message(struct ustcomm_app *app, char **msg, struct ustcomm_source *src, int timeout);
+extern int ustcomm_ustd_recv_message(struct ustcomm_ustd *ustd, char **msg, struct ustcomm_source *src, int timeout);
+extern int ustcomm_app_recv_message(struct ustcomm_app *app, char **msg, struct ustcomm_source *src, int timeout);
-int ustcomm_init_app(pid_t pid, struct ustcomm_app *handle);
+extern int ustcomm_init_app(pid_t pid, struct ustcomm_app *handle);
-int ustcomm_init_ustd(struct ustcomm_ustd *handle);
+extern int ustcomm_init_ustd(struct ustcomm_ustd *handle);
-int ustcomm_connect_app(pid_t pid, struct ustcomm_connection *conn);
-int ustcomm_send_request(struct ustcomm_connection *conn, const char *req, char **reply);
-int ustcomm_send_reply(struct ustcomm_server *server, char *msg, struct ustcomm_source *src);
+extern int ustcomm_connect_app(pid_t pid, struct ustcomm_connection *conn);
+extern int ustcomm_connect_path(const char *path, struct ustcomm_connection *conn, pid_t signalpid);
+extern int ustcomm_send_request(struct ustcomm_connection *conn, const char *req, char **reply);
+extern int ustcomm_send_reply(struct ustcomm_server *server, char *msg, struct ustcomm_source *src);
+extern int ustcomm_disconnect(struct ustcomm_connection *conn);
-int nth_token_is(char *str, char *token, int tok_no);
+extern int nth_token_is(char *str, char *token, int tok_no);
-char *nth_token(char *str, int tok_no);
+extern char *nth_token(char *str, int tok_no);
-int pid_is_online(pid_t);
+extern int pid_is_online(pid_t);
#endif /* USTCOMM_H */
return retval | low;
}
-//static inline u64 trace_clock_read64(void)
-//{
-// struct timeval tv;
-// u64 retval;
-//
-// gettimeofday(&tv, NULL);
-// retval = tv.tv_sec;
-// retval *= 1000000;
-// retval += tv.tv_usec;
-//
-// return retval;
-//}
+#if 0
+static inline u64 trace_clock_read64(void)
+{
+ struct timeval tv;
+ u64 retval;
+
+ gettimeofday(&tv, NULL);
+ retval = tv.tv_sec;
+ retval *= 1000000;
+ retval += tv.tv_usec;
+
+ return retval;
+}
+#endif
static inline u64 trace_clock_frequency(void)
{
struct ust_opts {
enum command cmd;
pid_t *pids;
- char* regex;
+ char *regex;
regex_t preg;
int regex_state;
};
opts->pids = malloc((argc-optind+1) * sizeof(pid_t));
for(i=optind; i<argc; i++) {
- opts->pids[pididx++] = atoi(argv[i]);
+ /* don't take any chances, use a long long */
+ long long tmp;
+ char *endptr;
+ tmp = strtoull(argv[i], &endptr, 10);
+ if(*endptr != '\0') {
+ ERR("The pid \"%s\" is invalid.", argv[i]);
+ return 1;
+ }
+ opts->pids[pididx++] = (pid_t) tmp;
}
opts->pids[pididx] = -1;
}
if (opts->cmd == ENABLE_MARKER || opts->cmd == DISABLE_MARKER) {
- if (opts->regex_state = regcomp(&opts->preg, opts->regex, 0)) {
- fprintf(stderr, "Invalid regular expression.\n");
+ opts->regex_state = regcomp(&opts->preg, opts->regex, 0);
+ if (opts->regex_state) {
+ ERR("invalid regular expression\n");
}
}
return 0;
}
-static void regex_change_m_state(struct ust_opts* opts, pid_t pid) {
- struct USTcmd_cmsf* cmsf = NULL;
+static void regex_change_m_state(struct ust_opts *opts, pid_t pid)
+{
+ struct marker_status *cmsf = NULL;
unsigned int i = 0;
int e = (opts->cmd == ENABLE_MARKER);
return;
}
while (cmsf[i].channel != NULL) {
- char* mc;
+ char *mc;
asprintf(&mc, "%s/%s", cmsf[i].channel, cmsf[i].marker);
if (regexec(&opts->preg, mc, 0, NULL, 0) == 0) {
/* We got a match! */
int main(int argc, char *argv[])
{
pid_t *pidit;
- struct ustcomm_connection conn;
int result;
struct ust_opts opts;
result = parse_opts_long(argc, argv, &opts);
if(result) {
+ fprintf(stderr, "\n");
usage();
exit(EXIT_FAILURE);
}
exit(EXIT_FAILURE);
}
if (opts.cmd == GET_ONLINE_PIDS) {
- pid_t* pp = ustcmd_get_online_pids();
+ pid_t *pp = ustcmd_get_online_pids();
unsigned int i = 0;
if (pp) {
}
pidit = opts.pids;
- struct USTcmd_cmsf* cmsf = NULL;
+ struct marker_status *cmsf = NULL;
while(*pidit != -1) {
switch (opts.cmd) {
case START_TRACE:
- if (ustcmd_start_trace(*pidit)) {
- fprintf(stderr,
- "error while trying to for trace "
- "with PID %u\n", (unsigned int) *pidit);
+ result = ustcmd_start_trace(*pidit);
+ if (result) {
+ ERR("error while trying to for trace with PID %u\n", (unsigned int) *pidit);
+ break;
+ }
+ //printf("sucessfully started trace for PID %u\n", (unsigned int) *pidit);
break;
- }
- printf("sucessfully started trace for PID %u\n",
- (unsigned int) *pidit);
- break;
case STOP_TRACE:
- if (ustcmd_stop_trace(*pidit)) {
- fprintf(stderr,
- "error while trying to stop trace "
- "for PID %u\n", (unsigned int) *pidit);
+ result = ustcmd_stop_trace(*pidit);
+ if (result) {
+ ERR("error while trying to stop trace for PID %u\n", (unsigned int) *pidit);
+ break;
+ }
+ //printf("sucessfully stopped trace for PID %u\n", (unsigned int) *pidit);
break;
- }
- printf("sucessfully stopped trace for PID %u\n",
- (unsigned int) *pidit);
- break;
case START:
- if (ustcmd_setup_and_start(*pidit)) {
- fprintf(stderr,
- "error while trying to setup/start "
- "trace for PID %u\n",
- (unsigned int) *pidit);
+ result = ustcmd_setup_and_start(*pidit);
+ if (result) {
+ ERR("error while trying to setup/start trace for PID %u\n", (unsigned int) *pidit);
+ break;
+ }
+ //printf("sucessfully setup/started trace for PID %u\n", (unsigned int) *pidit);
break;
- }
- printf("sucessfully setup/started trace for PID %u\n",
- (unsigned int) *pidit);
- break;
case DESTROY:
- if (ustcmd_destroy_trace(*pidit)) {
- fprintf(stderr,
- "error while trying to destroy "
- "trace with PID %u\n",
- (unsigned int) *pidit);
+ result = ustcmd_destroy_trace(*pidit);
+ if (result) {
+ ERR("error while trying to destroy trace with PID %u\n", (unsigned int) *pidit);
+ break;
+ }
+ //printf("sucessfully destroyed trace for PID %u\n", (unsigned int) *pidit);
break;
- }
- printf("sucessfully destroyed trace for PID %u\n",
- (unsigned int) *pidit);
- break;
case LIST_MARKERS:
- cmsf = NULL;
- if (ustcmd_get_cmsf(&cmsf, *pidit)) {
- fprintf(stderr,
- "error while trying to list markers for"
- " PID %u\n", (unsigned int) *pidit);
+ cmsf = NULL;
+ if (ustcmd_get_cmsf(&cmsf, *pidit)) {
+ fprintf(stderr,
+ "error while trying to list markers for"
+ " PID %u\n", (unsigned int) *pidit);
+ break;
+ }
+ unsigned int i = 0;
+ while (cmsf[i].channel != NULL) {
+ printf("{PID: %u, channel/marker: %s/%s, "
+ "state: %u, fs: %s}\n",
+ (unsigned int) *pidit,
+ cmsf[i].channel,
+ cmsf[i].marker,
+ cmsf[i].state,
+ cmsf[i].fs);
+ ++i;
+ }
+ ustcmd_free_cmsf(cmsf);
break;
- }
- unsigned int i = 0;
- while (cmsf[i].channel != NULL) {
- printf("{PID: %u, channel/marker: %s/%s, "
- "state: %u, fs: %s}\n",
- (unsigned int) *pidit,
- cmsf[i].channel,
- cmsf[i].marker,
- cmsf[i].state,
- cmsf[i].fs);
- ++i;
- }
- ustcmd_free_cmsf(cmsf);
- break;
case ENABLE_MARKER:
case DISABLE_MARKER:
break;
default:
- fprintf(stderr, "error: unknown command...\n");
+ ERR("unknown command\n");
break;
}
pidit++;
}
- exit_free:
if (opts.pids != NULL) {
free(opts.pids);
}