From 52829efe52cf3f6bf8266b87285ac988a9e3bb8d Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Wed, 23 Oct 2013 11:39:05 -0400 Subject: [PATCH] Add tools for collecting data on message sending times. Usage, on the javascript console: > feature_flags.collect_send_times = true; > compose.send_many_messages("test", "test", 3) > compose.send_times_data [47, 99, 48] (imported from commit a2a22eea9bb1bbe24a79ec0453c099dabfc61c19) --- static/js/compose.js | 38 ++++++++++++++++++++++++++++++++++++-- static/js/feature_flags.js | 1 + 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/static/js/compose.js b/static/js/compose.js index 0e21243d1a..33050dd6c3 100644 --- a/static/js/compose.js +++ b/static/js/compose.js @@ -345,8 +345,11 @@ function send_message_socket(request, success) { }); } -function send_message() { - var request = create_message_object(); +exports.send_times_data = []; +function send_message(request) { + if (request === undefined) { + request = create_message_object(); + } exports.snapshot_message(request); if (request.type === "private") { @@ -360,6 +363,9 @@ function send_message() { if (feature_flags.log_send_times) { blueslip.log("send time: " + (new Date() - start_time)); } + if (feature_flags.collect_send_times) { + exports.send_times_data.push((new Date() - start_time)); + } $("#new_message_content").val('').focus(); autosize_textarea(); $("#send-status").hide(0); @@ -380,6 +386,34 @@ function send_message() { } } +// This function is for debugging / data collection only. Arguably it +// should live in debug.js, but then it wouldn't be able to call +// send_message() directly below. +exports.test_send_many_messages = function (stream, subject, count) { + var num_sent = 0; + + function do_send_one () { + var message = {}; + num_sent += 1; + + message.type = "stream"; + message.to = stream; + message.subject = subject; + message.content = num_sent.toString(); + message.client = client(); + + send_message(message); + + if (num_sent === count) { + return; + } + + setTimeout(do_send_one, 1000); + } + + do_send_one(); +}; + exports.finish = function () { clear_invites(); diff --git a/static/js/feature_flags.js b/static/js/feature_flags.js index 9edf771d44..fdb565b9a6 100644 --- a/static/js/feature_flags.js +++ b/static/js/feature_flags.js @@ -19,6 +19,7 @@ var is_customer4 = _.contains(customer4_realms, page_params.domain); // Manually-flipped debugging flags exports.log_send_times = false; +exports.collect_send_times = false; // Permanent realm-specific stuff: