|
|
1.1 ! root 1: /* ! 2: * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. ! 3: * ! 4: * @APPLE_LICENSE_HEADER_START@ ! 5: * ! 6: * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights ! 7: * Reserved. This file contains Original Code and/or Modifications of ! 8: * Original Code as defined in and that are subject to the Apple Public ! 9: * Source License Version 1.1 (the "License"). You may not use this file ! 10: * except in compliance with the License. Please obtain a copy of the ! 11: * License at http://www.apple.com/publicsource and read it before using ! 12: * this file. ! 13: * ! 14: * The Original Code and all software distributed under the License are ! 15: * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER ! 16: * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, ! 17: * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, ! 18: * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the ! 19: * License for the specific language governing rights and limitations ! 20: * under the License. ! 21: * ! 22: * @APPLE_LICENSE_HEADER_END@ ! 23: */ ! 24: ! 25: /* ! 26: File: HFSInstrumentation.c ! 27: ! 28: Contains: Code for instrumenting the File Manager ! 29: ! 30: Version: HFS Plus 1.0 ! 31: ! 32: Written by: Mark Day ! 33: ! 34: Copyright: � 1997 by Apple Computer, Inc., all rights reserved. ! 35: ! 36: File Ownership: ! 37: ! 38: DRI: Mark Day ! 39: ! 40: Other Contacts: Don Brady, Deric Horn ! 41: ! 42: Technology: xxx put technology here xxx ! 43: ! 44: Writers: ! 45: ! 46: (DSH) Deric Horn ! 47: (djb) Don Brady ! 48: (msd) Mark Day ! 49: ! 50: Change History (most recent first): ! 51: ! 52: <CS5> 7/21/97 djb Add STLogStartTime and STLogEndTime routines for summary traces. ! 53: <CS4> 7/16/97 DSH FilesInternal.i renamed FileMgrInternal.i to avoid name ! 54: collision ! 55: <CS3> 5/9/97 djb Include LowMemPriv.h ! 56: <CS2> 5/7/97 djb Add support for summary traces. ! 57: <CS1> 4/24/97 djb first checked in ! 58: <HFS5> 2/27/97 msd By default, disable the HFS instrumentation nodes. They can be ! 59: turned on at runtime with the instrumentation viewer. ! 60: <HFS4> 2/26/97 msd Add nodes for HFS:Extents, and add data descriptor for an ! 61: extent. ! 62: <HFS3> 2/6/97 msd Add a format descriptor for to help with logging FSSpec's. ! 63: <HFS2> 1/21/97 msd Create the HFS and VSM nodes in the instrumentation tree. ! 64: <HFS1> 1/17/97 msd first checked in ! 65: <0> 1/16/97 msd First written. ! 66: ! 67: */ ! 68: ! 69: #if ( PRAGMA_LOAD_SUPPORTED ) ! 70: #pragma load PrecompiledHeaders ! 71: #else ! 72: #if TARGET_OS_MAC ! 73: #include <Gestalt.h> ! 74: #include <LowMemPriv.h> ! 75: #include <Types.h> ! 76: #else ! 77: #include "../../hfs.h" ! 78: #include "../headers/system/MacOSStubs.h" ! 79: #endif /* TARGET_OS_MAC */ ! 80: #endif /* PRAGMA_LOAD_SUPPORTED */ ! 81: ! 82: #include "../headers/FileMgrInternal.h" ! 83: #include "../headers/system/HFSInstrumentation.h" ! 84: ! 85: ! 86: void GetTimeBase(UInt64 *timeBase); ! 87: ! 88: ! 89: ! 90: void InitHFSInstrumentation(void); ! 91: ! 92: ! 93: void InitHFSInstrumentation(void) ! 94: { ! 95: #if TARGET_OS_MAC ! 96: OSStatus err; ! 97: InstTraceClassRef catSearch; ! 98: FSVarsRec *fsVars; ! 99: InstPathClassRef pathClass; ! 100: InstDataDescriptorRef specDescriptor; ! 101: InstDataDescriptorRef extentDescriptor; ! 102: ! 103: fsVars = (FSVarsRec*) LMGetFSMVars(); ! 104: ! 105: err = InstInitialize68K(); ! 106: if (err != noErr) DebugStr("\pError from InstInitialize68K"); ! 107: ! 108: err = InstCreatePathClass( kInstRootClassRef, "HFS", kInstEnableClassMask, &pathClass); ! 109: if (err != noErr) DebugStr("\pError from InstCreatePathClass"); ! 110: ! 111: if ( HFSInstrumentation ) ! 112: { ! 113: err = InstCreatePathClass( kInstRootClassRef, "HFS:VSM", kInstEnableClassMask, &pathClass); ! 114: if (err != noErr) DebugStr("\pError from InstCreatePathClass"); ! 115: err = InstCreatePathClass( kInstRootClassRef, "HFS:Extents", kInstEnableClassMask, &pathClass); ! 116: if (err != noErr) DebugStr("\pError from InstCreatePathClass"); ! 117: ! 118: err = InstCreateTraceClass(kInstRootClassRef, "HFS:CatSearch", 'srch', kInstEnableClassMask, &catSearch); ! 119: if (err != noErr) DebugStr("\pError from InstCreateTraceClass"); ! 120: ! 121: fsVars->later[0] = (UInt32) catSearch; ! 122: ! 123: err = InstCreateDataDescriptor( "[vol: %d, parID: %08lX, name: %s]", &specDescriptor); ! 124: if (err != noErr) DebugStr("\pError from InstCreateDataDescriptor"); ! 125: ! 126: fsVars->later[1] = (UInt32) specDescriptor; ! 127: ! 128: err = InstCreateDataDescriptor( "fileID: %8lX, start: %8lX, num: %8lX, FABN: %8lX", &extentDescriptor); ! 129: if (err != noErr) DebugStr("\pError from InstCreateDataDescriptor"); ! 130: ! 131: fsVars->later[2] = (UInt32) extentDescriptor; ! 132: } ! 133: #endif ! 134: } ! 135: ! 136: ! 137: void STLogStartTime(UInt32 selector) ! 138: { ! 139: #if TARGET_OS_MAC ! 140: FSVarsRec *fsVars; ! 141: ! 142: fsVars = (FSVarsRec*) LMGetFSMVars(); ! 143: ! 144: if ( fsVars->gNativeCPUtype >= gestaltCPU601 ) ! 145: { ! 146: CallProfile *p; ! 147: ! 148: p = &fsVars->gCallProfile[selector]; ! 149: ! 150: if (p->refCount++ == 0) ! 151: GetTimeBase(&p->startBase); // record start time for first call (recursive calls are ignored) ! 152: } ! 153: #else ! 154: #pragma unused(selector) ! 155: #endif /* TARGET_OS_MAC */ ! 156: } ! 157: ! 158: ! 159: void STLogEndTime(UInt32 selector, OSErr error) ! 160: { ! 161: #if TARGET_OS_MAC ! 162: FSVarsRec *fsVars; ! 163: ! 164: fsVars = (FSVarsRec*) LMGetFSMVars(); ! 165: ! 166: if ( fsVars->gNativeCPUtype >= gestaltCPU601 ) ! 167: { ! 168: CallProfile *p; ! 169: UInt64 timebase; // in nanoseconds ! 170: UInt32 elaspedTime; ! 171: ! 172: p = &fsVars->gCallProfile[selector]; ! 173: p->refCount--; ! 174: ! 175: if ( p->refCount != 0 ) ! 176: return; // this is a recursive call, so skip ! 177: ! 178: GetTimeBase(&timebase); ! 179: timebase = U64Subtract(timebase, p->startBase); ! 180: ! 181: ! 182: // check if gTimeBaseFactor has been set up yet... ! 183: if ( fsVars->gTimeBaseFactor == 0 ) ! 184: { ! 185: long response; ! 186: OSErr result; ! 187: ! 188: result = Gestalt( gestaltNativeCPUtype, &response ); ! 189: if (result) return; // gTimeBaseFactor not ready yet so bail ! 190: ! 191: if ( fsVars->gNativeCPUtype == gestaltCPU601 ) ! 192: { ! 193: fsVars->gTimeBaseFactor = (UInt32) 1000; // convert from nanosec to �sec ! 194: } ! 195: else // 603 or 604 (ie has real TimeBase register) ! 196: { ! 197: result = Gestalt( gestaltBusClkSpeed, &response ); ! 198: if (result) return; // gTimeBaseFactor not ready yet so bail ! 199: ! 200: fsVars->gTimeBaseFactor = (UInt32) response / (UInt32) 4000000; // calc �sec conversion factor ! 201: } ! 202: } ! 203: ! 204: if ( timebase.hi == 0 ) ! 205: elaspedTime = timebase.lo / fsVars->gTimeBaseFactor; ! 206: else ! 207: return; // this time is too long (we're probally in the debugger!) ! 208: ! 209: ! 210: if ( elaspedTime > p->maxTime ) ! 211: p->maxTime = elaspedTime; ! 212: ! 213: if ( elaspedTime < p->minTime || p->minTime == 0 ) ! 214: p->minTime = elaspedTime; ! 215: ! 216: p->callCount++; ! 217: ! 218: if ( error != 0 ) ! 219: p->errCount++; ! 220: ! 221: timebase.lo = elaspedTime; ! 222: timebase.hi = 0; ! 223: p->totalTime = U64Add(p->totalTime, timebase); ! 224: } ! 225: #else ! 226: #pragma unused(selector,error) ! 227: #endif /* TARGET_OS_MAC */ ! 228: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.