Hibernating Rhinos

Zero friction databases

Uber Prof Production Profiling–Profiling production application on Azure

In this post I’m going to cover one of the great features of Uber Prof v2.0: production profiling of remote applications running on Windows Azure.

The production profiling feature is currently supported in the following profilers: NHibernate Profiler, Entity Framework Profiler, Linq to SQL Profiler, LLBLGen Profiler. In this post I’m going to demonstrate how to use this with the Entity Framework Profiler.

First, we need to create our project. Since we want to host the project on Windows Azure, I’ll use an ASP.NET MVC + Web API project.


The next thing is to enable production profiling. In order to so, we need to install the EntityFrameworkProfiler.Production NuGet package.


As a side note, if you wonder what is the other package called EntityFrameworkProfiler, you probably want to read this post.

After the package is installed, you can see that it created the following file in our project:

using System;
using System.IO;
using System.Web.Http;
using HibernatingRhinos.Profiler.Production;

[assembly: WebActivator.PreApplicationStartMethod(typeof(ProductionProfilingOnAzureSample.App_Start.EntityFrameworkProfilerProductionBootstrapper), "PreStart")]
namespace ProductionProfilingOnAzureSample.App_Start
    public static class EntityFrameworkProfilerProductionBootstrapper
        public static void PreStart()
            // Initialize the profiler with the production profiling feature. 
            // Production profiling let's you let you see profiling information remotely using the following URL: http://your-server/profiler/profiler.html
            string license = GetResource("ProductionProfilingOnAzureSample.App_Start.EntityFrameworkProfilerLicense.xml");
            ProductionProfiling.Initialize(license, GlobalConfiguration.Configuration);

        private static string GetResource(string sourcesResource)
            using (var sourceCodeStream = typeof(EntityFrameworkProfilerProductionBootstrapper).Assembly.GetManifestResourceStream(sourcesResource))
                if (sourceCodeStream == null)
                    throw new InvalidOperationException(string.Format("Resource file is missing: {0}", sourcesResource));
                return new StreamReader(sourceCodeStream).ReadToEnd();

This class will run on the startup of your project and will expose a URL endpoint that we can use to load the profiler UI. In this case we’re using the GlobalConfiguration.Configuration from the WebAPI Web Host package, but please note that you can also expose your own self hosted server in order to production profile a different types of projects, like a service, or what not…

Also note that we’re embedding the license file as an embedded resource in our project and we’re passing the license string to the Initialize method of the ProductionProfiling class. This is needed since the profiler is now split into to parts, the server – which is embedded right into your application and will run within your application own process, and the UI client which is a Silverlight application that you can get from the remote server through your browser. So again, the license string is passed and evaluated right from the server initialization process.

Now it’s time to run our project. I’m running it but get the following exception: …

Resource file is missing: ProductionProfilingOnAzureSample.App_Start.EntityFrameworkProfilerLicense.xml

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: Resource file is missing: ProductionProfilingOnAzureSample.App_Start.EntityFrameworkProfilerLicense.xml
Source Error:

Line 22: 			{
Line 23: 				if (sourceCodeStream == null)
Line 24: 					throw new InvalidOperationException(string.Format("Resource file is missing: {0}", sourcesResource));
Line 25: 				return new StreamReader(sourceCodeStream).ReadToEnd();
Line 26: 			}

Source File: c:\Users\Fitzchak\Documents\Visual Studio 11\Projects\ProductionProfilingOnAzureSample\ProductionProfilingOnAzureSample\App_Start\EntityFrameworkProfilerBootstrapper.cs    Line: 24

Remember what I told you? We need to embedded a license file. So let’s go and ask for a trial license file: http://hibernatingrhinos.com/products/efprof/trial.

After that I’m doing that, I got a trial license in my email inbox. Now we need to include this in the project as an embedded resource.


And now we are ready to see the profiler in action. Run the project and browse to the /profiler/profiler.html endpoint:


Do you see that? This is Entity Framework Profiler running right in your browser and let you profile your remote production application right from your computer!

You may be wonder why we do not see actual data in the profiler yet but this is your work to do. Attach it to your application and you’ll see some nice information that will let you understand what your ORM is doing easily.

Here is an example:

ScreenShots-EFProf-InBrowser (1)

Wait a second… Didn’t you said that we’re going to run this on Azure?

Yes, I added the following code to the HomeController and pushed the code to azure:

public class HomeController : Controller
    public ActionResult Index()
        for (int i = 0; i < 2; i++)
            using (var context = new ApplicationContext())

                context.Messages.Add(new Message {Text = "Text 1", CreatedAt = DateTime.UtcNow});

                var messages = context.Messages.ToList();

                var messages2 = context.Messages
                                        .Where(message => message.Text == "Profiling on Azure" && message.Text.Length > 10)
        return View();

You can run the above code by opening the following page,  http://efprof.cloudapp.net/, and see the profiler in action here: http://efprof.cloudapp.net/profiler/profiler.html.


For any feedback, please contact us in the profilers forums, by email (support at hibernatingrhinos.com) or just leave a comment here.


Published at

Originally posted at

Comments (3)

What’s new in Uber Prof v2.0?

Along with the launch of our new website hibernatingrhinos.com, we’re happy to announce that v2.0 of Uber Prof profilers is now in beta!

While we’re perfecting the product, you can take advantage on that and buy a license now with a 20% discount. This will work for both monthly license and standard license.

You can also request a trial license on the website, which will let you use the profiler for 30 days.

Now for the interesting staff, what’s new in Uber Prof v2.0?

1. Silverlight interface. When you run the profiler.exe the UI that opens is a OOB Silverlight application. You can also open the profiler interface in your browser, which means that you can profiler remote systems! In fact, we ported all of the WPF user interface of v1.0 to Silverlight in order to enable production profiling of remote systems.


2. Production profiling. We now supports profiling production systems, using the HibernatingRhinos.Profiler.Production.dll. If you’re using ASP.NET MVC, you will be able to configure the profiler to use the following route “/profiler” in order to see the profiler interface in your browser.


3. Performance. We tuned to performance of the profiler and the profiler now it far more responsive. You can run the profiler now for days, and it will still work.


4. Running on the cloud. We did some work in order to let you profile your application on Azure. You can profiler your cloud application right from your browser, using the production profiling feature.

The next post will contains instructions how to run the profiler in a production application, on Azure.


Published at

Originally posted at

Comments (1)