home *** CD-ROM | disk | FTP | other *** search
- /*
- * This code illustrates how to create a tally statistic node and
- * how to update its values. The resulting tally has one bucket
- * for each of the file types present at the root level of the boot
- * volume. The bucket ID is the file type; the bucket count is the
- * number of files of that type present.
- */
-
- #include "Instrumentation.h"
-
- #include <Files.h>
-
-
- OSStatus InitInstrumentation( void);
- OSStatus TallyRootFileTypes( InstTallyClassRef tally);
-
- InstTallyClassRef gFileTypesTally;
-
-
- void main()
- {
- if ( noErr == InitInstrumentation())
- {
- TallyRootFileTypes( gFileTypesTally);
- }
- }
-
-
- OSStatus InitInstrumentation( void)
- /* Create and enable our statistics nodes. The counts are initially zero. */
- {
- OSStatus err;
-
- err = InstCreateTallyClass( kInstRootClassRef, "Samples:File Types", 20,
- kInstEnableClassMask, &gFileTypesTally);
- return err;
- }
-
-
- OSStatus TallyRootFileTypes( InstTallyClassRef tally)
- /* Count up the types of the files at the root level of the current volume. */
- {
- CInfoPBRec pb;
- WDPBRec volPB;
- OSStatus err;
- Str63 fName;
-
- volPB.ioCompletion = NULL;
- volPB.ioNamePtr = NULL;
-
- if ( noErr == ( err = PBHGetVolSync( &volPB)))
- {
- pb.hFileInfo.ioCompletion = NULL;
- pb.hFileInfo.ioNamePtr = fName;
- pb.hFileInfo.ioVRefNum = volPB.ioWDVRefNum;
- pb.hFileInfo.ioDirID = 0;
-
- for ( pb.hFileInfo.ioFDirIndex=1; noErr == PBGetCatInfoSync( &pb); pb.hFileInfo.ioFDirIndex++)
- {
- if ( pb.hFileInfo.ioFlAttrib & ioDirMask) // folder
- InstUpdateTally( tally, (void*) 'ERIK', 1);
- else
- InstUpdateTally( tally, (void*) pb.hFileInfo.ioFlFndrInfo.fdType, 1);
- pb.hFileInfo.ioDirID = 0;
- }
- }
-
- return err;
- }
-
-
-