home *** CD-ROM | disk | FTP | other *** search
/ Carousel Volume 2 #1 / carousel.iso / mactosh / code / c_diskti.sit < prev    next >
Encoding:
Text File  |  1988-06-20  |  15.8 KB  |  554 lines

  1. 18-Jun-88 14:27:31-MDT,8857;000000000000
  2. Return-Path: <u-lchoqu%sunset@cs.utah.edu>
  3. Received: from cs.utah.edu by SIMTEL20.ARPA with TCP; Sat, 18 Jun 88 14:27:19 MDT
  4. Received: by cs.utah.edu (5.54/utah-2.0-cs)
  5.     id AA22174; Sat, 18 Jun 88 14:27:18 MDT
  6. Received: by sunset.utah.edu (5.54/utah-2.0-leaf)
  7.     id AA24560; Sat, 18 Jun 88 14:27:15 MDT
  8. Date: Sat, 18 Jun 88 14:27:15 MDT
  9. From: u-lchoqu%sunset@cs.utah.edu (Lee Choquette)
  10. Message-Id: <8806182027.AA24560@sunset.utah.edu>
  11. To: rthum@simtel20.arpa
  12. Subject: DiskTimer.c
  13.  
  14. /* DiskTimer.c                  Steve Brecher
  15.  *
  16.  * This is an MPW C source file.  Set Tabs to 4.
  17.  *
  18.  * This program does a performance test on the volume from which it is launched:
  19.  *              Data transfer speed:
  20.  *                      32KB reads
  21.  *                      32KB writes
  22.  *              Access time:
  23.  *                      1 512-byte read from block 0 followed by 1 512-byte read
  24.  *              from offset 1MB (volume must be at least 1MB+512bytes large)
  25.  *
  26.  * Each test is performed multiple times.
  27.  *
  28.  * The write tests use the data that was previously read, so the test is
  29.  * non-destructive.
  30.  *
  31.  * The predecessor program, DiskBench, did the I/O starting at volume offset 0.
  32.  * That was unfair if the volume started within 32KB of a cylinder boundary, or
  33.  * if the first 32KB happened to contain a remapped block or track, or required
  34.  * controller or driver retries due to a soft error.  DiskTimer does a
  35.  * pre-calibration by doing a smaller number of I/O iterations at various
  36.  * offsets up to 32KB from the start of the volume, and using the offset which
  37.  * results in the best time for the reported tests.
  38.  *
  39.  * To a avoid constant sector skew between I/Os, which might be unfair
  40.  * to some drives, there is now a varying delay between I/O requests.  The
  41.  * delay is obtained via a pseudo-random number generator, using the same
  42.  * seed on each run.
  43.  *
  44.  * In order to avoid confusion with results from the previous DiskBench
  45.  * program, DiskTimer reports results in seconds instead of ticks.
  46.  */
  47.  
  48. /* #define              Version "1.0"   /* 15-Sep-86 */
  49. #define         Version "1.1"   /* 16-Sep-86 report results in seconds */
  50.  
  51. #include        <Types.h>
  52. #include        <Strings.h>
  53. #include        <Resources.h>
  54. #include        <Quickdraw.h>
  55. #include        <Fonts.h>
  56. #include        <Windows.h>
  57. #include        <TextEdit.h>
  58. #include        <Dialogs.h>
  59. #include        <Memory.h>
  60. #include        <Events.h>
  61. #include        <Files.h>
  62. #include        <SegLoad.h>
  63.  
  64. /* If the following two counts are changed, DITL 129 must be changed also */
  65. #define TransferCount   100     /* number of times to perform data transfer tes/
  66. #define SeekCount               80      /* number of times to perform seek test/
  67.  
  68. #define CalibCount              10      /* number of read iterations for calibr/
  69. #define XferSize                (32*1024)
  70. #define WaitDlogID              128
  71. #define ResultsAlertID  129
  72. #define ErrorAlertID    130
  73. #define GreetAlertID    131
  74. #define StrVolTooSmall  128
  75.  
  76. #define CurApRefNum             ((short *)0x900)
  77. #define FCBsPtr                 ((Ptr *)0x34E)
  78. #define Ticks                   ((longword *)0x16A)
  79. #define fcbVPtr                 20
  80.  
  81. typedef unsigned long   longword;
  82.  
  83. DialogPtr       DlogPtr;
  84. Handle          BuffHndl;       /* to I/O buffer */
  85. IOParam         ioPB;
  86. longword        XferRdTicks, XferWtTicks, AccessTicks;
  87. Boolean         SkipAccess;     /* flag to skip access tests if volume too smal/
  88. longword        VolOffset;
  89.  
  90. void Error(err)
  91.         OSErr   err;
  92.         {
  93.         char    ErrStr[8];
  94.  
  95.         DisposDialog(DlogPtr);
  96.         sprintf(ErrStr, "%d", err);
  97.         ParamText(ErrStr, 0, 0, 0);
  98.         StopAlert(ErrorAlertID, 0);
  99.         ExitToShell();
  100. }
  101.  
  102. /*
  103.  * Put up intro alert; return true/false for OK/Cancel.  If OK, put up
  104.  * "Please wait" dialog and get mouse location; get data buffer.
  105.  * Note:  random seed is initted to 1 by InitGraf.
  106.  */
  107. Boolean Initialize()
  108.         {
  109.         extern struct qd qd;
  110.  
  111.     InitGraf(&qd.thePort); InitFonts(); InitWindows(); TEInit(); InitDialogs(0);
  112.         FlushEvents(everyEvent, 0);
  113.         
  114.         BuffHndl = NewHandle(XferSize);
  115.         InitCursor();
  116.         if (Alert(GreetAlertID, 0L) == ok) {
  117.                 DlogPtr = GetNewDialog(WaitDlogID, 0, (WindowPtr)-1);
  118.                 BeginUpdate(DlogPtr);
  119.                 DrawDialog(DlogPtr);
  120.                 EndUpdate(DlogPtr);
  121.                 return true; }
  122.         return false;
  123. }
  124.  
  125. longword XferTest(Count, Write)
  126.         int             Count;
  127.         Boolean Write;
  128.         {
  129.         int                     i;
  130.         OSErr           err;
  131.         longword        StartTicks, TempTicks, CurrTicks;
  132.  
  133.         StartTicks = *Ticks;
  134.         for (i=0; i<Count; ) {
  135.                 ioPB.ioPosOffset = VolOffset;
  136.                 if (Write)
  137.                         err = PBWrite(&ioPB, false);
  138.                 else
  139.                         err = PBRead(&ioPB, false);
  140.                 if (err)
  141.                         Error(err);
  142.                 if (++i < Count) {
  143.                         TempTicks = *Ticks;
  144.                         Delay((Random()&7)+1, &CurrTicks);
  145.                         StartTicks += CurrTicks - TempTicks; } }
  146.         return *Ticks - StartTicks;
  147. }
  148.  
  149. /*
  150.  * Set up ioPB with driver refNum and default volume's drive number.
  151.  * Set value of SkipAccess flag.
  152.  * Determine which offset in the set 0,4K,8K,...32K from start of volume
  153.  * results in best 32K read time.
  154.  */
  155. void Calibrate()
  156.         {
  157.         VCB                     *vcbPtr;
  158.         longword        TempTicks, BestTicks, BestOffset;
  159.  
  160.         vcbPtr = *(VCB **)(*FCBsPtr + *CurApRefNum + fcbVPtr);
  161.         ioPB.ioRefNum = vcbPtr->vcbDRefNum;
  162.         ioPB.ioVRefNum = vcbPtr->vcbDrvNum;
  163.         ioPB.ioBuffer = *BuffHndl;
  164.         ioPB.ioPosMode = fsFromStart;
  165.         ioPB.ioReqCount = 512;
  166.         VolOffset = 0;
  167.         XferTest(1, false); /* seek to start of volume */
  168.         ioPB.ioReqCount = XferSize;
  169.         BestTicks = 0xFFFFFFFF;
  170.         for (VolOffset=0; VolOffset<XferSize; VolOffset+=4096)
  171.                 if ((TempTicks=XferTest(CalibCount, false)) < BestTicks) {
  172.                         BestTicks = TempTicks;
  173.                         BestOffset = VolOffset; }
  174.         VolOffset = BestOffset;
  175.         SkipAccess = (vcbPtr->vcbAlBlkSiz * vcbPtr->vcbNmAlBlks) < VolOffset + ;
  176. }
  177.  
  178. longword AccessTest()
  179.         {
  180.         int                     i;
  181.         OSErr           err;
  182.         longword        StartTicks, TempTicks, CurrTicks;
  183.  
  184.         ioPB.ioReqCount = 512;
  185.         StartTicks = *Ticks;
  186.         for (i=0; i<SeekCount/2; ) {
  187.                 ioPB.ioPosOffset = VolOffset + 1024*1024;
  188.                 if (err = PBRead(&ioPB, false))
  189.                         Error(err);
  190.                 TempTicks = *Ticks;
  191.                 Delay((Random()&7)+1, &CurrTicks);
  192.                 StartTicks += CurrTicks - TempTicks;
  193.                 ioPB.ioPosOffset = VolOffset;
  194.                 if (err = PBRead(&ioPB, false))
  195.                         Error(err);
  196.                 if (++i < SeekCount/2) {
  197.                         TempTicks = *Ticks;
  198.                         Delay((Random()&7)+1, &CurrTicks);
  199.                         StartTicks += CurrTicks - TempTicks; } }
  200.         return *Ticks - StartTicks;
  201. }
  202.  
  203. void Results()
  204.         {
  205.         char            XferRdStr[8], XferWtStr[8], AccessStr[64];
  206.         short           itemHit;
  207.  
  208.         DisposDialog(DlogPtr);          /* take down "Please wait" */
  209.         sprintf(XferRdStr, "%6.1f", XferRdTicks/60.0);
  210.         sprintf(XferWtStr, "%6.1f", XferWtTicks/60.0);
  211.         if (SkipAccess)
  212.                 strcpy(AccessStr, p2cstr(*GetResource('STR ', StrVolTooSmall)));
  213.         else
  214.                 sprintf(AccessStr, "%6.1f", AccessTicks/60.0);
  215.         ParamText(XferRdStr, XferWtStr, AccessStr, Version);
  216.         Alert(ResultsAlertID, 0);
  217. }
  218.  
  219. main()
  220.         {
  221.         
  222.         if (Initialize()) {
  223.                 Calibrate();
  224.                 XferRdTicks = XferTest(TransferCount, false);   /* reads */
  225.                 XferWtTicks = XferTest(TransferCount, true);    /* writes */
  226.                 if (!SkipAccess)
  227.                         AccessTicks = AccessTest();
  228.                 Results(); }
  229.         ExitToShell();
  230. }
  231.  
  232.  
  233. Press <CR> to continue !}i
  234. }i
  235.  
  236. [70001,1011]
  237. DSKTIM.C                  16-Sep-86 6325               27
  238.  
  239. Enter command, N for next file
  240. or <CR> for disposition menu !
  241.  
  242. Data Library Disposition Menu
  243.  
  244.  1 (REA)  Read this file
  245.  2 (DOW)  Download this file
  246.  3 (M)    Data Library Menu
  247.  
  248.  
  249. Enter choice or <CR> for next !
  250.  
  251.  
  252. [75726,3541]
  253. MEMUTL                    12-Sep-86 4880(2112)         106
  254.  
  255.     Keywords: MEMORY AVERAGE
  256. 18-Jun-88 14:28:43-MDT,7811;000000000000
  257. Return-Path: <u-lchoqu%sunset@cs.utah.edu>
  258. Received: from cs.utah.edu by SIMTEL20.ARPA with TCP; Sat, 18 Jun 88 14:28:31 MDT
  259. Received: by cs.utah.edu (5.54/utah-2.0-cs)
  260.     id AA22192; Sat, 18 Jun 88 14:28:20 MDT
  261. Received: by sunset.utah.edu (5.54/utah-2.0-leaf)
  262.     id AA24586; Sat, 18 Jun 88 14:28:17 MDT
  263. Date: Sat, 18 Jun 88 14:28:17 MDT
  264. From: u-lchoqu%sunset@cs.utah.edu (Lee Choquette)
  265. Message-Id: <8806182028.AA24586@sunset.utah.edu>
  266. To: rthum@simtel20.arpa
  267. Subject: EarthIdle.c
  268.  
  269. #include    "MenuMgr.h"
  270. #include    "QuickDraw.h"
  271. #include    "DialogMgr.h"
  272. #include    "ToolBoxUtil.h"
  273. #include    "EventMgr.h"
  274.  
  275. #define appleMenuID        1
  276. #define fileMenuID        2
  277. #define    WNETrapNumber    0x60
  278. #define    UnImpTrapNumber    0x9f
  279. #define    AppleMenuSpot    1
  280. #define    FileMenuSpot    2
  281.  
  282. /**
  283.  **        Earth Idle [public domain]
  284.  **
  285.  **        This program was originally written by Michael Peirce  of 
  286.  **        The Black Swamp Software Company in San Jose, California
  287.  **        in LightSpeedC v2.13 from Think Technologies.  It was a way
  288.  **        to investigate how CPU time is divided up by MultiFinder.
  289.  **        
  290.  **        Feel free to play around with the source code and if
  291.  **        you get something that's either moderately interesting
  292.  **        or a nice improvement please make it available to the
  293.  **        various nets (or at least send me a copy!)...mrp
  294.  **
  295.  **        To build this program all you need is a LightSpeedC project
  296.  **        containing this source code and the MacTraps library.  You
  297.  **        also need a resource file; you can get this by simply copying
  298.  **        the original program and renaming it "Earth Idle.proj.rsrc" or
  299.  **        what ever is appropriate given the name of your project file.
  300.  **
  301.  **        If you need (or care to) contact us, you can reach us at:
  302.  **
  303.  **            The Black Swamp Software Company
  304.  **            1680 Braddock Court
  305.  **            San Jose, California 95125
  306.  **
  307.  **                    or
  308.  **
  309.  **            "MPEIRCE" on both MCI Mail and Delphi
  310.  **
  311.  **
  312.  **        Revision history...
  313.  **        _when______        _who__________        _what________________
  314.  **        06-DEC-1987        Michael Peirce        Initial prerelease (1.0B1)
  315.  **        10-DEC-1987        Michael Peirce        Shows the tick count along with spinning (1.0b2)
  316.  **        12-DEC-1987        MIchael Peirce        Now it saves the screen location across launches (1.0b3)
  317.  **        26-DEC-1987        Michael Peirce        Readied for release (1.0)
  318.  **/
  319.     
  320. main ()
  321. {
  322. register Boolean WNEisThere,showTime = TRUE;
  323. register int    i,lastTick;
  324. MenuHandle        appleMenu,fileMenu;
  325. WindowPtr        earthWindow;
  326. register PicHandle
  327.                 earthPict[64],
  328.                 backGround;
  329. EventRecord        event;
  330. Boolean            userDone = FALSE;
  331. WindowPtr         whichWindow;
  332. long            menuResult;
  333. int                windowCode,theMenu,theItem,refnum,itemHit,t=0;
  334. register    DialogPtr        AboutDialog;
  335. Rect            dragRect;
  336. int                currentEarth = 0;
  337. static char        name[255],istring[16];
  338. Point            Loc;
  339. static unsigned long    
  340.                 lastTime = 0,runningTotal = 0;
  341. static    Rect    base = {0,0,80,80};
  342. static    Boolean onlyNulls = TRUE;
  343. static unsigned long
  344.                 oldTime[10] = {0,0,0,0,0,0,0,0,0,0};
  345. Rect            **windowLocation;
  346.  
  347.     /*
  348.      *    Setup the standard items...
  349.      */
  350.  
  351.     InitGraf(&thePort);
  352.     InitFonts();
  353.     InitWindows();
  354.     InitMenus();
  355.     TEInit();
  356.     InitDialogs(0L);
  357.     InitCursor();
  358.  
  359.     lastTime   = Ticks;
  360.  
  361.     /*
  362.      *    Setup menus
  363.      */
  364.  
  365.     appleMenu = GetMenu(appleMenuID);
  366.     fileMenu  = GetMenu(fileMenuID);
  367.     CheckItem(fileMenu,1,TRUE);
  368.  
  369.     AddResMenu (appleMenu, 'DRVR');
  370.     
  371.     InsertMenu (appleMenu, 0);
  372.     InsertMenu (fileMenu, 0);
  373.     
  374.     DrawMenuBar ();
  375.  
  376.     /*
  377.      *    Setup our window - get it from the template.
  378.      */
  379.  
  380.     earthWindow = GetNewWindow(1,0L,-1L);
  381.  
  382.     /*
  383.      *    Load in the Earth pictures.
  384.      *    
  385.      *    The pictures were generated using EarthPlot 3.0 with 
  386.      *    latitude 30 degress north and longitude every 20 degrees.
  387.      *     The resource ID's are the degrees longitude.
  388.      */
  389.  
  390.     for (i=0;i<=18;i++)
  391.         earthPict[18-i] = GetPicture(i*20);
  392.  
  393.     backGround = GetPicture(-1);
  394.  
  395.     /*
  396.      *    Setup a drag rectangle that avoids the menu bar and leaves
  397.      *    a few pixels showing all the way around.
  398.      */
  399.  
  400.     SetRect(&dragRect,    4,
  401.                         24,
  402.                         screenBits.bounds.right  - 4,
  403.                         screenBits.bounds.bottom - 4);
  404.  
  405.     /*
  406.      *    Draw the info text small.
  407.      */
  408.  
  409.     SetPort(earthWindow);
  410.     TextSize(9);
  411.  
  412.     /*
  413.      *    Is MultiFinder really out there?  We really only care if
  414.      *    the WaitNextEvent trap is there to call.  If it's not
  415.      *    we're probably not in MultiFinder, but we'll run any
  416.      *    way and just use GetNextEvent.
  417.      */
  418.  
  419.     WNEisThere = NGetTrapAddress(WNETrapNumber,1) !=
  420.                  NGetTrapAddress(UnImpTrapNumber,1);
  421.  
  422.     do {
  423.         if (WNEisThere) {                    
  424.             WaitNextEvent(everyEvent,&event,0L/*WaitTime*/,0L);
  425.             /* Note to hackers: try using different values in
  426.                 the WaitTime parameter in the above call... */
  427.         }
  428.         else {
  429.             SystemTask();
  430.             GetNextEvent(everyEvent,&event);
  431.         }
  432.  
  433.         /*
  434.          *    Handle OUR events.
  435.          */
  436.  
  437.         switch (event.what) {
  438.         case updateEvt:
  439.             BeginUpdate(earthWindow);
  440.             DrawPicture(backGround,&earthWindow->portRect);
  441.             EndUpdate(earthWindow);
  442.         case mouseDown:
  443.             windowCode = FindWindow(event.where, &whichWindow);
  444.             switch (windowCode) {
  445.             case inSysWindow:
  446.                 SystemClick(&event, whichWindow);
  447.                 break;
  448.             case inMenuBar:
  449.                 menuResult = MenuSelect (event.where);
  450.                 theMenu = HiWord(menuResult);    
  451.                 theItem = LoWord(menuResult);
  452.                 switch (theMenu) {
  453.                     case 0: 
  454.                         break;
  455.                     case AppleMenuSpot: 
  456.                         if (theItem == 1) {
  457.                             /*
  458.                              *    Put up our ABOUT BOX.
  459.                              */
  460.                             AboutDialog = GetNewDialog (1,0L,(long)-1);
  461.                             ModalDialog(0L, &itemHit);
  462.                             DisposDialog(AboutDialog);
  463.                             AboutDialog = GetNewDialog (2,0L,(long)-1);
  464.                             ModalDialog(0L, &itemHit);
  465.                             DisposDialog(AboutDialog);
  466.                         }
  467.                         else {
  468.                             /*
  469.                              *    Handle DA's.
  470.                              */
  471.                             GetItem(appleMenu, theItem, name); 
  472.                             refnum = OpenDeskAcc (name);
  473.                             SetPort(earthWindow);
  474.                             }
  475.                         break;
  476.                     case FileMenuSpot:
  477.                         /*
  478.                          *    Toggle showTime or quit
  479.                          */
  480.                         switch (theItem) {
  481.                         case 1: /* SHOWTIME */
  482.                             if (showTime = !showTime)
  483.                                 CheckItem(fileMenu,1,TRUE);
  484.                             else
  485.                                 CheckItem(fileMenu,1,FALSE);
  486.                             break;
  487.                         case 2: /* SAVE WINDOW POSITION */
  488.                             /*
  489.                              *    Save our current window location.  So figure
  490.                              *    out where we are, then stuff it back into the
  491.                              *    window template resource.  **** WE SHOULD
  492.                              *    MAKE SURE THAT IT'S ON THE SCREEN WHEN WE
  493.                              *    LOAD IT BACK IN ****
  494.                              */
  495.                             windowLocation = (Rect **)GetResource('WIND',1);
  496.  
  497.                             **windowLocation = base;
  498.  
  499.                             LocalToGlobal(*windowLocation);
  500.                             LocalToGlobal(&botRight(**windowLocation));
  501.  
  502.                             ChangedResource(windowLocation);
  503.                             WriteResource(windowLocation);
  504.                             break;
  505.                         case 3:
  506.                             userDone = TRUE;
  507.                         }
  508.                         break;
  509.                 }
  510.                 HiliteMenu(0);
  511.                 break;
  512.             case inDrag:
  513.                 DragWindow(earthWindow,event.where,&dragRect);
  514.             }
  515.         }
  516.  
  517.         if (!onlyNulls || event.what==nullEvent) {
  518.             /*
  519.              *    Save what time it is now and update our running
  520.              *    total of ticks.
  521.              */
  522.     
  523.             runningTotal    = runningTotal - oldTime[t];
  524.             oldTime[t]        = Ticks - lastTime;
  525.             lastTime        = Ticks;
  526.             runningTotal    = runningTotal + oldTime[t];
  527.             
  528.             t = (t + 1) % 10;
  529.     
  530.             /*
  531.              *    Now update the screen with the new Earth picture and
  532.              *    our current running total.
  533.              */
  534.     
  535.             NumToString(runningTotal,istring);
  536.     
  537.             DrawPicture(earthPict[currentEarth],&earthWindow->portRect);
  538.     
  539.             if (showTime) {
  540.                 MoveTo(2,79);
  541.                 DrawString(istring);
  542.             }
  543.     
  544.             /*
  545.              *    Bump our current Earth picture to be the next one.
  546.              */
  547.     
  548.             currentEarth = (currentEarth + 1) % 18;
  549.         }
  550.  
  551.     } while (!userDone);
  552.  
  553. }
  554.