Mercurial > prosody-hg
comparison core/statsmanager.lua @ 6555:7b2d16c14659
statsmanager, util.statistics: API changes, remove debugging
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Wed, 21 Jan 2015 01:26:06 +0000 |
| parents | 6c22bec3e8d0 |
| children | 1e749832ed3b |
comparison
equal
deleted
inserted
replaced
| 6554:6c22bec3e8d0 | 6555:7b2d16c14659 |
|---|---|
| 21 function measure(type, name) | 21 function measure(type, name) |
| 22 local f = assert(stats[type], "unknown stat type: "..type); | 22 local f = assert(stats[type], "unknown stat type: "..type); |
| 23 return f(name); | 23 return f(name); |
| 24 end | 24 end |
| 25 | 25 |
| 26 local mark_collection_start = measure("duration", "stats.collection_time"); | 26 local mark_collection_start = measure("times", "stats.collection"); |
| 27 local mark_processing_start = measure("duration", "stats.processing_time"); | 27 local mark_processing_start = measure("times", "stats.processing"); |
| 28 | 28 |
| 29 function collect() | 29 function collect() |
| 30 local mark_collection_done = mark_collection_start(); | 30 local mark_collection_done = mark_collection_start(); |
| 31 changed_stats, stats_extra = {}, {}; | 31 changed_stats, stats_extra = {}, {}; |
| 32 for name, getter in pairs(stats.get_stats()) do | 32 for stat_name, getter in pairs(stats.get_stats()) do |
| 33 local type, value, extra = getter(); | 33 local type, value, extra = getter(); |
| 34 local stat_name = name..":"..type; | |
| 35 local old_value = latest_stats[stat_name]; | 34 local old_value = latest_stats[stat_name]; |
| 36 latest_stats[stat_name] = value; | 35 latest_stats[stat_name] = value; |
| 37 if value ~= old_value then | 36 if value ~= old_value then |
| 38 changed_stats[stat_name] = value; | 37 changed_stats[stat_name] = value; |
| 39 end | 38 end |
| 40 if extra then | 39 if extra then |
| 41 print(stat_name, extra) | |
| 42 stats_extra[stat_name] = extra; | 40 stats_extra[stat_name] = extra; |
| 43 if type == "duration" then | |
| 44 local rate = extra.rate; | |
| 45 local rate_name = name..":rate"; | |
| 46 latest_stats[rate_name] = rate; | |
| 47 changed_stats[rate_name] = rate; | |
| 48 end | |
| 49 end | 41 end |
| 50 end | 42 end |
| 51 mark_collection_done(); | 43 mark_collection_done(); |
| 52 local mark_processing_done = mark_processing_start(); | 44 local mark_processing_done = mark_processing_start(); |
| 53 fire_event("stats-updated", { stats = latest_stats, changed_stats = changed_stats, stats_extra = stats_extra }); | 45 fire_event("stats-updated", { stats = latest_stats, changed_stats = changed_stats, stats_extra = stats_extra }); |
