Skip to content

Instantly share code, notes, and snippets.

@esoxjem
Created October 20, 2016 21:26
Show Gist options
  • Save esoxjem/c0797fe65e37adbcdce471a65d0b6814 to your computer and use it in GitHub Desktop.
Save esoxjem/c0797fe65e37adbcdce471a65d0b6814 to your computer and use it in GitHub Desktop.
public class SamplingInterceptor implements Interceptor
{
@Override
public Response intercept(Chain chain) throws IOException
{
Request request = chain.request();
DeviceBandwidthSampler.getInstance().startSampling();
Response response = chain.proceed(request);
DeviceBandwidthSampler.getInstance().stopSampling();
return response;
}
}
@NightlyNexus
Copy link

Hey, just happened upon this and going to offer some unsolicited advice.
This DeviceBandwidthSampler.stopSampling() appears to be used for measuring the time to complete an entire call.
This code stops sampling after the response headers come back. It looks like it is meant to be called after the response body is exhausted. You may want to check out the new OkHttp EventListener API.

@esoxjem
Copy link
Author

esoxjem commented Mar 6, 2018

Oh hey @NightlyNexus. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment