

		Microsoft Windows NT Working Set Tuner README File

                       September 04, 1994



1.  Description:
----------------

	Windows NT (32-bit) Working Set Tuner (WST) for x86, Mips,
        Alpha, and PowerPC platforms.

	The working set of a program is a collection of those pages in the
	program's virtual address space which have recently been referenced.
	As the working set size decreases, memory demand decreases.  Since
	it is advantageous to minimize the memory demand, the working set
	tuner DLL is developed to measure code working set, and produce an
	ordering of the functions (procedures) within the code which will be
	small, if not minimal, in a paging environment.  In any practical case
	there are probably many optimal assignments of functions to pages.
	Although this method does not claim optimality, it will produce results
	at least as good as a programmer could achieve by hand in a reasonable
	amount of time.  This method consists of two parts:

	1)  Data Collection:

		Data is collected in C programs by using the attributed
	profiling hook provided by the Microsoft C compiler (compiling with the
	"-Gh" option).  Data is not collected in assembler language programs.
	A hook routine in the working set tuner DLL, WST.DLL, is called before
	each C functions is called.  The hook examines its environment to
	determine the identity of the called function.  A bit is set in a
	bitmap every time a function is called within the specified time segment.
	A new bitmap is used (new snapshot) for each new time segment: smaller
	time segments will cause higher frequency of snapshots which will
	produce better working set (with some diminishing point of return...).
	The collected WST data is dumped upon the program's termination or via
	WST's dump facility called WstDump.exe.  Functions' symbols in the
	program's symbol table are used by the WST.dll to match function names
	to bits in the bitmap.

	2)  Data Reduction:

		Two post-processing tools, WstCat.exe & WsTune.exe, were
	developed to process the collected data and produce an ordering of the
	functions (packing list) which, when placed into pages, will result
	in a smaller working set of pages in memory compared to its original
	working set size for the activity measured.  The packing list, created
	using an ordering algorithm, can be used by the linker to perform the
	actual packing within the executable's object modules.



2.  WST Files:
--------------

	o  wst.ini	 -- WST initialization file.
	o  wst.dll	 -- WST DLL.
	o  wst.lib	 -- WST library file containing WST entry point.
	o  wstdump.exe	 -- Dump utility for dumping/clearing wst data, and
			    stopping data collection at any time.
	o  wstune.exe	 -- Data analysis utility for creating the packing list
			    from collected data.
	o  wstcat.exe	 -- Concatenation utility for multiple data files.
	o  penter.lib    -- An empty library containing a dummy WST entry point.
	                    This can be used instead of WST.lib to link with an
			    executable object module which was compiled with the
			    -Gh option, so the application can run without recompiling
                            and without any of the WST overheads.



3.  Using the Working Set Tuner Dll:
------------------------------------

	o  Create the WST directory in the root directory of C: drive. (c:\wst)

	o  Place WST.INI in the WST directory of C: drive and list all
	   the DLL/EXE images to be tuned as follows:

	   (Note:  WST.INI and all its three section headers must exist but the
	    sections could be left blank)

	   [EXES]
	   Name of applications to be tuned. Each name should be on a
	   new line.

	   [PATCH IMPORTS]
           List of DLLs/EXEs to be tuned for all of their imported entries.
           Each name should be on a new line.

	   [TIME INTERVAL]
	   Elapsed time in milliseconds between recording snapshots
	   (if left blank default time interval of 1000 is used)

	o  Sample WST.INI file:

	   [EXES]
	   myapp.exe

	   [PATCH IMPORTS]

	   [TIME INTERVAL]
	   1500

	o  Attach WST.DLL to the application process:

	   -  Recompile your EXE/DLL using the "-Gh" and "-Zd" compiler
	      options.  (NOTE - on Mips platform, use "-Od" to disable
              compiler optimization.)


	   -  Link it with WST.LIB using the "-debugtype:coff" and
	      "-debug:mapped,partial" linker options.

	   -  This method will cause all the C functions in the recompiled
	      sources to be accessible to WST.DLL.

           NOTE:-  If symbols have been removed from your exe
           or dll, Wst will try to locate the symbols files (DBG
           files) using the path as specified in the environment
           variable "_nt_symbol_path".
           E.G. if the DBG file of your exe is in c:\symbols\exe, set
           _nt_symbol_path to c:\symbols.

	o  Place WST.DLL in your SYSTEM directory (i.e. ..\nt\system32).

	o  If this is the only run that is to be considered for tuning, clear
	   any existing .TMI and .WSP files in C:\WST directory.

	o  Run your applications.

	o  Data will be collected for all the applications specified in the
	   [EXES] section of the WST.INI.

	o  Exit the application to dump the WST data, or run WstDump.exe
	   to dump the data.  See section 4 "WST Data" for details.

	o  If you have multiple TMI & WSP files, run WstCat.exe to concatenate
	   data from multiple runs.  See section 5 "Using WstCat" for details.

	o  Run WsTune.exe to generate the packing list (.prf file) based on
	   the collected WST data.  See section 6 "Using WsTune" for details.

	o  Use the packing list to direct the linker to order the modules
	   as specified in the packing list (.prf file).  See section 8
	   "Linking with the Packing List" for details.



4.  WST Data:
-------------

	o  WST data can be captured in two ways:

	   1)  Upon termination of the application WST data is dumped
	       automatically.

	   2)  Using the dump utility, WstDump.exe, WST data can be dumped
	       at any time.  See section 7 "Using WstDump" for details.


	o  Data files are created in C:\WST directory.

	o  WST data is dumped into data files using the application and its
	   DLLs names with .TMI & .WSP extensions.

	o  If TMI & WSP files exist in the c:\wst directory, new data files
           with .T?? and .W?? are created where ?? is a number between
           0x01-0xff.  The number indicates the run number.  All the data
           files can be concatenated (using WstCat.exe) to generate a single
           packing list from the multiple run data files.



5.  Using WstCat:
-----------------

	o  WstCat.exe can be used to concatenate multiple .WSP and .TMI files
	   (multiple files will be named *.T00 - *.Tff and *.W00 - *.Wff)
	   into a single file for analysis.  This allows the user to run
	   multiple scenarios, over time, and analyze them as a single run.
	   WST will also create multiple files if a scenario exceeds its 3200
	   snapshots limit.

	   Usage:  WstCat modulename

     		   modulename is the name of the DLL or EXE which is being
		   tuned and data has been collected for.

	   Note:  The original TMI & WSP files will be renamed to TXX & WXX
	          by WstCat.



6.  Using WsTune:
-----------------

	o  WsTune.exe is used to analyze the data created by WST.  WsTune
	   will also create the packing list, .PRF file, which is used by
	   the linker to pack your DLL or EXE.

	o  The DATA files created by wstune are:

	        -  .DT (Data Tuned) contains the analysis data/bitstrings for
		   all api's called in the "packing list" order.

		-  .DN (Data Not tuned) contains the api's called in
		   the "unpacked" order.

		-  .PRF contains the packing list to be used by the linker.

		-  .WSR is a worker index file created for internal use.
		

	   Usage:  WsTune [/O] [/D] [/N] [?] ModuleName.WSP

		   /O   Dump data to file (*.DT tuned & *.DN not tuned).
		   /D   Dump analysis data only (don't dump bitstrings data).
		   /N   Just analyze bitstring data, don't dump any data.
		   /?   Causes the usage message to be displayed.



7.  Using WstDump:
------------------

	o  WstDump.exe can be used to stop WST data collection and clear/dump
	   WST collected data for all the applications being tuned, at any time.

	o  The following options are available via WstDump.exe:

	      - Stop : Stops WST data collection (applications continue to run).

	      - Clear and Restart : Clears any existing WST data and
				    restarts data collection.

	      - Dump and Stop : Dumps any existing WST data and stops the
				data collection (applications continue to run).

	o  Data is dumped to C:\WST using the application and its DLLs names
           with .TMI & .WSP extensions.

	o  If TMI & WSP files exist in the C:\WST directory, new data files
           with .T?? and .W?? are created where ?? is a number between
           0x01-0xff.  The number indicates the run number.  All the data
           files can be concatenated (using WstCat.exe) to generate a single
           packing list from the multiple run data files.




8.  Linking with the Packing List:
----------------------------------

	o  Recompile your applications using the Microsoft C Compiler "-Gy"
	   option.  (Remove the "-Gh" option to avoid extra overhead.)

	o  Relink your applications using the link "-order:@filename" option
	   where filename is the name of your packing list (i.e. .prf file
	   generated by WsTune.exe).



9.  Caveats:
------------

	o  If symbols are not available in an EXE/DLL that is being tuned,
	   ??? is displayed as the function name in data and analysis files
	   (??? is not listed in the packing list, however.)

	o  WST data is *NOT* collected for functions in assembler language
	   programs/objects.



** END OF README **
