summaryrefslogtreecommitdiff
path: root/src/vulkan/overlay-layer
diff options
context:
space:
mode:
authorRafael Antognolli <rafael.antognolli@intel.com>2019-12-06 12:18:19 -0800
committerRafael Antognolli <rafael.antognolli@intel.com>2019-12-13 20:53:44 +0000
commita94fa1da9396c21c73e77aff029089c29f02a3a7 (patch)
tree8865577ae7191a9ee68474313534a74abdbdaeed /src/vulkan/overlay-layer
parent606dff1b73fa9509e3a0b21970f02068a8d40219 (diff)
vulkan/overlay: Add a command to start capturing data to a file.
By default, if an output_file is specified, the overlay layer will start capturing data immediately. After this commit, when a control socket is used, the capture starts disabled by default, and is only enabled when a command ":capture=1;" is received. when the capture is enabled, we might have already accumulated some stats. To avoid capturing such noise, we discard and reset the fps and stats, updating the display and capturing only data from that point on. Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Diffstat (limited to 'src/vulkan/overlay-layer')
-rw-r--r--src/vulkan/overlay-layer/overlay.cpp47
1 files changed, 44 insertions, 3 deletions
diff --git a/src/vulkan/overlay-layer/overlay.cpp b/src/vulkan/overlay-layer/overlay.cpp
index bc4240d8d76..7ab3463b2b4 100644
--- a/src/vulkan/overlay-layer/overlay.cpp
+++ b/src/vulkan/overlay-layer/overlay.cpp
@@ -56,6 +56,12 @@ struct instance_data {
bool first_line_printed;
int control_client;
+
+ /* Dumping of frame stats to a file has been enabled. */
+ bool capture_enabled;
+
+ /* Dumping of frame stats to a file has been enabled and started. */
+ bool capture_started;
};
struct frame_stat {
@@ -562,7 +568,17 @@ static void parse_command(struct instance_data *instance_data,
const char *cmd, unsigned cmdlen,
const char *param, unsigned paramlen)
{
- /* TODO: Parse commands here. */
+ if (!strncmp(cmd, "capture", cmdlen)) {
+ int value = atoi(param);
+ bool enabled = value > 0;
+
+ if (enabled) {
+ instance_data->capture_enabled = true;
+ } else {
+ instance_data->capture_enabled = false;
+ instance_data->capture_started = false;
+ }
+ }
}
#define BUFSIZE 4096
@@ -769,11 +785,26 @@ static void snapshot_swapchain_frame(struct swapchain_data *data)
data->accumulated_stats.stats[s] += device_data->frame_stats.stats[s] + data->frame_stats.stats[s];
}
+ /* If capture has been enabled but it hasn't started yet, it means we are on
+ * the first snapshot after it has been enabled. At this point we want to
+ * use the stats captured so far to update the display, but we don't want
+ * this data to cause noise to the stats that we want to capture from now
+ * on.
+ *
+ * capture_begin == true will trigger an update of the fps on display, and a
+ * flush of the data, but no stats will be written to the output file. This
+ * way, we will have only stats from after the capture has been enabled
+ * written to the output_file.
+ */
+ const bool capture_begin =
+ instance_data->capture_enabled && !instance_data->capture_started;
+
if (data->last_fps_update) {
double elapsed = (double)(now - data->last_fps_update); /* us */
- if (elapsed >= instance_data->params.fps_sampling_period) {
+ if (capture_begin ||
+ elapsed >= instance_data->params.fps_sampling_period) {
data->fps = 1000000.0f * data->n_frames_since_update / elapsed;
- if (instance_data->params.output_file) {
+ if (instance_data->capture_started) {
if (!instance_data->first_line_printed) {
bool first_column = true;
@@ -812,6 +843,9 @@ static void snapshot_swapchain_frame(struct swapchain_data *data)
memset(&data->accumulated_stats, 0, sizeof(data->accumulated_stats));
data->n_frames_since_update = 0;
data->last_fps_update = now;
+
+ if (capture_begin)
+ instance_data->capture_started = true;
}
} else {
data->last_fps_update = now;
@@ -2445,6 +2479,13 @@ static VkResult overlay_CreateInstance(
parse_overlay_env(&instance_data->params, getenv("VK_LAYER_MESA_OVERLAY_CONFIG"));
+ /* If there's no control file, and an output_file was specified, start
+ * capturing fps data right away.
+ */
+ instance_data->capture_enabled =
+ instance_data->params.output_file && instance_data->params.control < 0;
+ instance_data->capture_started = instance_data->capture_enabled;
+
for (int i = OVERLAY_PARAM_ENABLED_vertices;
i <= OVERLAY_PARAM_ENABLED_compute_invocations; i++) {
if (instance_data->params.enabled[i]) {