aboutsummaryrefslogtreecommitdiffstats
path: root/sway/desktop/transaction.c
diff options
context:
space:
mode:
authorLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-08-18 16:58:50 +1000
committerLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-08-19 16:17:24 +1000
commit8d1dd038233cf946b36813c4c8508c17f4cda0fc (patch)
treee672976231d33467da6c8a03633c604eb0c8deb8 /sway/desktop/transaction.c
parentMerge pull request #2453 from ianyfan/commands (diff)
downloadsway-8d1dd038233cf946b36813c4c8508c17f4cda0fc.tar.gz
sway-8d1dd038233cf946b36813c4c8508c17f4cda0fc.tar.zst
sway-8d1dd038233cf946b36813c4c8508c17f4cda0fc.zip
Standardise debug variables
This makes all debug options stored in a single struct rather than in various places, changes/fixes the behaviour of existing options, and introduces some new options. * Fixes damage issues with `-Drender-tree` texture (by removing scissor) * Offsets the render tree overlay's `y` position for those who have swaybar at the top * Replaces `-Ddamage=rerender` with `-Dnodamage` * Replaces `-Ddamage=highlight` with `-Dhighlight-damage` * Replaces `-Dtxn-debug` with `-Dtxn-wait` * Introduces `-Dnoatomic` * Removes the `create_time` and `ms_arranging` figures from transactions and the log message. Transactions are created after arranging and the create time is of no significance. * Fixes `-Dtxn-debug` (now `-Dtxn-wait`) not working.
Diffstat (limited to 'sway/desktop/transaction.c')
-rw-r--r--sway/desktop/transaction.c57
1 files changed, 19 insertions, 38 deletions
diff --git a/sway/desktop/transaction.c b/sway/desktop/transaction.c
index c300558a..219f5362 100644
--- a/sway/desktop/transaction.c
+++ b/sway/desktop/transaction.c
@@ -1,5 +1,6 @@
1#define _POSIX_C_SOURCE 200809L 1#define _POSIX_C_SOURCE 200809L
2#include <errno.h> 2#include <errno.h>
3#include <limits.h>
3#include <stdbool.h> 4#include <stdbool.h>
4#include <stdlib.h> 5#include <stdlib.h>
5#include <string.h> 6#include <string.h>
@@ -16,26 +17,12 @@
16#include "list.h" 17#include "list.h"
17#include "log.h" 18#include "log.h"
18 19
19/**
20 * How long we should wait for views to respond to the configure before giving
21 * up and applying the transaction anyway.
22 */
23int txn_timeout_ms = 200;
24
25/**
26 * If enabled, sway will always wait for the transaction timeout before
27 * applying it, rather than applying it when the views are ready. This allows us
28 * to observe the rendered state while a transaction is in progress.
29 */
30bool txn_debug = false;
31
32struct sway_transaction { 20struct sway_transaction {
33 struct wl_event_source *timer; 21 struct wl_event_source *timer;
34 list_t *instructions; // struct sway_transaction_instruction * 22 list_t *instructions; // struct sway_transaction_instruction *
35 size_t num_waiting; 23 size_t num_waiting;
36 size_t num_configures; 24 size_t num_configures;
37 uint32_t con_ids; // Bitwise XOR of view container IDs 25 uint32_t con_ids; // Bitwise XOR of view container IDs
38 struct timespec create_time;
39 struct timespec commit_time; 26 struct timespec commit_time;
40}; 27};
41 28
@@ -53,9 +40,6 @@ static struct sway_transaction *transaction_create() {
53 return NULL; 40 return NULL;
54 } 41 }
55 transaction->instructions = create_list(); 42 transaction->instructions = create_list();
56 if (server.debug_txn_timings) {
57 clock_gettime(CLOCK_MONOTONIC, &transaction->create_time);
58 }
59 return transaction; 43 return transaction;
60} 44}
61 45
@@ -149,19 +133,14 @@ static void transaction_add_container(struct sway_transaction *transaction,
149 */ 133 */
150static void transaction_apply(struct sway_transaction *transaction) { 134static void transaction_apply(struct sway_transaction *transaction) {
151 wlr_log(WLR_DEBUG, "Applying transaction %p", transaction); 135 wlr_log(WLR_DEBUG, "Applying transaction %p", transaction);
152 if (server.debug_txn_timings) { 136 if (debug.txn_timings) {
153 struct timespec now; 137 struct timespec now;
154 clock_gettime(CLOCK_MONOTONIC, &now); 138 clock_gettime(CLOCK_MONOTONIC, &now);
155 struct timespec *create = &transaction->create_time;
156 struct timespec *commit = &transaction->commit_time; 139 struct timespec *commit = &transaction->commit_time;
157 float ms_arranging = (commit->tv_sec - create->tv_sec) * 1000 + 140 float ms = (now.tv_sec - commit->tv_sec) * 1000 +
158 (commit->tv_nsec - create->tv_nsec) / 1000000.0;
159 float ms_waiting = (now.tv_sec - commit->tv_sec) * 1000 +
160 (now.tv_nsec - commit->tv_nsec) / 1000000.0; 141 (now.tv_nsec - commit->tv_nsec) / 1000000.0;
161 float ms_total = ms_arranging + ms_waiting; 142 wlr_log(WLR_DEBUG, "Transaction %p: %.1fms waiting "
162 wlr_log(WLR_DEBUG, "Transaction %p: %.1fms arranging, %.1fms waiting, " 143 "(%.1f frames if 60Hz)", transaction, ms, ms / (1000.0f / 60));
163 "%.1fms total (%.1f frames if 60Hz)", transaction,
164 ms_arranging, ms_waiting, ms_total, ms_total / (1000.0f / 60));
165 } 144 }
166 145
167 // Apply the instruction state to the container's current state 146 // Apply the instruction state to the container's current state
@@ -310,25 +289,30 @@ static void transaction_commit(struct sway_transaction *transaction) {
310 con->instruction = instruction; 289 con->instruction = instruction;
311 } 290 }
312 transaction->num_configures = transaction->num_waiting; 291 transaction->num_configures = transaction->num_waiting;
313 if (server.debug_txn_timings) { 292 if (debug.txn_timings) {
314 clock_gettime(CLOCK_MONOTONIC, &transaction->commit_time); 293 clock_gettime(CLOCK_MONOTONIC, &transaction->commit_time);
315 } 294 }
295 if (debug.noatomic) {
296 transaction->num_waiting = 0;
297 } else if (debug.txn_wait) {
298 // Force the transaction to time out even if all views are ready.
299 // We do this by inflating the waiting counter.
300 transaction->num_waiting += 1000000;
301 }
316 302
317 if (transaction->num_waiting) { 303 if (transaction->num_waiting) {
318 // Set up a timer which the views must respond within 304 // Set up a timer which the views must respond within
319 transaction->timer = wl_event_loop_add_timer(server.wl_event_loop, 305 transaction->timer = wl_event_loop_add_timer(server.wl_event_loop,
320 handle_timeout, transaction); 306 handle_timeout, transaction);
321 if (transaction->timer) { 307 if (transaction->timer) {
322 wl_event_source_timer_update(transaction->timer, txn_timeout_ms); 308 wl_event_source_timer_update(transaction->timer,
309 server.txn_timeout_ms);
323 } else { 310 } else {
324 wlr_log(WLR_ERROR, "Unable to create transaction timer (%s). " 311 wlr_log(WLR_ERROR, "Unable to create transaction timer (%s). "
325 "Some imperfect frames might be rendered.", 312 "Some imperfect frames might be rendered.",
326 strerror(errno)); 313 strerror(errno));
327 handle_timeout(transaction); 314 transaction->num_waiting = 0;
328 } 315 }
329 } else {
330 wlr_log(WLR_DEBUG,
331 "Transaction %p has nothing to wait for", transaction);
332 } 316 }
333 317
334 // The debug tree shows the pending/live tree. Here is a good place to 318 // The debug tree shows the pending/live tree. Here is a good place to
@@ -341,7 +325,7 @@ static void set_instruction_ready(
341 struct sway_transaction_instruction *instruction) { 325 struct sway_transaction_instruction *instruction) {
342 struct sway_transaction *transaction = instruction->transaction; 326 struct sway_transaction *transaction = instruction->transaction;
343 327
344 if (server.debug_txn_timings) { 328 if (debug.txn_timings) {
345 struct timespec now; 329 struct timespec now;
346 clock_gettime(CLOCK_MONOTONIC, &now); 330 clock_gettime(CLOCK_MONOTONIC, &now);
347 struct timespec *start = &transaction->commit_time; 331 struct timespec *start = &transaction->commit_time;
@@ -352,15 +336,12 @@ static void set_instruction_ready(
352 transaction->num_configures - transaction->num_waiting + 1, 336 transaction->num_configures - transaction->num_waiting + 1,
353 transaction->num_configures, ms, 337 transaction->num_configures, ms,
354 instruction->container->name); 338 instruction->container->name);
355
356 } 339 }
357 340
358 // If the transaction has timed out then its num_waiting will be 0 already. 341 // If the transaction has timed out then its num_waiting will be 0 already.
359 if (transaction->num_waiting > 0 && --transaction->num_waiting == 0) { 342 if (transaction->num_waiting > 0 && --transaction->num_waiting == 0) {
360 if (!txn_debug) { 343 wlr_log(WLR_DEBUG, "Transaction %p is ready", transaction);
361 wlr_log(WLR_DEBUG, "Transaction %p is ready", transaction); 344 wl_event_source_timer_update(transaction->timer, 0);
362 wl_event_source_timer_update(transaction->timer, 0);
363 }
364 } 345 }
365 346
366 instruction->container->instruction = NULL; 347 instruction->container->instruction = NULL;