From acec697fe7a833f3c0439ef30e1dce5f9cda3de0 Mon Sep 17 00:00:00 2001 From: Leo Franchi Date: Thu, 13 Feb 2014 12:49:44 -0500 Subject: [PATCH] Report unnarrow times as well as narrow times (imported from commit b3a889aa11dc112508c5a1d213f68e5223a879fc) --- .../files/graphite/aggregation-rules.conf | 4 +++ static/js/narrow.js | 28 +++++++++++++++++++ zerver/views/__init__.py | 10 +++++++ zproject/urls.py | 1 + 4 files changed, 43 insertions(+) diff --git a/puppet/zulip_internal/files/graphite/aggregation-rules.conf b/puppet/zulip_internal/files/graphite/aggregation-rules.conf index aa1b915dc4..8dab2ada58 100644 --- a/puppet/zulip_internal/files/graphite/aggregation-rules.conf +++ b/puppet/zulip_internal/files/graphite/aggregation-rules.conf @@ -54,3 +54,7 @@ stats.timers..endtoend.displayed_time.all. (5) = sum stats.timers..narrow.initial_core.all. (5) = sum stats.timers..narrow.initial_core.*. stats.timers..narrow.initial_free.all. (5) = sum stats.timers..narrow.initial_free.*. stats.timers..narrow.network.all. (5) = sum stats.timers..narrow.network.*. + +# Do the same for unnarrow times +stats.timers..unnarrow.initial_core.all. (5) = sum stats.timers..unnarrow.initial_core.*. +stats.timers..unnarrow.initial_free.all. (5) = sum stats.timers..unnarrow.initial_free.*. diff --git a/static/js/narrow.js b/static/js/narrow.js index 340d4127c3..0728421e03 100644 --- a/static/js/narrow.js +++ b/static/js/narrow.js @@ -3,6 +3,7 @@ var narrow = (function () { var exports = {}; var current_filter; +var unnarrow_times; // A small concession to unit testing follows: exports._set_current_filter = function (filter) { @@ -116,6 +117,26 @@ function maybe_report_narrow_time(msg_list) { } +function report_unnarrow_time() { + if (unnarrow_times === undefined || + unnarrow_times.start_time === undefined || + unnarrow_times.initial_core_time === undefined || + unnarrow_times.initial_free_time === undefined) { + return; + } + + var initial_core_time = unnarrow_times.initial_core_time - unnarrow_times.start_time; + var initial_free_time = unnarrow_times.initial_free_time - unnarrow_times.start_time; + + channel.post({ + url: '/json/report_unnarrow_time', + data: {"initial_core": initial_core_time.toString(), + "initial_free": initial_free_time.toString()} + }); + + unnarrow_times = {}; +} + exports.activate = function (raw_operators, opts) { var start_time = new Date(); var was_narrowed_already = exports.active(); @@ -386,6 +407,7 @@ exports.deactivate = function () { if (current_filter === undefined) { return; } + unnarrow_times = {start_time: new Date()}; blueslip.debug("Unnarrowed"); if (ui.actively_scrolling()) { @@ -464,6 +486,12 @@ exports.deactivate = function () { compose_fade.update_message_list(); $(document).trigger($.Event('narrow_deactivated.zulip', {msg_list: current_msg_list})); + + unnarrow_times.initial_core_time = new Date(); + setTimeout(function () { + unnarrow_times.initial_free_time = new Date(); + report_unnarrow_time(); + }); }; exports.restore_home_state = function () { diff --git a/zerver/views/__init__.py b/zerver/views/__init__.py index f34f86b988..03824b09be 100644 --- a/zerver/views/__init__.py +++ b/zerver/views/__init__.py @@ -1711,6 +1711,16 @@ def json_report_narrow_time(request, user_profile, statsd.timing("narrow.network.%s" % (statsd_key(user_profile.realm.domain, clean_periods=True),), network) return json_success() +@authenticated_json_post_view +@has_request_variables +def json_report_unnarrow_time(request, user_profile, + initial_core=REQ(converter=to_non_negative_int), + initial_free=REQ(converter=to_non_negative_int)): + request._log_data["extra"] = "[%sms/%sms]" % (initial_core, initial_free) + statsd.timing("unnarrow.initial_core.%s" % (statsd_key(user_profile.realm.domain, clean_periods=True),), initial_core) + statsd.timing("unnarrow.initial_free.%s" % (statsd_key(user_profile.realm.domain, clean_periods=True),), initial_free) + return json_success() + @authenticated_json_post_view @has_request_variables def json_report_error(request, user_profile, message=REQ, stacktrace=REQ, diff --git a/zproject/urls.py b/zproject/urls.py index ad38ad6441..c1a279d6dc 100644 --- a/zproject/urls.py +++ b/zproject/urls.py @@ -130,6 +130,7 @@ urlpatterns += patterns('zerver.views', url(r'^json/report_error$', 'json_report_error'), url(r'^json/report_send_time$', 'json_report_send_time'), url(r'^json/report_narrow_time$', 'json_report_narrow_time'), + url(r'^json/report_unnarrow_time$', 'json_report_unnarrow_time'), url(r'^json/update_message_flags$', 'messages.json_update_flags'), url(r'^json/register$', 'json_events_register'), url(r'^json/upload_file$', 'json_upload_file'),