﻿ August « 2012 « So Tired !_!

So Tired !_! 逆水行舟, 不进则退!



Posted by Nick Xu



The Problem

Windows developers are used to a case-insensitive file system, which means that they might create a file called "mydata" in one place, and try to access it somewhere else as "MyData" or as "MYDATA". This breaks on most Unix setups because Unix is case sensitive[1].

Another problem is that developers sometimes hardcode the directory separator character in their source code ("\") instead of using Path.DirectorySeparator and using Path.Combine for combining this paths. This is a problem because "\" is a valid file name components on Unix. This means that if an application hardcodes for example "Logs\access_log", in Unix this will not store the contents in the "Logs" directory as the file "access_log". Instead, it will store the results in a file called "Logs\access_log".

Only a few applications cope with drive letters, but they might still pose a problem as the colon is a valid filename in Unix, which means that "A:\file" is a valid filename in the current directory.


The Usual Solution




The New Solution



  • case: makes all file system access case insensitive.
  • drive: strips drive name from pathnames.
  • all: enables both case and drive.


	$ export MONO_IOMAP=all
	$ mono myapp.exe


	MonoSetEnv MONO_IOMAP=all




IOMAP reporting utility



The code which does that is pretty fast, so it doesn't impact your application's performance too much even though it collects and stores a large amount of data (mostly pointers and some strings, though). When file name mapping is performed during file I/O, the profiler code looks up the string address and retrieves the stack trace to store it for later use. When the application exits a summary report is printed to the console which includes some statistics on the string, its original (requested) and target (mapped) form as well as a location (if it was possible to determine it) where the string was created. The location is determined using simple heuristics, so it might sometimes point to a location which is near the place where the string was created. The heuristics code walks the stack frames looking for first frame which is in application code - that is it ignores the well-known class library assemblies shipped with Mono (corlib, System*, some Mono* assemblies etc) and all the assemblies installed in the GAC. The first frame which doesn't belong in either of the above is considered to be user's code and is reported to be the string allocation location. If the stack trace doesn't contain any such frames, full trace is recorded and shown in the summary.

It is advisable to compile your application with full debugging information, so that source files and line numbers can be reported (otherwise only Namespace.Class.Method will be printed). To enable the utility, make sure the MONO_IOMAP environment variable is present and set to 'all', 'case' or 'drive' and execute your application as follows:

   mono --debug --profile=iomap your_application.exe

If you're porting an ASP.NET application, use the following command line:

Filed under: Linux No Comments