* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*/
+#include <stdlib.h>
#include <stdbool.h>
+#include <string.h>
+#include <errno.h>
+#include <inttypes.h>
#include <X11/Xlib.h>
#include <cairo-xlib.h>
#include "acre.h"
#include "math.h"
+#define STRNCMP_LITERAL(var, literal) \
+ strncmp ((var), (literal), sizeof (literal) - 1)
+
static acre_t *
-load_chart (void)
+load_fips_data (const char *filename)
{
+ FILE *file;
acre_t *acre;
- acre_data_t *data0, *data1, *data2;
- int i;
+ acre_data_t *frame_time;
+ char *line = NULL, *s;
+ size_t line_size;
+ ssize_t bytes;
+
+ file = fopen (filename, "r");
+ if (file == NULL) {
+ fprintf (stderr, "Failed to open %s: %s\n",
+ filename, strerror (errno));
+ return NULL;
+ }
acre = acre_create ();
- acre_set_x_axis_label (acre, "X axis");
- acre_set_y_axis_label (acre, "Y axis");
- data0 = acre_data_create ();
- data1 = acre_data_create ();
- data2 = acre_data_create ();
+ acre_set_title (acre, filename);
+ acre_set_x_axis_label (acre, "Frame #");
+ acre_set_y_axis_label (acre, "Frame time (ms)");
- acre_data_set_name (data0, "Data 0");
- acre_data_set_name (data1, "Data 1");
- acre_data_set_name (data2, "Data 2");
+ frame_time = acre_data_create ();
- for (i = 0; i <= 100; i++) {
- acre_data_add_point_2d (data0, i, 0 - (i/3.0)*(i/3.0));
- }
+ while (1) {
+ int scanned;
- for (i = 0; i < 100; i++) {
- double t = 1.0 - (i / 100.0);
- acre_data_add_point_2d (data1, i, -1000 * (1.0 - t*t*t));
- }
-
- for (i = 0; i <= 1000; i++) {
- double t, x, y;
- t = i/10.0 - 50;
- x = t + 50;
- if (t == 0.0)
- y = -200;
- else
- y = -1200 + 1000 * sin(t) / t;
- acre_data_add_point_2d (data2, x, y);
+ bytes = getline (&line, &line_size, file);
+ if (bytes == -1)
+ break;
+
+ s = line;
+
+ if (STRNCMP_LITERAL (s, "frame-time: ") == 0) {
+ unsigned frame;
+ int64_t frame_time_ns;
+
+ s += strlen("frame-time: ");
+
+ scanned = sscanf (s, "%d %" SCNu64,
+ &frame, &frame_time_ns);
+ if (scanned != 2) {
+ fprintf (stderr, "Warning: Failed to parse line: %s\n", line);
+ continue;
+ }
+
+ acre_data_add_point_2d (frame_time, frame,
+ frame_time_ns / 1e6);
+ } else {
+ /* Ignoring all other lines. */
+ }
}
- acre_add_data (acre, data0);
- acre_add_data (acre, data1);
- acre_add_data (acre, data2);
+ free (line);
- acre_set_title (acre, "All the data");
+ acre_add_data (acre, frame_time);
return acre;
}
}
int
-main (void)
+main (int argc, char *argv[])
{
Display *dpy;
Window window, root;
int width = 800;
int height = 600;
- acre = load_chart ();
+ if (argc < 2) {
+ fprintf (stderr, "Usage: acre-x data-file\n");
+ fprintf (stderr, "Where the data file is the output from fips (with frame-timing feature.\n");
+ exit (1);
+ }
+
+ acre = load_fips_data (argv[1]);
+
+ if (acre == NULL)
+ return 1;
dpy = XOpenDisplay (NULL);