Ayende @ Rahien

Unnatural acts on source code

xProfiler – A generic OR/M Profiler

With the release of NH Prof v1.0, I started to look if I can extend what I am doing for NHibernate for other OR/M in the .NET space. My initial spiking makes me optimistic, this is certainly possible. I’ll probably talk at length about the actual architectural implementation, but for now I want to concentrate on the actual high level requirements. I want to be able to support the following:

  • Linq to SQL
  • SubSonic
  • LLBLGen
  • Plug your own DAL

While none of them are going to provide me with the detailed information that I can get from NHibernate, it turns out that I can get a pretty good mileage from just pushing the basics along. The first spikes with Linq to SQL are promising (more about that will show up starting next week or the one after that), and I intend to allow you to:

  • Show DataContext
  • Show SQL Statements
    • Show you the actual formatted SQL, including parameters
    • Show you the stack trace of where that SQL was generated
  • Generate alerts for bad practices such as SELECT N+1 or issuing too many queries

There are things that I can do with NHibernate that are simply not possible with other OR/Ms (something like tracking loaded entities per session, for example, or showing cached queries), but since most of those are actually capabilities that NHibernate has and the others do not, I think it is still great.

Currently the plan is to have a separate product for each OR/M, that means that buying NH Prof will not get you L2S Prof, but we will most likely have some uber license that will cover all of them.

You’ll notice that the Entity Framework isn’t listed in my initial targets list. That is for a very simple reason, plugging into EF seems to be about nine times harder than doing it with anything else. I would need to get a strong feedback that this is something that enough people are willing to pay for.

Comments

Michael Stum
10/04/2009 11:28 PM by
Michael Stum

Sweet! As I tend towards SubSonic at the moment, that's good news. As it's Open Source, maybe Rob Conery can add some hooks that would make "SubProf" more awesome?

But in any case, you're really filling a hole here, as "Just use SQL Server Profiler to profile your ORM" is not the most satisfying situation and anything that makes the ORM Black Box more transparent without losing ORM functionality (aka. "If it's slow, just replace it with hand-written ADO.net") is great!

Mike
10/05/2009 02:14 AM by
Mike

Any chance of a version that profiles ADO based code? Having something like NHProf for legacy code would be amazingly helpful.

Working with SQL Profiler after using NHProf feels like I'm going back to the stone age :)

Ayende Rahien
10/05/2009 07:44 AM by
Ayende Rahien

Mike,

Yes, that is actually planned

Mikael Henriksson
10/05/2009 07:48 AM by
Mikael Henriksson

Hi Ayende,

I am currently switching between NHibernate and Entity Framework and will continue to do so the coming years. I will end up buying NHProf eventually but I'd really love to see some Entity Framework support there.

Why is it harder to hook in to? I already built some simple query dumping / profiling methods for it and it wasn't that hard but maybe if you try to dig deeper into the framework it gets harder? Have you talked to the guys at the Entity Framework team about your plans? Maybe they'd be able to give you a few hints!

Further I am glad to see these plans of multiple ORM support. It is something that has been totally missing and it's going to be many developers best friend. Great work!

Ayende Rahien
10/05/2009 07:54 AM by
Ayende Rahien

Mikael,

How are you doing this?

And as for the difficulty, there is going to be a post about it today

neonp
10/05/2009 08:00 AM by
neonp

Hi Ayende,

Why would you like to support LINQ To SQL whilst it has been annouced that it is discontinued ? Were you talking about Entity Framework ?

Sean Kearon
10/05/2009 08:08 AM by
Sean Kearon

Sounds very good to me - how about adding XPO from Developer Express to the list sometime?

Ayende Rahien
10/05/2009 09:29 AM by
Ayende Rahien

Sean,

I would need to see how many people request it, and anyway it is something that I'll only consider after I finish the L2S one.

Ayende Rahien
10/05/2009 09:30 AM by
Ayende Rahien

Neonp.

Put simply, L2S is a low hanging fruit, it is very easy to plug into it and it is a great PoC of the xProfiler.

And no, I am specifically NOT talking about EF for now

Ayende Rahien
10/05/2009 09:33 AM by
Ayende Rahien

Mikael,

You are doing this manually, per each query?

Mikael Henriksson
10/05/2009 09:38 AM by
Mikael Henriksson

Ayende,

Semi-manual. I turned the dumping to text file on/off in ".config" whenever I have had a problem with my queries and it became quite obvious that EF in it's current release form has some serious issues with joins ;)

Ayende Rahien
10/05/2009 09:42 AM by
Ayende Rahien

When I am talking about manual, I am talking about having to touch every single query that you make

Mikael Henriksson
10/05/2009 09:51 AM by
Mikael Henriksson

I see where you are going and in that case as darn manual as it gets.

Ayende Rahien
10/05/2009 09:58 AM by
Ayende Rahien

That is more or less my point, for xProf, I can't expect you to do that.

Ayende Rahien
10/05/2009 10:03 AM by
Ayende Rahien

Kim,

I saw that, yes. That is my comment about the nine times harder than anything else.

tobi
10/05/2009 12:11 PM by
tobi

I think that you can plug into Entity Framework via reflection pretty easily. The Api would change every 2 years or so but that should not be a problem.

Alex Yakunin
10/05/2009 01:55 PM by
Alex Yakunin

That's actually a great idea. I think you must mainly think about client-side profiling API allowing any ORM to notify it on a particular event.

There are things that I can do with NHibernate that are simply not possible with other OR/Ms (something like tracking loaded entities per session, for example, or showing cached queries)

It's easy to support them if API is open.

If you'll be quick, you have high chances to be the very first on this market ;)

Alex Yakunin
10/05/2009 02:00 PM by
Alex Yakunin

I think that you can plug into Entity Framework via reflection pretty easily.

I think it's better to start from providing an open API for NHProf. If so, most ORM vendors (+ community) will create its implementations for each ORM by their own, and you'll get significantly bigger market area with almost zero efforts.

Ayende Rahien
10/05/2009 02:07 PM by
Ayende Rahien

Alex,

That is not quite as easy as it may seems.

Most of the work NH Prof is doing is done on the profiler side, not on the profiled side.

Things like extracting parameters, formatting SQL,defining alerts, etc.

Judah Himango
10/05/2009 02:08 PM by
Judah Himango

Oren,

Just to throw ideas out there, DB4O doesn't have any profiler, and of course SQL Profiler does not work in that space. We could really use a DB4O profiler there. I'd pay money for it.

It would obviously require a big big big change in your code. But I thought I'd throw it out there as a wild idea.

Ayende Rahien
10/05/2009 02:18 PM by
Ayende Rahien

Judah,

What do you want to see there?

Alex Yakunin
10/05/2009 03:25 PM by
Alex Yakunin

Most of the work NH Prof is doing is done on the profiler side, not on the profiled side.

Err... That seems even better.

On the other hand, I suspect there must be significant differences in alerts and their detection.

Ayende Rahien
10/05/2009 03:27 PM by
Ayende Rahien

Alex,

Is IS better.

But it means that there is a lot of stuff there that I would need to handle. It is not just a matter of opening up some sort of an API.

Alex Yakunin
10/05/2009 03:36 PM by
Alex Yakunin

Ah, yes - that's true. Well, that's the problem you must solve, if you're going to make it true ORM-independent ;)

E.g. alert detectors can be a part of profiler-side API. On the other hand, all info gathering stuff should be @ profiled side.

Frankly speaking, I studied NHProf just by screenshots you publish, so I don't know if it's even possible or not to implement this. I general, I feel it must be possible, but I don't know the details.

Anyway, if there will be such an API, we'd be glad to build a plugin for DO4.

Comments have been closed on this topic.