MiniProfiler / dotnet

A simple but effective mini-profiler for ASP.NET (and Core) websites
https://miniprofiler.com/dotnet/
MIT License
2.92k stars 602 forks source link

Include "number of rows read" in CustomTiming for DataReaders #531

Open jdaigle opened 4 years ago

jdaigle commented 4 years ago

I'm considering a feature to count the number of rows read by a profiled IDataReader as a new property on CustomTiming. I'm looking for feedback on whether or not this seems useful, and to discuss a possible design for the feature (I'm happy to spend the time building it).

A couple of ideas:

  1. Add a new method IDbProfiler.ReaderRead(IDataReader reader) that increments a NumberOfRowsRead property. While this is pretty clean, it's probably not very performant since the current implementation of IDbReader would require a dictionary lookup.
  2. Change IDbProfiler.ReaderFinish(IDataReader reader) so that it includes int numberOfRowsRead.

Both of these, unfortunately, are breaking changes to the interface. But how many people are implementing custom IDbProfiler implementations?

I'm open to to other ideas too.

NickCraver commented 4 years ago

I'm a little confused what the source of this data would be, since we're an ADO.NET wrapper - what's the input on the number of rows from DbDataReader?

jdaigle commented 4 years ago

@NickCraver my thought is simply a counter that is incremented each time DbDataReader.Read() or DbDataRader.ReadAsync() is called and returns true.

So my design question is which class owns this counter?

  1. It could IDbProfiler. I think that would require a new IDbProfiler.ReaderRead(IDataReader reader) method that is called by ProfiledDbDataReader each time a row is read. As I mentioned above, this might be pretty expensive given how it uses a dictionary to maintain state for multiple readers.
  2. Alternatively, ProfiledDbDataReader uses its own counter. Then add a new parameter to IDbProfiler.ReaderFinish(IDataReader reader, int numberOfRowsRead) to save off the result.
crimcol commented 2 years ago

I would like to see returned number of rows from sql. Did you found solution for that?