Stopwatch vs. DateTime


.NET developers usually know they should measure code performance using a Stopwatch class from the System.Diagnostics namespace. From time to time though I see code where someone uses DateTime instances for this purpose. And it’s not very surprising as DateTime class is usually the one that comes to mind when you think of time in .NET. In today’s post I would like to show you the difference in accuracy of both those approaches and the price you need to pay using either of them. We will work on this sample code that does nothing but measure time :):

Read more ›

Tagged with: , , , ,
Posted in CodeProject, Profiling .NET applications

MSMQ helper tools


In today’s short post I would like to present you three tools that I use frequently in diagnosing services that use MS Message Queues. These are:

  • MessageDumper – downloads and removes messages from queue
  • MessagePeeker – downloads but does not remove messages from queue
  • MessagePusher – sends collected messages to a given queue

MessageDumper and MessagePeeker gather messages in batches, storing each batch in a separate file. The size of the batch and the number of files is configurable from the command line. Output files can be then processed by MessagePusher and send to a different queue, for example on a developer’s machine.

Case of diagnostics

Imagine you have a production Windows Service that processes statistics. Statistics are generated by web applications on people actions and sent to your service using MS Message Queues (let’s assume the service queue is private and its name is LowLevelDesign.Stats). Some day you observe that for a specific set of statistics messages your service breaks. In order to debug the issue locally you need those messages. You may then ask your admin to stop the service, wait for the statistics to come and run:

MessagePeeker -q .\private$\LowLevelDesign.Stats -o brokenset 

This command should generate 2 files on output: brokenset.headers and brokenset.1. The first one is a header file which contains information about messages stored in other files. Copy the generated files to your local machine and run:

MessagePusher -q .\private$\LowLevelDesign.Local.Stats -i brokenset

and all the saved messages will be sent to your local queue. As said previously when you have many messages to process you may gather them in batches. The presented tools are available for download on my .NET Diagnostics Toolkit page.

Tagged with: ,
Posted in Diagnosing Applications on Windows

NullReferenceException and MachineKey.Decode


In my recent project I had to sign a http cookie in order to disallow any unauthorized changes to its content. I didn’t want to reinvent the wheel but use something already implemented in ASP.NET – for instance mechanism that is used to sign ViewState content. After some research I found promising methods: System.Web.Security.MachineKey.Encode/Decode (I’m using .NET4, in 4.5 these method are obsolete and new methods: Protect/Unprotect were introduced to replace them). Let’s first look at an example how to use those methods. The below code snippet retrieves content of a signed cookie or prints information that the cookie was tampered:

Read more ›

Tagged with: , , ,
Posted in Diagnosing ASP.NET

ASP.NET MVC bundles internals


The idea of minimizing and combining multiple script and style files into one file has been popular among web developers for quite some time. With the 4th version of ASP.NET MVC Microsoft introduced a mechanism (called bundles) that allow .NET developers to automate and control this process. Although bundles are quite easy to configure and use they might sometimes do not behave as expected. In this post I’m going to acquaint you with bundles internals and present you ways to troubleshoot problems they may generate.

Read more ›

Tagged with: , , ,
Posted in CodeProject, Diagnosing ASP.NET

The truth about app_offline.htm


In this short post I would like to present you am interesting fact about app_offline.htm. Let’s start with a small puzzle. Imagine you have 2 files in your IIS application folder: web.config and app_offline.htm. Web.config contains following lines:

<?xml version="1.0"?>
<configuration>
</configuration

and app_offline.htm:

We'll be back in a moment.

Notice that in the web.config file the configuration tag is not closed. Now the question is: what will you see if you try to access your application from the browser?

Read more ›

Tagged with: , ,
Posted in Diagnosing ASP.NET

Injecting code into .NET applications


Recently I have been playing with Function Evaluation available in .NET debugging API. This functionality allows a managed debugger to inject some arbitrary code while the debuggee is stopped. The injected code might be simply a call to the object’s ToString method or to a property getter. As a developer you profit from this service when you use Watch windows or when you run some code in the Immediate window in Visual Studio. In this post I will present you my MDbg plugin (includes a command: inject) that adopts the funceval API and an example diagnostics case in which I used it.

Read more ›

Tagged with: , , , ,
Posted in CodeProject, Using .NET debugging API

Set process memory limit with Process Governor


Today I would like to introduce you to Process Governor – a new tool I added to my .NET diagnostics toolkit. This application allows you to set a limit on a memory committed by a process. On Windows committed memory is actually all private memory that the process uses. I wrote this tool to test my .NET applications (including web applications) for memory leaks. With it I can check if under heavy load they won’t throw OutOfMemoryException.

Read more ›

Tagged with: , , , ,
Posted in CodeProject, Diagnosing Applications on Windows
Follow

Get every new post delivered to your Inbox.

Join 27 other followers