Oolite 1.91.0.7644-241112-7f5034b
Loading...
Searching...
No Matches
OOLogHeader.m
Go to the documentation of this file.
1/*
2
3OOLogHeader.m
4
5
6Copyright (C) 2007-2013 Jens Ayton and contributors
7
8Permission is hereby granted, free of charge, to any person obtaining a copy
9of this software and associated documentation files (the "Software"), to deal
10in the Software without restriction, including without limitation the rights
11to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12copies of the Software, and to permit persons to whom the Software is
13furnished to do so, subject to the following conditions:
14
15The above copyright notice and this permission notice shall be included in all
16copies or substantial portions of the Software.
17
18THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24SOFTWARE.
25
26*/
27
28#import "OOLogHeader.h"
29#import "OOCPUInfo.h"
30#import "OOLogging.h"
31#import "OOOXPVerifier.h"
32#import "Universe.h"
33#import "OOStellarBody.h"
35#import "OOSound.h"
36
37
38static NSString *AdditionalLogHeaderInfo(void);
39
40NSString *OOPlatformDescription(void);
41
42
43#ifdef ALLOW_PROCEDURAL_PLANETS
44#warning ALLOW_PROCEDURAL_PLANETS is no longer optional and the macro should no longer be defined.
45#endif
46
47#ifdef DOCKING_CLEARANCE_ENABLED
48#warning DOCKING_CLEARANCE_ENABLED is no longer optional and the macro should no longer be defined.
49#endif
50
51#ifdef WORMHOLE_SCANNER
52#warning WORMHOLE_SCANNER is no longer optional and the macro should no longer be defined.
53#endif
54
55#ifdef TARGET_INCOMING_MISSILES
56#warning TARGET_INCOMING_MISSILES is no longer optional and the macro should no longer be defined.
57#endif
58
59
61{
62 // Bunch of string literal macros which are assembled into a CPU info string.
63 #if defined (__ppc__)
64 #define CPU_TYPE_STRING "PPC-32"
65 #elif defined (__ppc64__)
66 #define CPU_TYPE_STRING "PPC-64"
67 #elif defined (__i386__)
68 #define CPU_TYPE_STRING "x86-32"
69 #elif defined (__x86_64__)
70 #define CPU_TYPE_STRING "x86-64"
71 #else
72 #if OOLITE_BIG_ENDIAN
73 #define CPU_TYPE_STRING "<unknown big-endian architecture>"
74 #elif OOLITE_LITTLE_ENDIAN
75 #define CPU_TYPE_STRING "<unknown little-endian architecture>"
76 #else
77 #define CPU_TYPE_STRING "<unknown architecture with unknown byte order>"
78 #endif
79 #endif
80
81 #if OOLITE_MAC_OS_X
82 #define OS_TYPE_STRING "Mac OS X"
83 #elif OOLITE_WINDOWS
84 #define OS_TYPE_STRING "Windows"
85 #elif OOLITE_LINUX
86 #define OS_TYPE_STRING "Linux" // Hmm, what about other unices?
87 #elif OOLITE_SDL
88 #define OS_TYPE_STRING "unknown SDL system"
89 #else
90 #define OS_TYPE_STRING "unknown system"
91 #endif
92
93 #if OO_DEBUG
94 #define RELEASE_VARIANT_STRING " debug"
95 #elif !defined (NDEBUG)
96 #define RELEASE_VARIANT_STRING " test release"
97 #else
98 #define RELEASE_VARIANT_STRING ""
99 #endif
100
101 NSArray *featureStrings = [NSArray arrayWithObjects:
102 // User features
103 #if OOLITE_OPENAL
104 @"OpenAL",
105 #endif
106
107 #if OO_SHADERS
108 @"GLSL shaders",
109 #endif
110
111 #if NEW_PLANETS
112 @"new planets",
113 #endif
114
115 // Debug features
116 #if OO_CHECK_GL_HEAVY
117 @"heavy OpenGL error checking",
118 #endif
119
120 #ifndef OO_EXCLUDE_DEBUG_SUPPORT
121 @"JavaScript console support",
122 #if OOLITE_MAC_OS_X
123 // Under Mac OS X, Debug.oxp adds more than console support.
124 @"Debug plug-in support",
125 #endif
126 #endif
127
128 #if OO_OXP_VERIFIER_ENABLED
129 @"OXP verifier",
130 #endif
131
132 #if OO_LOCALIZATION_TOOLS
133 @"localization tools",
134 #endif
135
136 #if DEBUG_GRAPHVIZ
137 @"debug GraphViz support",
138 #endif
139
140 #if OOJS_PROFILE
141 #ifdef MOZ_TRACE_JSCALLS
142 @"JavaScript profiling",
143 #else
144 @"JavaScript native callback profiling",
145 #endif
146 #endif
147
148 #if OO_FOV_INFLIGHT_CONTROL_ENABLED
149 @"FOV in-flight control",
150 #endif
151
152 nil];
153
154 // systemString: NSString with system type and possibly version.
155 #if (OOLITE_MAC_OS_X || (OOLITE_GNUSTEP_1_20 && !OOLITE_WINDOWS))
156 NSString *systemString = [NSString stringWithFormat:@OS_TYPE_STRING " %@", [[NSProcessInfo processInfo] operatingSystemVersionString]];
157 #elif OOLITE_WINDOWS
158 NSString *systemString = [NSString stringWithFormat:@OS_TYPE_STRING " %@ %@-bit", operatingSystemFullVersion(), is64BitSystem() ? @"64":@"32"];
159 #else
160 #define systemString @OS_TYPE_STRING
161 #endif
162
163 NSString *versionString = nil;
164 #if (defined (SNAPSHOT_BUILD) && defined (OOLITE_SNAPSHOT_VERSION))
165 versionString = @"development version " OOLITE_SNAPSHOT_VERSION;
166 #else
167 versionString = [NSString stringWithFormat:@"version %@", [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]];
168 #endif
169 if (versionString == nil) versionString = @"<unknown version>";
170
171 NSMutableString *miscString = [NSMutableString stringWithFormat:@"Opening log for Oolite %@ (" CPU_TYPE_STRING RELEASE_VARIANT_STRING ") under %@ at %@.\n", versionString, systemString, [NSDate date]];
172
173 [miscString appendString:AdditionalLogHeaderInfo()];
174
175 NSString *featureDesc = [featureStrings componentsJoinedByString:@", "];
176 if ([featureDesc length] == 0) featureDesc = @"none";
177 [miscString appendFormat:@"\nBuild options: %@.\n", featureDesc];
178
179 [miscString appendString:@"\nNote that the contents of the log file can be adjusted by editing logcontrol.plist."];
180
181 OOLog(@"log.header", @"%@\n", miscString);
182}
183
184
186{
187 #if OOLITE_MAC_OS_X
188 NSString *systemString = [NSString stringWithFormat:@OS_TYPE_STRING " %@", [[NSProcessInfo processInfo] operatingSystemVersionString]];
189 #else
190 #define systemString @OS_TYPE_STRING
191 #endif
192
193 return [NSString stringWithFormat:@"%@ ("CPU_TYPE_STRING RELEASE_VARIANT_STRING")", systemString];
194}
195
196
197// System-specific stuff to append to log header.
198#if OOLITE_MAC_OS_X
199#include <sys/sysctl.h>
200
201
202static NSString *GetSysCtlString(const char *name);
203static unsigned long long GetSysCtlInt(const char *name);
204static NSString *GetCPUDescription(void);
205
206static NSString *AdditionalLogHeaderInfo(void)
207{
208 NSString *sysModel = nil;
209 unsigned long long sysPhysMem;
210
211 sysModel = GetSysCtlString("hw.model");
212 sysPhysMem = GetSysCtlInt("hw.memsize");
213
214 return [NSString stringWithFormat:@"Machine type: %@, %llu MiB memory, %@.", sysModel, sysPhysMem >> 20, GetCPUDescription()];
215}
216
217#ifndef CPUFAMILY_INTEL_MEROM
218 #define CPUFAMILY_INTEL_MEROM 0x426f69ef
219#endif
220
221#ifndef CPUFAMILY_INTEL_HASWELL
222 #define CPUFAMILY_INTEL_HASWELL 0x10b282dc
223#endif
224
225#ifndef CPUFAMILY_INTEL_BROADWELL
226 #define CPUFAMILY_INTEL_BROADWELL 0x582ed09c
227#endif
228
229#ifndef CPUFAMILY_INTEL_SKYLAKE
230 #define CPUFAMILY_INTEL_SKYLAKE 0x37fc219f
231#endif
232
233
234static NSString *GetCPUDescription(void)
235{
236 NSString *typeStr = nil, *subTypeStr = nil;
237
238 unsigned long long sysCPUType = GetSysCtlInt("hw.cputype");
239 unsigned long long sysCPUFamily = GetSysCtlInt("hw.cpufamily");
240 unsigned long long sysCPUFrequency = GetSysCtlInt("hw.cpufrequency");
241 unsigned long long sysCPUCount = GetSysCtlInt("hw.physicalcpu");
242 unsigned long long sysLogicalCPUCount = GetSysCtlInt("hw.logicalcpu");
243
244 /* Note: CPU_TYPE_STRING tells us the build architecture. This gets the
245 physical CPU type. They may differ, for instance, when running under
246 Rosetta. The code is written for flexibility, although ruling out
247 x86 code running on PPC would be entirely reasonable.
248 */
249 switch (sysCPUType)
250 {
251 case CPU_TYPE_POWERPC:
252 typeStr = @"PowerPC";
253 break;
254
255 case CPU_TYPE_I386:
256 typeStr = @"x86";
257 switch (sysCPUFamily)
258 {
260 subTypeStr = @" (Core 2/Merom)";
261 break;
262
263 case CPUFAMILY_INTEL_PENRYN:
264 subTypeStr = @" (Penryn)";
265 break;
266
267 case CPUFAMILY_INTEL_NEHALEM:
268 subTypeStr = @" (Nehalem)";
269 break;
270
271 case CPUFAMILY_INTEL_WESTMERE:
272 subTypeStr = @" (Westmere)";
273 break;
274
275 case CPUFAMILY_INTEL_SANDYBRIDGE:
276 subTypeStr = @" (Sandy Bridge)";
277 break;
278
279 case CPUFAMILY_INTEL_IVYBRIDGE:
280 subTypeStr = @" (Ivy Bridge)";
281 break;
282
284 subTypeStr = @" (Haswell)";
285 break;
286
288 subTypeStr = @" (Broadwell)";
289 break;
290
292 subTypeStr = @" (Skylake)";
293 break;
294
295 default:
296 subTypeStr = [NSString stringWithFormat:@" (family 0x%llx)", sysCPUFamily];
297 }
298 break;
299
300 case CPU_TYPE_ARM:
301 typeStr = @"ARM";
302 }
303
304 if (typeStr == nil) typeStr = [NSString stringWithFormat:@"CPU type %llu", sysCPUType];
305
306 NSString *countStr = nil;
307 if (sysCPUCount == sysLogicalCPUCount) countStr = [NSString stringWithFormat:@"%llu", sysCPUCount];
308 else countStr = [NSString stringWithFormat:@"%llu (%llu logical)", sysCPUCount, sysLogicalCPUCount];
309
310 return [NSString stringWithFormat:@"%@ x %@%@ @ %llu MHz", countStr, typeStr, subTypeStr, (sysCPUFrequency + 500000) / 1000000];
311}
312
313
314static NSString *GetSysCtlString(const char *name)
315{
316 char *buffer = NULL;
317 size_t size = 0;
318
319 // Get size
320 sysctlbyname(name, NULL, &size, NULL, 0);
321 if (size == 0) return nil;
322
323 buffer = alloca(size);
324 if (sysctlbyname(name, buffer, &size, NULL, 0) != 0) return nil;
325 return [NSString stringWithUTF8String:buffer];
326}
327
328
329static unsigned long long GetSysCtlInt(const char *name)
330{
331 unsigned long long llresult = 0;
332 unsigned int intresult = 0;
333 size_t size;
334
335 size = sizeof llresult;
336 if (sysctlbyname(name, &llresult, &size, NULL, 0) != 0) return 0;
337 if (size == sizeof llresult) return llresult;
338
339 size = sizeof intresult;
340 if (sysctlbyname(name, &intresult, &size, NULL, 0) != 0) return 0;
341 if (size == sizeof intresult) return intresult;
342
343 return 0;
344}
345
346#else
347static NSString *AdditionalLogHeaderInfo(void)
348{
349 unsigned cpuCount = OOCPUCount();
350 NSString *cpuDescription = OOCPUDescription();
351 OOMemoryStatus systemMemoryStatus = OOSystemMemoryStatus();
352
353 return [NSString stringWithFormat:@"%@ %u processor%@ detected. System RAM: %llu MB (free: %llu MB).", cpuDescription, cpuCount, cpuCount != 1 ? @"s" : @"", systemMemoryStatus.ooPhysicalMemory, systemMemoryStatus.ooAvailableMemory];
354}
355#endif
NSUInteger OOCPUCount(void)
Definition OOCPUInfo.m:101
static NSString * GetCPUDescription(void)
static NSString * GetSysCtlString(const char *name)
NSString * OOPlatformDescription(void)
#define CPUFAMILY_INTEL_HASWELL
#define CPUFAMILY_INTEL_SKYLAKE
static unsigned long long GetSysCtlInt(const char *name)
#define CPUFAMILY_INTEL_BROADWELL
#define CPUFAMILY_INTEL_MEROM
void OOPrintLogHeader(void)
Definition OOLogHeader.m:60
static NSString * AdditionalLogHeaderInfo(void)
#define OOLog(class, format,...)
Definition OOLogging.h:88
return nil
voidpf void uLong size
Definition ioapi.h:134