A Humble Geek Wannabe
"The competent programmer is fully aware of the strictly limited size of his own skull; therefore he approaches the programming task in full humility, and among other things he avoids clever tricks like the plague." - Edsger W.Dijkstra
Thursday, March 15, 2012
Dumping ground for some useful WinDbg commands
1. Setup symbols path
srv*C:\symbols\web*http://msdl.microsoft.com/download/symbols;C:\symbols\web;C:\symbols\private
2. Load SOS
.loadby sos mscorwks(or "clr" when on .NET 4 tools)
.load sosex
.reload
3. Usefull commands
!threadpool
We can then use the !Threadpool-command to find out exactly what the CPU-usage was at the time the dump was taken. We'll also get some useful information like the number of work requests in the queue, completion port threads and timers.
!runaway
This is a nice command that will list all running threads and their CPU-usage. It's your best friend when troubleshooting a high CPU hang issue.
!threads
To get more information about the running threads we can run the !Threads-command. This will list all managed threads in the application, what application domain the thread is currently executing under, etc.
Switch to thread: ~[number of thread]s ex: ~50s
!clrstack -p
List the stack for the current thread
!pe
Print exception
Display all managed threads call stacks:
~*e !CLRStack (~ = symbol for thread, * = any, e = execute an action. Mean: for each thread, execute !CLRStack command)
###Memory leaks###
!eeheap -gc
!dumpheap -stat
!dumpobject (!do)
!dumpstackobjects (!dso)
!dumparray (!da)
!dumpheap -stat -type TextBox
!dumpheap -mt "address"
!gcroot "address" --see what is keeping alive this object
###Sosex###
!dlk - detect deadlock
!mk
To cancel a long execution in debugger (BUSY word on left bottom), press CTRL + Pause
Link to sosex : http://www.stevestechspot.com/
List of available commands: http://msdn.microsoft.com/en-us/library/bb190764(VS.80).aspx
Other links:
http://blogs.msdn.com/b/johan/archive/2007/01/11/how-to-install-windbg-and-get-your-first-memory-dump.aspx
http://blogs.msdn.com/b/tess/archive/tags/debugging/
http://blogs.msdn.com/b/tess/archive/2008/02/04/net-debugging-demos-information-and-setup-instructions.aspx
Friday, June 4, 2010
How to Use WinMerge as the Diff tool for Mercurial
- Open Mercurial.ini config file. On my WIN7 system, this file exists at C:\Users\MyUser\Mercurial.ini. If you are on an XP system, it's probably in C:\Documents and Settings\<your user name>\Mercurial.ini.
- Add the following lines:
[extdiff]
cmd.winmerge = C:\Program Files (x86)\WinMerge\WinMergeU.exe
opts.winmerge = /e /x /ub /wl
[merge-tools]
winmergeu.executable = C:\Program Files (x86)\WinMerge\WinMergeU.exe
winmergeu.priority= 1
winmergeu.fixeol=True
winmergeu.checkchanged=True
winmergeu.args= /e /ub /dl other /dr local $other $local $output
winmergeu.gui=False
winmergeu.binary=True
[tortoisehg]
vdiff = winmerge - Now run TortoiseHg's Global Settings tool. On the TortoiseHg tab, select winmerge for the Visual Diff Command, and winmergeu for the Three-way Merge Tool options, apply, close.
http://superuser.com/questions/23576/how-to-use-winmerge-as-the-diff-tool-for-mercurial
http://stackoverflow.com/questions/2073543/use-winmerge-as-tortoisehg-merge-tool
Tuesday, April 27, 2010
Add binary serialization to a WCF webservice using UsernameOverTransport security
In order to enable this we have to add a new binding to our service and specify which endpoint to use. Add the following binding to the bindings section in the web.config on the service and client side:
<customBinding>
<binding name="binaryHttpBinding">
<security authenticationMode="UserNameOverTransport" requireSecurityContextCancellation="true" >
<secureConversationBootstrap authenticationMode="UserNameForSslNegotiated" />
</security>
<binaryMessageEncoding maxReadPoolSize="2147483647" maxSessionSize="2147483647" maxWritePoolSize="2147483647">
<readerQuotas maxDepth="32" maxStringContentLength="5242880"
maxArrayLength="200000" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
</binaryMessageEncoding>
<httpsTransport maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"></httpsTransport>
</binding>
</customBinding>
Specify an endpoint for it like this, and you are ready to go:
<endpoint address="" binding="customBinding" bindingConfiguration="binaryHttpBinding" contract="ServiceLibrary.MyService" />
Hope this helps, I searched a while for the solution and it wasn't on the web.
Starting to love this WCF thingy :)
Saturday, March 20, 2010
How to properly close WCF connections
If you don’t have the time to read the article and the references, the summary is that using the Dispose pattern is a bad practice for WCF connections, because well, someone at MSFT screwed up the design and ICommunicationObject.Close() throws a bunch of exceptions, which goes against the specifications for IDisposable which should NEVER throw an exception on Dispose(). So let’s see what code I have before:
18 {
19 public void Dispose()
20 {
21 Close();
22 }
23 }
This is better than we had before, but maybe I can improve this more. Any ideas?
Develop with passion,
Adrian
Wednesday, January 27, 2010
IPad
The IPad has some serious downsides, maybe the best outcome is Amazon releasing a cheaper/better Kindle soon?
IPad is interesting, but I still favor a netbook/PC + e-Reader, a lot more openness and possibilities.
Sunday, January 24, 2010
Building my own website
Giving the fact that at work I will continue working with Web Forms for the next year I think, I need to start some home project to learn Asp.Net MVC. I'm thinking for some time at creating my own website, so this seems to be a great opportunity to do something useful while learning. I know that there are a bunch of blogging engines for .NET, but I think I will do it from scratch anyway.
I wonder how soon I will have something usable...
Monday, September 28, 2009
Books
- Test Driven Development by Example - this is a great introductory book for TDD, what I enjoyed the most about it was the easy writing style and the small jokes throughout the book, see the comment regarding Singleton pattern :) Reading this book made me feel that I can somehow absorb author's knowledge and experience about code quality and design even if this wasn't the main purpose of the book.
- Refactoring: Improving the design of existing code - well, this is the best book related to programming I've read so far, a book which I will reread each year. The 4th chapter, related to Code Smells is really great and succeeds at naming almost all smells found in a bad code. Reading this book you realize how many times you sort of felt that the code is "smelling", but you didn't know how to make it clean and how to tackle the problem. This is a must read for every programmer, I guarantee that it will change how you look at coding.
- Working Effectively with Legacy Code - a great book by Michael Feathers, sort of complementary to Refactoring by Fowler. This book is about "safe" refactoring s, how can you find the sensing points and how to introduce tests in a legacy code base. Giving the fact that 80-90% of the time we are working with a legacy code base, sometimes we even write "legacy code", this is a must read for every programmer, at least once :)
- Clean Code - great book by Uncle Bob, this contains his amendments about how clean code should look like. Even if you don't have to agree with him on all of his rules, certainly our lives would be much easier if all the programmers would follow 80-90% of the rules. Giving the fact that the definition for "clean code" is not set in stone yet, the most important thing is to try create clean and beautiful code, code that we will be proud of or at least not embarrassed in the future :)