Merge pull request #1907 from elfprince13/osxDedeprecation

OSX de-deprecation (profiler and macFileIO)
This commit is contained in:
Areloch 2017-01-31 09:46:44 -06:00 committed by GitHub
commit 87c9fce380
5 changed files with 223 additions and 199 deletions

View file

@ -491,10 +491,11 @@ template<class T> T ReservedSocketList<T>::resolve(NetSocket socketToResolve)
EntryType &entry = mSocketList[socketToResolve.getHandle()];
return entry.used ? entry.value : -1;
}
ConnectionNotifyEvent* Net::smConnectionNotify = NULL;
ConnectionAcceptedEvent* Net::smConnectionAccept = NULL;
ConnectionReceiveEvent* Net::smConnectionReceive = NULL;
PacketReceiveEvent* Net::smPacketReceive = NULL;
static ConnectionNotifyEvent* smConnectionNotify = NULL;
static ConnectionAcceptedEvent* smConnectionAccept = NULL;
static ConnectionReceiveEvent* smConnectionReceive = NULL;
static PacketReceiveEvent* smPacketReceive = NULL;
ConnectionNotifyEvent& Net::getConnectionNotifyEvent()
{

View file

@ -220,7 +220,6 @@ struct Net
static ConnectionReceiveEvent* smConnectionReceive;
static PacketReceiveEvent* smPacketReceive;
static bool init();
static void shutdown();

View file

@ -27,7 +27,7 @@
#endif
#if defined(TORQUE_OS_MAC)
#include <CoreServices/CoreServices.h> // For high resolution timer
#include <mach/mach_time.h>
#endif
#include "core/stream/fileStream.h"
@ -54,9 +54,9 @@ Profiler *gProfiler = NULL;
Vector<StringTableEntry> gProfilerNodeStack;
#define TORQUE_PROFILE_AT_ENGINE_START true
#define PROFILER_DEBUG_PUSH_NODE( nodename ) \
gProfilerNodeStack.push_back( nodename );
gProfilerNodeStack.push_back( nodename );
#define PROFILER_DEBUG_POP_NODE() \
gProfilerNodeStack.pop_back();
gProfilerNodeStack.pop_back();
#else
#define TORQUE_PROFILE_AT_ENGINE_START false
#define PROFILER_DEBUG_PUSH_NODE( nodename ) ;
@ -135,20 +135,26 @@ U32 endHighResolutionTimer(U32 time[2])
void startHighResolutionTimer(U32 time[2]) {
UnsignedWide t;
Microseconds(&t);
time[0] = t.lo;
time[1] = t.hi;
U64 now = mach_absolute_time();
AssertFatal(sizeof(U32[2]) == sizeof(U64), "Can't pack mach_absolute_time into U32[2]");
memcpy(time, &now, sizeof(U64));
}
U32 endHighResolutionTimer(U32 time[2]) {
UnsignedWide t;
Microseconds(&t);
return t.lo - time[0];
// given that we're returning a 32 bit integer, and this is unsigned subtraction...
// it will just wrap around, we don't need the upper word of the time.
// NOTE: the code assumes that more than 3 hrs will not go by between calls to startHighResolutionTimer() and endHighResolutionTimer().
// I mean... that damn well better not happen anyway.
static mach_timebase_info_data_t sTimebaseInfo = {0, 0};
U64 now = mach_absolute_time();
AssertFatal(sizeof(U32[2]) == sizeof(U64), "Can't pack mach_absolute_time into U32[2]");
U64 then;
memcpy(&then, time, sizeof(U64));
if(sTimebaseInfo.denom == 0){
mach_timebase_info(&sTimebaseInfo);
}
// Handle the micros/nanos conversion first, because shedding a few bits is better than overflowing.
U64 elapsedMicros = ((now - then) / 1000) * sTimebaseInfo.numer / sTimebaseInfo.denom;
return (U32)elapsedMicros; // Just truncate, and hope we didn't overflow
}
#else
@ -283,7 +289,7 @@ void Profiler::validate()
if(!wk)
Platform::debugBreak();
for(wk = dp->mParent->mChildHash[walk->mNameHash & (ProfilerData::HashTableSize - 1)] ;
wk; wk = wk->mNextHash)
wk; wk = wk->mNextHash)
if(wk == dp)
break;
if(!wk)
@ -346,7 +352,7 @@ void Profiler::hashPush(ProfilerRootData *root)
mStackDepth++;
PROFILER_DEBUG_PUSH_NODE(root->mName);
AssertFatal(mStackDepth <= mMaxStackDepth,
"Stack overflow in profiler. You may have mismatched PROFILE_START and PROFILE_ENDs");
"Stack overflow in profiler. You may have mismatched PROFILE_START and PROFILE_ENDs");
if(!mEnabled)
return;
@ -358,7 +364,7 @@ void Profiler::hashPush(ProfilerRootData *root)
}
if(mCurrentProfilerData->mLastSeenProfiler &&
mCurrentProfilerData->mLastSeenProfiler->mRoot == root)
mCurrentProfilerData->mLastSeenProfiler->mRoot == root)
nextProfiler = mCurrentProfilerData->mLastSeenProfiler;
if(!nextProfiler)
@ -514,11 +520,11 @@ static void profilerDataDumpRecurse(ProfilerData *data, char *buffer, U32 buffer
{
// dump out this one:
Con::printf("%7.3f %7.3f %8d %s%s",
100 * data->mTotalTime / totalTime,
100 * (data->mTotalTime - data->mSubTime) / totalTime,
data->mInvokeCount,
buffer,
data->mRoot ? data->mRoot->mName : "ROOT" );
100 * data->mTotalTime / totalTime,
100 * (data->mTotalTime - data->mSubTime) / totalTime,
data->mInvokeCount,
buffer,
data->mRoot ? data->mRoot->mName : "ROOT" );
data->mTotalTime = 0;
data->mSubTime = 0;
data->mInvokeCount = 0;
@ -552,11 +558,11 @@ static void profilerDataDumpRecurseFile(ProfilerData *data, char *buffer, U32 bu
{
char pbuffer[256];
dSprintf(pbuffer, 255, "%7.3f %7.3f %8d %s%s\n",
100 * data->mTotalTime / totalTime,
100 * (data->mTotalTime - data->mSubTime) / totalTime,
data->mInvokeCount,
buffer,
data->mRoot ? data->mRoot->mName : "ROOT" );
100 * data->mTotalTime / totalTime,
100 * (data->mTotalTime - data->mSubTime) / totalTime,
data->mInvokeCount,
buffer,
data->mRoot ? data->mRoot->mName : "ROOT" );
fws.write(dStrlen(pbuffer), pbuffer);
data->mTotalTime = 0;
data->mSubTime = 0;
@ -612,10 +618,10 @@ void Profiler::dump()
for(U32 i = 0; i < rootVector.size(); i++)
{
Con::printf("%7.3f %7.3f %8d %s",
100 * (rootVector[i]->mTotalTime - rootVector[i]->mSubTime) / totalTime,
100 * rootVector[i]->mTotalTime / totalTime,
rootVector[i]->mTotalInvokeCount,
rootVector[i]->mName);
100 * (rootVector[i]->mTotalTime - rootVector[i]->mSubTime) / totalTime,
100 * rootVector[i]->mTotalTime / totalTime,
rootVector[i]->mTotalInvokeCount,
rootVector[i]->mName);
rootVector[i]->mTotalInvokeCount = 0;
rootVector[i]->mTotalTime = 0;
rootVector[i]->mSubTime = 0;
@ -637,32 +643,32 @@ void Profiler::dump()
FileStream fws;
bool success = fws.open(mDumpFileName, Torque::FS::File::Write);
AssertFatal(success, "Cannot write profile dump to specified file!");
char buffer[1024];
char buffer[1024];
dStrcpy(buffer, "Profiler Data Dump:\n");
fws.write(dStrlen(buffer), buffer);
dStrcpy(buffer, "Ordered by non-sub total time -\n");
fws.write(dStrlen(buffer), buffer);
dStrcpy(buffer, "%%NSTime %% Time Invoke # Name\n");
dStrcpy(buffer, "Profiler Data Dump:\n");
fws.write(dStrlen(buffer), buffer);
dStrcpy(buffer, "Ordered by non-sub total time -\n");
fws.write(dStrlen(buffer), buffer);
dStrcpy(buffer, "%%NSTime %% Time Invoke # Name\n");
fws.write(dStrlen(buffer), buffer);
for(U32 i = 0; i < rootVector.size(); i++)
{
dSprintf(buffer, 1023, "%7.3f %7.3f %8d %s\n",
100 * (rootVector[i]->mTotalTime - rootVector[i]->mSubTime) / totalTime,
100 * rootVector[i]->mTotalTime / totalTime,
rootVector[i]->mTotalInvokeCount,
rootVector[i]->mName);
fws.write(dStrlen(buffer), buffer);
for(U32 i = 0; i < rootVector.size(); i++)
{
dSprintf(buffer, 1023, "%7.3f %7.3f %8d %s\n",
100 * (rootVector[i]->mTotalTime - rootVector[i]->mSubTime) / totalTime,
100 * rootVector[i]->mTotalTime / totalTime,
rootVector[i]->mTotalInvokeCount,
rootVector[i]->mName);
fws.write(dStrlen(buffer), buffer);
rootVector[i]->mTotalInvokeCount = 0;
rootVector[i]->mTotalTime = 0;
rootVector[i]->mSubTime = 0;
}
dStrcpy(buffer, "\nOrdered by non-sub total time -\n");
fws.write(dStrlen(buffer), buffer);
dStrcpy(buffer, "%%NSTime %% Time Invoke # Name\n");
fws.write(dStrlen(buffer), buffer);
rootVector[i]->mTotalInvokeCount = 0;
rootVector[i]->mTotalTime = 0;
rootVector[i]->mSubTime = 0;
}
dStrcpy(buffer, "\nOrdered by non-sub total time -\n");
fws.write(dStrlen(buffer), buffer);
dStrcpy(buffer, "%%NSTime %% Time Invoke # Name\n");
fws.write(dStrlen(buffer), buffer);
mCurrentProfilerData->mTotalTime = endHighResolutionTimer(mCurrentProfilerData->mStartTime);
@ -710,12 +716,12 @@ void Profiler::enableMarker(const char *marker, bool enable)
//-----------------------------------------------------------------------------
DefineEngineFunction( profilerMarkerEnable, void, ( const char* markerName, bool enable ), ( true ),
"@brief Enable or disable a specific profile.\n\n"
"@param enable Optional paramater to enable or disable the profile.\n"
"@param markerName Name of a specific marker to enable or disable.\n"
"@note Calling this function will first call profilerReset(), clearing all data from profiler. "
"All profile markers are enabled by default.\n\n"
"@ingroup Debugging")
"@brief Enable or disable a specific profile.\n\n"
"@param enable Optional paramater to enable or disable the profile.\n"
"@param markerName Name of a specific marker to enable or disable.\n"
"@note Calling this function will first call profilerReset(), clearing all data from profiler. "
"All profile markers are enabled by default.\n\n"
"@ingroup Debugging")
{
if( gProfiler )
gProfiler->enableMarker( markerName, enable );
@ -724,37 +730,37 @@ DefineEngineFunction( profilerMarkerEnable, void, ( const char* markerName, bool
//-----------------------------------------------------------------------------
DefineEngineFunction( profilerEnable, void, ( bool enable ),,
"@brief Enables or disables the profiler.\n\n"
"Data is only gathered while the profiler is enabled.\n\n"
"@note Profiler is not available in shipping builds.\n"
"T3D has predefined profiling areas surrounded by markers, "
"but you may need to define additional markers (in C++) around areas you wish to profile,"
" by using the PROFILE_START( markerName ); and PROFILE_END(); macros.\n\n"
"@ingroup Debugging\n" )
"@brief Enables or disables the profiler.\n\n"
"Data is only gathered while the profiler is enabled.\n\n"
"@note Profiler is not available in shipping builds.\n"
"T3D has predefined profiling areas surrounded by markers, "
"but you may need to define additional markers (in C++) around areas you wish to profile,"
" by using the PROFILE_START( markerName ); and PROFILE_END(); macros.\n\n"
"@ingroup Debugging\n" )
{
if(gProfiler)
gProfiler->enable(enable);
}
DefineEngineFunction(profilerDump, void, (),,
"@brief Dumps current profiling stats to the console window.\n\n"
"@note Markers disabled with profilerMarkerEnable() will be skipped over. "
"If the profiler is currently running, it will be disabled.\n"
"@ingroup Debugging")
"@brief Dumps current profiling stats to the console window.\n\n"
"@note Markers disabled with profilerMarkerEnable() will be skipped over. "
"If the profiler is currently running, it will be disabled.\n"
"@ingroup Debugging")
{
if(gProfiler)
gProfiler->dumpToConsole();
}
DefineEngineFunction( profilerDumpToFile, void, ( const char* fileName ),,
"@brief Dumps current profiling stats to a file.\n\n"
"@note If the profiler is currently running, it will be disabled.\n"
"@param fileName Name and path of file to save profiling stats to. Must use forward slashes (/). "
"Will attempt to create the file if it does not already exist.\n"
"@tsexample\n"
"profilerDumpToFile( \"C:/Torque/log1.txt\" );\n"
"@endtsexample\n\n"
"@ingroup Debugging" )
"@brief Dumps current profiling stats to a file.\n\n"
"@note If the profiler is currently running, it will be disabled.\n"
"@param fileName Name and path of file to save profiling stats to. Must use forward slashes (/). "
"Will attempt to create the file if it does not already exist.\n"
"@tsexample\n"
"profilerDumpToFile( \"C:/Torque/log1.txt\" );\n"
"@endtsexample\n\n"
"@ingroup Debugging" )
{
if(gProfiler)
gProfiler->dumpToFile(fileName);
@ -762,9 +768,9 @@ DefineEngineFunction( profilerDumpToFile, void, ( const char* fileName ),,
DefineEngineFunction( profilerReset, void, (),,
"@brief Resets the profiler, clearing it of all its data.\n\n"
"If the profiler is currently running, it will first be disabled. "
"All markers will retain their current enabled/disabled status.\n\n"
"@ingroup Debugging" )
"If the profiler is currently running, it will first be disabled. "
"All markers will retain their current enabled/disabled status.\n\n"
"@ingroup Debugging" )
{
if(gProfiler)
gProfiler->reset();

View file

@ -76,8 +76,8 @@ TEST(Net, TCPRequest)
handler.mDataReceived = 0;
// Hook into the signals.
Net::smConnectionNotify ->notify(&handler, &TcpHandle::notify);
Net::smConnectionReceive->notify(&handler, &TcpHandle::receive);
Net::smConnectionNotify .notify(&handler, &TcpHandle::notify);
Net::smConnectionReceive.notify(&handler, &TcpHandle::receive);
// Open a TCP connection to garagegames.com
handler.mSocket = Net::openConnectTo("72.246.107.193:80");
@ -85,8 +85,8 @@ TEST(Net, TCPRequest)
while(Process::processEvents() && (Platform::getRealMilliseconds() < limit) ) {}
// Unhook from the signals.
Net::smConnectionNotify ->remove(&handler, &TcpHandle::notify);
Net::smConnectionReceive->remove(&handler, &TcpHandle::receive);
Net::smConnectionNotify .remove(&handler, &TcpHandle::notify);
Net::smConnectionReceive.remove(&handler, &TcpHandle::receive);
EXPECT_GT(handler.mDataReceived, 0)
<< "Didn't get any data back!";
@ -139,8 +139,8 @@ struct JournalHandle
mDataReceived = 0;
// Hook into the signals.
Net::smConnectionNotify ->notify(this, &JournalHandle::notify);
Net::smConnectionReceive->notify(this, &JournalHandle::receive);
Net::smConnectionNotify .notify(this, &JournalHandle::notify);
Net::smConnectionReceive.notify(this, &JournalHandle::receive);
// Open a TCP connection to garagegames.com
mSocket = Net::openConnectTo("72.246.107.193:80");
@ -149,8 +149,8 @@ struct JournalHandle
while(Process::processEvents()) {}
// Unhook from the signals.
Net::smConnectionNotify ->remove(this, &JournalHandle::notify);
Net::smConnectionReceive->remove(this, &JournalHandle::receive);
Net::smConnectionNotify .remove(this, &JournalHandle::notify);
Net::smConnectionReceive.remove(this, &JournalHandle::receive);
EXPECT_GT(mDataReceived, 0)
<< "Didn't get any data back!";

View file

@ -68,46 +68,54 @@ bool dFileTouch(const char *path)
//-----------------------------------------------------------------------------
bool dPathCopy(const char* source, const char* dest, bool nooverwrite)
{
NSFileManager *manager = [NSFileManager defaultManager];
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString *nsource = [[NSString stringWithUTF8String:source] stringByStandardizingPath];
NSString *ndest = [[NSString stringWithUTF8String:dest] stringByStandardizingPath];
NSString *ndestFolder = [ndest stringByDeletingLastPathComponent];
if(! [manager fileExistsAtPath:nsource])
{
Con::errorf("dPathCopy: no file exists at %s",source);
if(source == NULL || dest == NULL)
return false;
}
if( [manager fileExistsAtPath:ndest] )
{
if(nooverwrite)
@autoreleasepool {
NSFileManager *manager = [NSFileManager defaultManager];
NSString *nsource = [manager stringWithFileSystemRepresentation:source length:dStrlen(source)];
NSString *ndest = [manager stringWithFileSystemRepresentation:dest length:dStrlen(dest)];
NSString *ndestFolder = [ndest stringByDeletingLastPathComponent];
if(! [manager fileExistsAtPath:nsource])
{
Con::errorf("dPathCopy: file already exists at %s",dest);
Con::errorf("dPathCopy: no file exists at %s",source);
return false;
}
Con::warnf("Deleting files at path: %s", dest);
bool deleted = [manager removeFileAtPath:ndest handler:nil];
if(!deleted)
if( [manager fileExistsAtPath:ndest] )
{
Con::errorf("Copy failed! Could not delete files at path: %s", dest);
return false;
if(nooverwrite)
{
Con::errorf("dPathCopy: file already exists at %s",dest);
return false;
}
Con::warnf("Deleting files at path: %s", dest);
if(![manager removeItemAtPath:ndest error:nil] || [manager fileExistsAtPath:ndest])
{
Con::errorf("Copy failed! Could not delete files at path: %s", dest);
return false;
}
}
if([manager fileExistsAtPath:ndestFolder] == NO)
{
ndestFolder = [ndestFolder stringByAppendingString:@"/"]; // createpath requires a trailing slash
Platform::createPath([ndestFolder UTF8String]);
}
bool ret = [manager copyItemAtPath:nsource toPath:ndest error:nil];
// n.b.: The "success" semantics don't guarantee a copy actually took place, so we'll verify
// because this is surprising behavior for a method called copy.
if( ![manager fileExistsAtPath:ndest] )
{
Con::warnf("The filemanager returned success, but the file was not copied. Something strange is happening");
ret = false;
}
return ret;
}
if([manager fileExistsAtPath:ndestFolder] == NO)
{
ndestFolder = [ndestFolder stringByAppendingString:@"/"]; // createpath requires a trailing slash
Platform::createPath([ndestFolder UTF8String]);
}
bool ret = [manager copyPath:nsource toPath:ndest handler:nil];
[pool release];
return ret;
}
//-----------------------------------------------------------------------------
@ -117,25 +125,35 @@ bool dFileRename(const char *source, const char *dest)
if(source == NULL || dest == NULL)
return false;
NSFileManager *manager = [NSFileManager defaultManager];
@autoreleasepool {
NSFileManager *manager = [NSFileManager defaultManager];
NSString *nsource = [manager stringWithFileSystemRepresentation:source length:dStrlen(source)];
NSString *ndest = [manager stringWithFileSystemRepresentation:dest length:dStrlen(dest)];
NSString *nsource = [manager stringWithFileSystemRepresentation:source length:dStrlen(source)];
NSString *ndest = [manager stringWithFileSystemRepresentation:dest length:dStrlen(dest)];
if(! [manager fileExistsAtPath:nsource])
{
Con::errorf("dFileRename: no file exists at %s",source);
return false;
if(! [manager fileExistsAtPath:nsource])
{
Con::errorf("dFileRename: no file exists at %s",source);
return false;
}
if( [manager fileExistsAtPath:ndest] )
{
Con::warnf("dFileRename: Deleting files at path: %s", dest);
}
bool ret = [manager moveItemAtPath:nsource toPath:ndest error:nil];
// n.b.: The "success" semantics don't guarantee a move actually took place, so we'll verify
// because this is surprising behavior for a method called rename.
if( ![manager fileExistsAtPath:ndest] )
{
Con::warnf("The filemanager returned success, but the file was not moved. Something strange is happening");
ret = false;
}
return ret;
}
if( [manager fileExistsAtPath:ndest] )
{
Con::warnf("dFileRename: Deleting files at path: %s", dest);
}
bool ret = [manager movePath:nsource toPath:ndest handler:nil];
return ret;
}
//-----------------------------------------------------------------------------
@ -722,9 +740,9 @@ bool Platform::isSubDirectory(const char *pathParent, const char *pathSub)
inline bool isGoodDirectory(dirent* entry)
{
return (entry->d_type == DT_DIR // is a dir
&& dStrcmp(entry->d_name,".") != 0 // not here
&& dStrcmp(entry->d_name,"..") != 0 // not parent
&& !Platform::isExcludedDirectory(entry->d_name)); // not excluded
&& dStrcmp(entry->d_name,".") != 0 // not here
&& dStrcmp(entry->d_name,"..") != 0 // not parent
&& !Platform::isExcludedDirectory(entry->d_name)); // not excluded
}
//-----------------------------------------------------------------------------
@ -856,7 +874,7 @@ static bool recurseDumpDirectories(const char *basePath, const char *subPath, Ve
if ( isDir )
{
if (dStrcmp(d->d_name, ".") == 0 ||
dStrcmp(d->d_name, "..") == 0)
dStrcmp(d->d_name, "..") == 0)
continue;
if (Platform::isExcludedDirectory(d->d_name))
continue;
@ -869,8 +887,8 @@ static bool recurseDumpDirectories(const char *basePath, const char *subPath, Ve
dSprintf(child, 1024, "%s/%s", subPath, d->d_name);
if (currentDepth < recurseDepth || recurseDepth == -1 )
recurseDumpDirectories(basePath, child, directoryVector,
currentDepth + 1, recurseDepth,
noBasePath);
currentDepth + 1, recurseDepth,
noBasePath);
}
else
{
@ -881,8 +899,8 @@ static bool recurseDumpDirectories(const char *basePath, const char *subPath, Ve
dSprintf(child, 1024, "/%s", d->d_name);
if (currentDepth < recurseDepth || recurseDepth == -1)
recurseDumpDirectories(basePath, child, directoryVector,
currentDepth + 1, recurseDepth,
noBasePath);
currentDepth + 1, recurseDepth,
noBasePath);
}
}
}