iowatcher: Add bounds checking in find_step
[blktrace.git] / iowatcher / plot.c
index 1e9b7d7345612e999142e4e2e62a4dbae7f0867d..d486f293fc2bdf3103853c11346568cca2fa2c39 100644 (file)
@@ -12,7 +12,7 @@
  *
  *  You should have received a copy of the GNU General Public License
  *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  *
  *  Parts of this file were imported from Jens Axboe's blktrace sources (also GPL)
  */
@@ -71,8 +71,10 @@ static int final_width = 0;
 
 static char *colors[] = {
        "blue", "darkgreen",
-       "red", "aqua",
-       "orange", "darkviolet",
+       "red",
+       "darkviolet",
+       "orange",
+       "aqua",
        "brown", "#00FF00",
        "yellow", "coral",
        "black", "darkred",
@@ -94,6 +96,19 @@ char *pick_color(void)
        return ret;
 }
 
+char *pick_fio_color(void)
+{
+       static int fio_color_index;
+       char *ret = colors[fio_color_index];
+
+       if (!ret) {
+               fio_color_index = 0;
+               ret = colors[fio_color_index];
+       }
+       fio_color_index += 2;
+       return ret;
+}
+
 static int cpu_color_index;
 
 char *pick_cpu_color(void)
@@ -515,10 +530,12 @@ static double find_step(double first, double last, int num_ticks)
        /* Round to power of 10 */
        step = exp(floor(log(step) / log10) * log10);
        /* Scale down step to provide enough ticks */
-       while ((last - first) / (step * mini_step[cur_mini_step]) > num_ticks
-              && cur_mini_step < TICK_MINI_STEPS)
+       while (cur_mini_step < TICK_MINI_STEPS
+              && (last - first) / (step * mini_step[cur_mini_step]) > num_ticks)
                cur_mini_step++;
-       step *= mini_step[cur_mini_step - 1];
+
+       if (cur_mini_step > 0)
+               step *= mini_step[cur_mini_step - 1];
 
        return step;
 }
@@ -939,7 +956,7 @@ int svg_io_graph_movie_array_spindle(struct plot *plot, struct pid_plot_history
                 "<circle cx=\"%.2f\" cy=\"%.2f\" "
                 "stroke=\"black\" stroke-width=\"6\" "
                 "r=\"%.2f\" fill=\"none\"/>\n",
-                -spindle_steps * 1.2, center_x, center_y, center_x, center_y, graph_width_extra / 2);
+                spindle_steps * 1.2, center_x, center_y, center_x, center_y, graph_width_extra / 2);
        write(plot->fd, line, strlen(line));
        snprintf(line, line_len, "<circle cx=\"%.2f\" cy=\"%.2f\" "
                "stroke=\"none\" fill=\"red\" r=\"%.2f\"/>\n</g>\n",
@@ -964,7 +981,7 @@ int svg_io_graph_movie_array_spindle(struct plot *plot, struct pid_plot_history
                snprintf(line, line_len, "<path transform=\"rotate(%.4f, %.2f, %.2f)\" "
                         "d=\"M %.2f %.2f a %.2f %.2f 0 0 1 0 5\" "
                         "stroke=\"%s\" stroke-width=\"4\"/>\n",
-                        rot, center_x, center_y,
+                        -rot, center_x, center_y,
                         axis_x_off_double(graph_width_extra / 2 + radius) + 8, center_y,
                         radius, radius, pph->color);