I am working on a project in WPF that uses Entity Framework with SQL Server. Optimize there shit. Everything is too slow. And I want to diagnose which parts of the code kill performance - I think there are only a few (I mean a lot, but not all) places that are poorly designed and kill performance.
Now for each table we have a class, for example UserRepository. This is not exactly a repository template. These classes have methods such as: GetAll(...), GetById(...), GetNewest(...), GetAllWithHigherSalaryThan(int salary, int companyId)etc., many db access methods. The database is used only in repository classes.
I do not want to talk about refactoring here. I just want to measure how long each method has been running and how many times it has been executed at run time. From this information I can find errors.
I want to measure about 100 methods that "choose from db" in many classes. SQL Server Provider does not do this because these methods are executed countless times, and analyzing logs from the profiler is, if possible, a nightmare with our approach to the database.
Method Example:
public IEnumerable<Foo> GetFoo(int y, int z)
{
return Context.Where(p =>
p.X == null &&
p.Y == y &&
p.Time >= z).OrderBy(x => x.Time).AsEnumerable();
}
Now I was thinking about adding a stopwatch to each method, measuring the execution time, counting the performances and transferring it to some singleton or something else, and then displaying it. Of course, I will turn off this diagnosis when I am done with it, but this approach is a very weekly course. I need to edit each method, and I don’t know how to turn it off after - I mean, I know that I can use something like #define DEBUG, but anyway.
- Reflections, ... , #?
?