Skip to content

Commit

Permalink
Enhance client request stats logging capabilities
Browse files Browse the repository at this point in the history
  • Loading branch information
Gavin Norman authored and nemanja-boric-sociomantic committed Aug 20, 2018
1 parent ee240a1 commit e1fa67b
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 9 deletions.
13 changes: 13 additions & 0 deletions relnotes/clientrequeststats.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
### Client stats loggin enhancements

`swarm.neo.client.mixins.ClientCore`

The `log` method of `RequestStatsTemplate` now accepts a second argument: a
settings struct that allows the user to specify the information that is logged.
The following options now exist:
* `LogSettings.occurred_only`: If true, only log stats for requests that have
occurred at least once in the lifetime of this program; if false, log stats
for all requests.
* `LogSettings.timing_histogram`: If true, log the full timing histogram; if
false, log just count and total time.

62 changes: 53 additions & 9 deletions src/swarm/neo/client/mixins/ClientCore.d
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,9 @@ template ClientCore ( )
/// Reference to outer object.
private This outer;

/// If true, only iterate over requests that have occurred.
bool occurred_only;

/*******************************************************************
Foreach iterator over request names and stats getter instances
Expand All @@ -678,26 +681,37 @@ template ClientCore ( )
static assert(is(typeof(rq_name) : istring));

auto slice = rq_name[];
auto stats = this.outer.request!(rq_name)();
res = dg(slice, stats);
if ( res )
break;
if ( !this.occurred_only ||
this.outer.requestHasOccurred!(rq_name) )
{
auto stats = this.outer.request!(rq_name)();
res = dg(slice, stats);
if ( res )
break;
}
}
return res;
}
}

/***********************************************************************
Gets an iterator over the stats for all requests (or all requests
that have occurred).
Params:
occurred_only = if true, only iterate over requests that have
occurred
Returns:
iterator over request names and stats getter instances for all
requests specified in Requests
***********************************************************************/

public RequestStatsFruct allRequests ( )
public RequestStatsFruct allRequests ( bool occurred_only = false )
{
return RequestStatsFruct(this);
return RequestStatsFruct(this, occurred_only);
}

/***********************************************************************
Expand All @@ -711,19 +725,49 @@ template ClientCore ( )
this.outer.connections.request_set.stats.clear();
}

/// Flags defining the behaviour of log().
public struct LogSettings
{
/// If true, only log stats for requests that have occurred at least
/// once in the lifetime of this program; if false, log stats for
/// all requests.
bool occurred_only;

/// If true, log the full timing histogram; if false, log just count
/// and total time.
bool timing_histogram;
}

/***********************************************************************
Writes stats about all requests to the provided stats log.
Params:
logger = stats log to write the filled instance of Aggr to
settings = flags definining what exactly to log
***********************************************************************/

public void log ( StatsLog logger )
public void log ( StatsLog logger,
LogSettings settings = LogSettings.init )
{
foreach ( rq, stats; this.allRequests() )
logger.addObject!("request")(rq, stats);
foreach ( rq, stats; this.allRequests(settings.occurred_only) )
{
if ( settings.timing_histogram )
logger.addObject!("request")(rq, stats.histogram.stats);
else
{
struct BasicStats
{
ulong count;
ulong total_time_micros;
}
BasicStats basic_stats;
basic_stats.count = stats.count;
basic_stats.total_time_micros = stats.histogram.total_time_micros;
logger.addObject!("request")(rq, basic_stats);
}
}
}
}

Expand Down

0 comments on commit e1fa67b

Please sign in to comment.