|
|
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: Timestamp.h
27:
28: Contains: Low-impact event timing function library
29:
30: Version: 1.1
31:
32: Written by: Martin Minow
33:
34: Copyright: � 1995-1997 by Apple Computer, Inc., all rights reserved.
35:
36: Change History (most recent first):
37:
38: <1> 04/14/97 MM Conversion for Rhapsody SCSI from Copland Timestamp.h;7.
39: */
40:
41: /* Timestamp.h */
42: /*
43: * Timestamp.h
44: * Copyright 1992-97 Apple Computer Inc. All Rights Reserved.
45: * Programmed by Martin Minow,
46: * Internet: [email protected]
47: * AppleLink: MINOW
48: * Version of May 25, 1995
49: */
50: /*
51: * Usage:
52: * 1. In the makefile (or elsewhere), define TIMESTAMP non-zero. If zero, this
53: * code will be stubbed out.
54: * 2. In your initialization routine, call MakeTimestampRecord() to create a
55: * timestamp record. This will be stored in a static, private, variable.
56: * 3. When you want to time something, call StoreTimestamp() as follows:
57: * {
58: * ns_time_t eventTime;
59: * IOGetTimestamp(&eventTime);
60: * StoreTimestamp(timestampTag, timestampValue, eventTime);
61: * }
62: * Where timestampTag and timestampValue are 32-bit unsigned integers
63: * that are not otherwise interpreted by the Timestamp library. By
64: * convention, timestampTag contains a 4-byte character (Macintosh OSType)
65: * that distinguishes timing events. The OSType, OSTag, and OSString macros
66: * can be used to construct tag values. OSTag is useful for recording
67: * elapsed time:
68: * StoreTimestamp(OSTag('+', "foo"), 0, startTime);
69: * ...
70: * StoreTimestamp(OSTag('-', "foo"), 0, endTime);
71: */
72:
73: #import <objc/objc.h>
74: #import <kernserv/ns_timer.h>
75: #import <driverkit/return.h>
76: #ifndef TIMESTAMP
77: #define TIMESTAMP 1 /* TEMP TEMP TEMP */
78: #endif
79:
80: #ifndef __APPLE_TYPES_DEFINED__
81: #define __APPLE_TYPES_DEFINED__ 1
82: /**
83: * These typedef's reproduce (more or less) the Macintosh data types I'm familiar with.
84: */
85: typedef void *PhysicalAddress; /* This is an address on the PCI bus */
86: typedef vm_address_t LogicalAddress; /* This address is "visible" to software */
87: typedef unsigned int UInt32; /* A 32-bit unsigned integer */
88: typedef unsigned char UInt8; /* A "byte-sized" integer */
89: typedef signed int SInt32; /* A 32-bit signed integer */
90: typedef BOOL Boolean; /* A TRUE/FALSE value (YES/NO in NeXT) */
91: #endif /* __APPLE_TYPES_DEFINED__ */
92:
93: /**
94: * Construct a UInt32 from four characters.
95: */
96: #define OSType(c0, c1, c2, c3) ( \
97: ( ((c0) << 24) \
98: | ((c1) << 16) \
99: | ((c2) << 8) \
100: | ((c3) << 0) \
101: ))
102: /**
103: * Construct an OSType from a single character and the first three characters from
104: * a given string.
105: */
106: #define OSTag(where, what) (OSType((where), (what)[0], (what)[1], (what)[2]))
107: /**
108: * Construct an OSType from the first four characters of a C-string.
109: */
110: #define OSString(what) (OSType((what)[0], (what)[1], (what)[2], (what)[3]))
111:
112: /* .___________________________________________________________________________________.
113: | Each timestamp entry contains the following information: |
114: | timestampTag A user-specified OSType that identifies this timestamp |
115: | timestampValue A user-specified additional value |
116: | eventTime The system UpTime value at the time the data was collected. |
117: .___________________________________________________________________________________.
118: */
119: struct TimestampDataRecord {
120: UInt32 timestampTag; /* Caller's tag parameter */
121: UInt32 timestampValue; /* Caller's value parameter */
122: ns_time_t eventTime; /* Nanoseconds at Timestamp call */
123: };
124: typedef struct TimestampDataRecord TimestampDataRecord, *TimestampDataPtr;
125:
126: #if TIMESTAMP
127: void MakeTimestampRecord(
128: UInt32 nEntries
129: );
130: void StoreNSecTimestamp(
131: UInt32 timestampTag,
132: UInt32 timestampValue,
133: ns_time_t timestampEventNSec
134: );
135: void StoreTimestamp(
136: UInt32 timestampTag,
137: UInt32 timestampValue
138: );
139: /**
140: * Returns the next timestamp, if any, in resultData.
141: * @param resultData Where to store the data
142: * @return TRUE Valid data returned
143: * FALSE No data is available.
144: */
145: Boolean ReadTimestamp(
146: TimestampDataPtr resultData
147: );
148: /**
149: * Return a vector of timestamps.
150: * @param resultVector Where to store the data
151: * @param count On entrance, this has the maximum number of elements
152: * to return. On exit, this will have the actual number
153: * of elements that were returned.
154: * Note that, if the semaphore is blocked, ReadTimestampVector will not return any
155: * data. Data cannot be collected while ReadTimestampVector is copying data
156: * to the user's buffer. Note that, since the user's buffer will typically be
157: * in pageable memory, pageing I/O that might otherwise be timestamped will
158: * be lost.
159: */
160: void ReadTimestampVector(
161: TimestampDataPtr resultVector, /* -> Result buffer */
162: UInt32 *count /* -> Max count, <-actual */
163: );
164:
165: Boolean EnableTimestamp(
166: Boolean enableTimestamp /* TRUE to enable timing */
167: );
168: Boolean PreserveTimestamp(
169: Boolean preserveFirst /* TRUE to preserve start */
170: );
171: void ResetTimestampIndex(void);
172: UInt32 GetTimestampSemaphoreLostCounter(void);
173: #else /* TIMESTAMP not compiled */
174: #define MakeTimestampRecord(nEntries) /* Nothing */
175: #define StoreTimestamp(timestampTag, timestampValue, timestampEvent) /* Nothing */
176: #define ReadTimestamp(resultData) (0) /* Fails */
177: #define ReadTimestampVector(resultVector, count) do { \
178: if ((count) != NULL) { \
179: *(count) = 0; \
180: } \
181: } while (0)
182: #define EnableTimestamp(enableTimestamp) (enableTimestamp)
183: #define PreserveTimestamp(preserveFirst) (preserveFirst)
184: #define ResetTimestampIndex() /* Nothing */
185: #define GetTimestampSemaphoreLostCount() (0)
186: #endif /* TIMESTAMP */
187:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.