add pidunique concept
authorPierre-Marc Fournier <pierre-marc.fournier@polymtl.ca>
Fri, 25 Sep 2009 19:14:52 +0000 (15:14 -0400)
committerPierre-Marc Fournier <pierre-marc.fournier@polymtl.ca>
Fri, 25 Sep 2009 19:14:52 +0000 (15:14 -0400)
libust/tracectl.c
ustd/ustd.c
ustd/ustd.h

index ee67daaac91fa99b6786c69bd8a3167712b535e8..1dd71621e0e147ba471c97c02366de92171ccfea 100644 (file)
 
 char consumer_stack[10000];
 
+/* This should only be accessed by the constructor, before the creation
+ * of the listener, and then only by the listener.
+ */
+s64 pidunique = -1LL;
+
 struct list_head blocked_consumers = LIST_HEAD_INIT(blocked_consumers);
 
 static struct ustcomm_app ustcomm_app;
@@ -93,6 +98,20 @@ struct blocked_consumer {
        struct list_head list;
 };
 
+static long long make_pidunique(void)
+{
+       s64 retval;
+       struct timeval tv;
+       
+       gettimeofday(&tv, NULL);
+
+       retval = tv.tv_sec;
+       retval <<= 32;
+       retval |= tv.tv_usec;
+
+       return retval;
+}
+
 static void print_markers(FILE *fp)
 {
        struct marker_iter iter;
@@ -682,6 +701,19 @@ void *listener_main(void *p)
                                WARN("could not disable marker; channel=%s, name=%s", channel_name, marker_name);
                        }
                }
+               else if(nth_token_is(recvbuf, "get_pidunique", 0) == 1) {
+                       char *reply;
+
+                       asprintf(&reply, "%lld", pidunique);
+
+                       result = ustcomm_send_reply(&ustcomm_app.server, reply, &src);
+                       if(result) {
+                               ERR("listener: get_pidunique: ustcomm_send_reply failed");
+                               goto next_cmd;
+                       }
+
+                       free(reply);
+               }
 //             else if(nth_token_is(recvbuf, "get_notifications", 0) == 1) {
 //                     struct ltt_trace_struct *trace;
 //                     char trace_name[] = "auto";
@@ -867,6 +899,11 @@ static void __attribute__((constructor(1000))) init()
        int result;
        char* autoprobe_val = NULL;
 
+       /* Assign the pidunique, to be able to differentiate the processes with same
+        * pid, (before and after an exec).
+        */
+       pidunique = make_pidunique();
+
        /* Initialize RCU in case the constructor order is not good. */
        urcu_init();
 
index fdf8d13f8d2f1fe418b1604a1b6baad3a1114fd1..ddbb18bfead46869bf02b43a4c328a2d534697a9 100644 (file)
@@ -326,6 +326,23 @@ int add_buffer(pid_t pid, char *bufname)
                return -1;
        }
 
+       /* get pidunique */
+       asprintf(&send_msg, "get_pidunique");
+       result = ustcomm_send_request(&buf->conn, send_msg, &received_msg);
+       free(send_msg);
+       if(result == -1) {
+               ERR("problem in ustcomm_send_request(get_pidunique)");
+               return -1;
+       }
+
+       result = sscanf(received_msg, "%lld", &buf->pidunique);
+       if(result != 1) {
+               ERR("unable to parse response to get_pidunique");
+               return -1;
+       }
+       free(received_msg);
+       DBG("got pidunique %lld", buf->pidunique);
+
        /* get shmid */
        asprintf(&send_msg, "get_shmid %s", buf->name);
        result = ustcomm_send_request(&buf->conn, send_msg, &received_msg);
@@ -411,7 +428,7 @@ int add_buffer(pid_t pid, char *bufname)
                trace_path = USTD_DEFAULT_TRACE_PATH;
        }
 
-       asprintf(&tmp, "%s/%u", trace_path, buf->pid);
+       asprintf(&tmp, "%s/%u_%lld", trace_path, buf->pid, buf->pidunique);
        result = create_dir_if_needed(tmp);
        if(result == -1) {
                ERR("could not create directory %s", tmp);
@@ -420,8 +437,8 @@ int add_buffer(pid_t pid, char *bufname)
        }
        free(tmp);
 
-       asprintf(&tmp, "%s/%u/%s_0", trace_path, buf->pid, buf->name);
-       result = fd = open(tmp, O_WRONLY | O_CREAT | O_TRUNC, 00600);
+       asprintf(&tmp, "%s/%u_%lld/%s_0", trace_path, buf->pid, buf->pidunique, buf->name);
+       result = fd = open(tmp, O_WRONLY | O_CREAT | O_TRUNC | O_EXCL, 00600);
        if(result == -1) {
                PERROR("open");
                ERR("failed opening trace file %s", tmp);
index 0b2db775e1c766fae68dd7c8f37c958bc619d6e7..65328d61ac933312a56775fcde9599f009384309 100644 (file)
@@ -28,6 +28,8 @@ struct buffer_info {
        int file_fd; /* output file */
 
        long consumed_old;
+
+       s64 pidunique;
 };
 
 ssize_t patient_write(int fd, const void *buf, size_t count);
This page took 0.026122 seconds and 4 git commands to generate.