run: don't fail if there is no GPU trace

Some old traces don't have GPU information and with the addition of
devfreq to the plots, they break summary_plots().  Let
get_all_freqs_data(), plot_freq_hists() and plot_load() cope with traces
without devfreq information.

Fix the number of freq plots while we are at it so that we only display
as many plots as we need and don't generate empty ones if the GPU
information is not there.

Change-Id: Id57eaf21771e711d72429ca38d74dbd2cc5eef5b
Signed-off-by: Javi Merino <javi.merino@arm.com>
diff --git a/cr2/plot_utils.py b/cr2/plot_utils.py
index bf34a3a..b76d14f 100644
--- a/cr2/plot_utils.py
+++ b/cr2/plot_utils.py
@@ -114,6 +114,25 @@
     set_ylim(ax, ylim)
     set_xlim(ax, xlim)
 
+def number_freq_plots(runs, map_label):
+    """Calculate the number of plots needed for allfreq plots and frequency
+    histogram plots
+
+    """
+    num_cpu_plots = len(map_label)
+
+    has_devfreq_data = False
+    for run in runs:
+        if len(run.devfreq_in_power.data_frame) > 0:
+            has_devfreq_data = True
+            break
+
+    num_freq_plots = num_cpu_plots
+    if has_devfreq_data:
+        num_freq_plots += 1
+
+    return num_freq_plots
+
 def plot_temperature(runs, width=None, height=None, ylim="range"):
     """Plot temperatures
 
@@ -166,7 +185,9 @@
 def plot_allfreqs(runs, map_label, width=None, height=None):
     """Make a multicolumn plots of the allfreqs plots of each run"""
     num_runs = len(runs)
-    axis = pre_plot_setup(width=width, height=height, nrows=len(map_label) + 1,
+    nrows = number_freq_plots(runs, map_label)
+
+    axis = pre_plot_setup(width=width, height=height, nrows=nrows,
                           ncols=num_runs)
 
     if num_runs == 1:
@@ -213,7 +234,7 @@
 def plot_freq_hists(runs, map_label):
     """Plot frequency histograms of multiple runs"""
     num_runs = len(runs)
-    nrows = 2 * (len(map_label) + 1)
+    nrows = 2 * number_freq_plots(runs, map_label)
     axis = pre_plot_setup(ncols=num_runs, nrows=nrows)
 
     if num_runs == 1: