Also make the sampling period configurable.
Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Reviewed-by: Eric Engestrom <eric.engestrom@intel.com>
VK_INSTANCE_LAYERS=VK_LAYER_MESA_overlay VK_LAYER_MESA_OVERLAY_CONFIG=help /path/to/my_vulkan_app
Turn on some statistics :
-VK_INSTANCE_LAYERS=VK_LAYER_MESA_overlay VK_LAYER_MESA_OVERLAY_CONFIG=submit=1,draw=1,pipeline_graphics=1 /path/to/my_vulkan_app
+VK_INSTANCE_LAYERS=VK_LAYER_MESA_overlay VK_LAYER_MESA_OVERLAY_CONFIG=submit,draw,pipeline_graphics /path/to/my_vulkan_app
Position the layer :
-VK_INSTANCE_LAYERS=VK_LAYER_MESA_overlay VK_LAYER_MESA_OVERLAY_CONFIG=submit=1,draw=1,pipeline_graphics=1,position=top-right /path/to/my_vulkan_app
+VK_INSTANCE_LAYERS=VK_LAYER_MESA_overlay VK_LAYER_MESA_OVERLAY_CONFIG=submit,draw,pipeline_graphics,position=top-right /path/to/my_vulkan_app
static void destroy_instance_data(struct instance_data *data)
{
+ if (data->params.output_file)
+ fclose(data->params.output_file);
unmap_object(data->instance);
ralloc_free(data);
}
static void snapshot_swapchain_frame(struct swapchain_data *data)
{
- uint64_t now = os_time_get();
+ struct instance_data *instance_data = data->device->instance;
+ uint64_t now = os_time_get(); /* us */
if (data->last_present_time) {
data->frame_times[(data->n_frames - 1) % ARRAY_SIZE(data->frame_times)] =
}
if (data->last_fps_update) {
- double elapsed = (double)(now - data->last_fps_update);
- if (elapsed >= 500000.0) {
- data->fps = ((uint64_t)data->n_frames_since_update * 1000000 / elapsed);
+ double elapsed = (double)(now - data->last_fps_update); /* us */
+ if (elapsed >= instance_data->params.fps_sampling_period) {
+ data->fps = 1000000.0f * data->n_frames_since_update / elapsed;
data->n_frames_since_update = 0;
data->last_fps_update = now;
+ if (instance_data->params.output_file) {
+ fprintf(instance_data->params.output_file, "%.2f\n", data->fps);
+ fflush(instance_data->params.output_file);
+ }
}
} else {
data->last_fps_update = now;
return LAYER_POSITION_TOP_LEFT;
}
+static FILE *
+parse_output_file(const char *str)
+{
+ return fopen(str, "w+");
+}
+
+static uint32_t
+parse_fps_sampling_period(const char *str)
+{
+ return strtol(str, NULL, 0) * 1000;
+}
+
static bool
parse_help(const char *str)
{
OVERLAY_PARAMS
#undef OVERLAY_PARAM_BOOL
#undef OVERLAY_PARAM_CUSTOM
- fprintf(stderr, "\tposition=\n"
- "\t\ttop-left\n"
- "\t\ttop-right\n"
- "\t\tbottom-left\n"
- "\t\tbottom-right\n");
+ fprintf(stderr, "\tposition=top-left|top-right|bottom-left|bottom-right\n");
+ fprintf(stderr, "\tfps_sampling_period=number of milliseconds\n");
return true;
}
i++;
for (; !is_delimiter(*s); s++, out_value++, i++)
*out_value = *s;
- }
+ } else
+ *(out_value++) = '1';
*out_value = 0;
if (*s && is_delimiter(*s)) {
/* Visible by default */
params->enabled[OVERLAY_PARAM_ENABLED_fps] = true;
params->enabled[OVERLAY_PARAM_ENABLED_frame_timing] = true;
+ params->fps_sampling_period = 500000; /* 500ms */
if (!env)
return;
#define OVERLAY_PARAM_BOOL(name) \
if (!strcmp(#name, key)) { \
- params->enabled[OVERLAY_PARAM_ENABLED_##name] = strtol(value, NULL, 0); \
+ params->enabled[OVERLAY_PARAM_ENABLED_##name] = \
+ strtol(value, NULL, 0); \
continue; \
}
-#define OVERLAY_PARAM_CUSTOM(name) \
- if (!strcmp(#name, key)) { \
+#define OVERLAY_PARAM_CUSTOM(name) \
+ if (!strcmp(#name, key)) { \
params->name = parse_##name(value); \
continue; \
}
extern "C" {
#endif
+#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
OVERLAY_PARAM_BOOL(pipeline_compute) \
OVERLAY_PARAM_BOOL(pipeline_raytracing) \
OVERLAY_PARAM_BOOL(acquire_timing) \
+ OVERLAY_PARAM_CUSTOM(fps_sampling_period) \
+ OVERLAY_PARAM_CUSTOM(output_file) \
OVERLAY_PARAM_CUSTOM(position) \
OVERLAY_PARAM_CUSTOM(help)
struct overlay_params {
bool enabled[OVERLAY_PARAM_ENABLED_MAX];
enum overlay_param_position position;
+ FILE *output_file;
+ uint32_t fps_sampling_period; /* us */
bool help;
};