iowatcher: Simplify temp movie directory creation
authorAndrew Price <anprice@redhat.com>
Sat, 26 Apr 2014 01:56:17 +0000 (02:56 +0100)
committerChris Mason <clm@fb.com>
Wed, 24 Sep 2014 19:02:09 +0000 (12:02 -0700)
plot_io_movie() was calling create_movie_temp_dir() which unnecessarily
strdup()ed a string constant leaving plot_io_movie() to free it. Replace
the strdup() with a mutable char array and get rid of the free(). Merge
the few remaining lines which create the movie dir into plot_io_movie().

Also prune a duplicate declaration of start_mpstat() in tracers.h

Signed-off-by: Andrew Price <anprice@redhat.com>
iowatcher/main.c
iowatcher/tracers.h

index 5cbfa53ddf4a2e218e830c1e5d6c3b6976b07f4d..92b0ef3a71e94917b73485f34b6ff094b2d03483 100644 (file)
@@ -569,19 +569,6 @@ again:
        }
 }
 
-static char *create_movie_temp_dir(void)
-{
-       char *ret;
-       char *pattern = strdup("io-movie-XXXXXX");;
-
-       ret = mkdtemp(pattern);
-       if (!ret) {
-               perror("Unable to create temp directory for movie files");
-               exit(1);
-       }
-       return ret;
-}
-
 static struct pid_plot_history *alloc_pid_plot_history(char *color)
 {
        struct pid_plot_history *pph;
@@ -1080,7 +1067,6 @@ static void cleanup_movie(char *movie_dir)
 static void plot_io_movie(struct plot *plot)
 {
        struct trace_file *tf;
-       char *movie_dir = create_movie_temp_dir();
        int i, pid;
        struct plot_history *history;
        int batch_i;
@@ -1091,6 +1077,12 @@ static void plot_io_movie(struct plot *plot)
        int batch_count;
        int graph_width_factor = 5;
        int orig_y_offset;
+       char movie_dir[] = "io-movie-XXXXXX";
+
+       if (mkdtemp(movie_dir) == NULL) {
+               perror("Unable to create temp directory for movie files");
+               exit(1);
+       }
 
        get_graph_size(&cols, &rows);
        batch_count = cols / total_frames;
@@ -1194,7 +1186,6 @@ static void plot_io_movie(struct plot *plot)
        convert_movie_files(movie_dir);
        encode_movie(movie_dir);
        cleanup_movie(movie_dir);
-       free(movie_dir);
 }
 
 static void plot_latency(struct plot *plot, unsigned int min_seconds,
index 92f349adf4d2dfad6323db3f3d791d26f1c34f05..0db19b4bb1da5b7c53ac8fa402f571bfa5f79cdc 100644 (file)
@@ -23,7 +23,6 @@ int stop_blktrace(void);
 int start_blktrace(char **devices, int num_devices, char *trace_name, char *dest);
 int start_mpstat(char *trace_name);
 int wait_for_tracers(void);
-int start_mpstat(char *trace_name);
 
 
 #endif