This is a question that I received during the Egyptian community launch of SharePoint 2010 and Office 2010. The following snippet does the trick!
SPWebService contentService = SPWebService.ContentService;
SPDeveloperDashboardSettings developerDashboard =
developerDashboard.DisplayLevel = SPDeveloperDashboardLevel.On;
The guy who asked me this question wanted to create a farm-scoped feature to easily toggle the developer dashboard instead of using Windows PowerShell or STSADM command line utility. He also promised to share his feature with me once he finishes it.
If you cannot wait and you want to do it yourself, it’s very easy thanks to Visual Studio 2010 and the new SharePoint project and item templates that ships with it. Just open up Visual Studio 2010, create an empty SharePoint project, add a farm-scoped feature, add an event receiver to the feature, copy the code above to the FeatureActivated method, deploy your solution and there you go!