mirror of
https://github.com/glest/glest-source.git
synced 2025-08-18 06:01:17 +02:00
Added the ability to tell mega-glest where to look for glest.ini, servers.ini and all of the various .log files. The new optional environment variable that mega-glest will look for is:
GLESTHOME
This commit is contained in:
@@ -233,13 +233,13 @@ bool isdir(const char *path)
|
||||
|
||||
bool EndsWith(const string &str, const string& key)
|
||||
{
|
||||
size_t keylen = key.length();
|
||||
size_t strlen = str.length();
|
||||
bool result = false;
|
||||
if (str.length() > key.length()) {
|
||||
result = (0 == str.compare (str.length() - key.length(), key.length(), key));
|
||||
}
|
||||
|
||||
if(keylen <= strlen)
|
||||
return string::npos != str.rfind(key.c_str(),strlen - keylen, keylen);
|
||||
else
|
||||
return false;
|
||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] result [%d] str = [%s] key = [%s]\n",__FILE__,__FUNCTION__,result,str.c_str(),key.c_str());
|
||||
return result;
|
||||
}
|
||||
|
||||
//finds all filenames like path and gets their checksum of all files combined
|
||||
|
@@ -270,13 +270,13 @@ bool isdir(const char *path)
|
||||
|
||||
bool EndsWith(const string &str, const string& key)
|
||||
{
|
||||
size_t keylen = key.length();
|
||||
size_t strlen = str.length();
|
||||
|
||||
if(keylen <= strlen)
|
||||
return string::npos != str.rfind(key.c_str(),strlen - keylen, keylen);
|
||||
else
|
||||
return false;
|
||||
bool result = false;
|
||||
if (str.length() > key.length()) {
|
||||
result = (0 == str.compare (str.length() - key.length(), key.length(), key));
|
||||
}
|
||||
|
||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] result [%d] str = [%s] key = [%s]\n",__FILE__,__FUNCTION__,result,str.c_str(),key.c_str());
|
||||
return result;
|
||||
}
|
||||
|
||||
//finds all filenames like path and gets their checksum of all files combined
|
||||
@@ -475,7 +475,7 @@ void getFullscreenVideoInfo(int &colorBits,int &screenWidth,int &screenHeight) {
|
||||
//const SDL_VideoInfo* vidInfo = SDL_GetVideoInfo();
|
||||
//colorBits = vidInfo->vfmt->BitsPerPixel;
|
||||
//screenWidth = vidInfo->current_w;
|
||||
|
||||
|
||||
/*
|
||||
//screenHeight = vidInfo->current_h;
|
||||
int cx = GetSystemMetrics(SM_CXVIRTUALSCREEN);
|
||||
|
@@ -155,9 +155,6 @@ const char* WSAGetLastErrorMessage(const char* pcMessagePrefix,
|
||||
|
||||
namespace Shared{ namespace Platform{
|
||||
|
||||
bool Socket::enableDebugText = true;
|
||||
bool Socket::enableNetworkDebugInfo = true;
|
||||
|
||||
// =====================================================
|
||||
// class Ip
|
||||
// =====================================================
|
||||
|
129
source/shared_lib/sources/util/leak_dumper.cpp
Normal file
129
source/shared_lib/sources/util/leak_dumper.cpp
Normal file
@@ -0,0 +1,129 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#include "leak_dumper.h"
|
||||
|
||||
#ifdef SL_LEAK_DUMP
|
||||
|
||||
AllocInfo::AllocInfo(){
|
||||
ptr= NULL;
|
||||
file= "";
|
||||
line= -1;
|
||||
bytes= -1;
|
||||
array= false;
|
||||
free= true;
|
||||
}
|
||||
|
||||
AllocInfo::AllocInfo(void* ptr, const char* file, int line, size_t bytes, bool array){
|
||||
this->ptr= ptr;
|
||||
this->file= file;
|
||||
this->line= line;
|
||||
this->bytes= bytes;
|
||||
this->array= array;
|
||||
free= false;
|
||||
}
|
||||
|
||||
// =====================================================
|
||||
// class AllocRegistry
|
||||
// =====================================================
|
||||
|
||||
// ===================== PRIVATE =======================
|
||||
|
||||
AllocRegistry::AllocRegistry(){
|
||||
allocCount= 0;
|
||||
allocBytes= 0;
|
||||
nonMonitoredCount= 0;
|
||||
nonMonitoredBytes= 0;
|
||||
}
|
||||
|
||||
// ===================== PUBLIC ========================
|
||||
|
||||
AllocRegistry &AllocRegistry::getInstance(){
|
||||
static AllocRegistry allocRegistry;
|
||||
return allocRegistry;
|
||||
}
|
||||
|
||||
AllocRegistry::~AllocRegistry(){
|
||||
|
||||
string leakLog = "leak_dump.log";
|
||||
if(getGameReadWritePath() != "") {
|
||||
leakLog = getGameReadWritePath() + leakLog;
|
||||
}
|
||||
|
||||
dump(leakLog.c_str());
|
||||
}
|
||||
|
||||
void AllocRegistry::allocate(AllocInfo info){
|
||||
++allocCount;
|
||||
allocBytes+= info.bytes;
|
||||
unsigned hashCode= reinterpret_cast<unsigned>(info.ptr) % maxAllocs;
|
||||
|
||||
for(int i=hashCode; i<maxAllocs; ++i){
|
||||
if(allocs[i].free){
|
||||
allocs[i]= info;
|
||||
return;
|
||||
}
|
||||
}
|
||||
for(int i=0; i<hashCode; ++i){
|
||||
if(allocs[i].free){
|
||||
allocs[i]= info;
|
||||
return;
|
||||
}
|
||||
}
|
||||
++nonMonitoredCount;
|
||||
nonMonitoredBytes+= info.bytes;
|
||||
}
|
||||
|
||||
void AllocRegistry::deallocate(void* ptr, bool array){
|
||||
unsigned hashCode= reinterpret_cast<unsigned>(ptr) % maxAllocs;
|
||||
|
||||
for(int i=hashCode; i<maxAllocs; ++i){
|
||||
if(!allocs[i].free && allocs[i].ptr==ptr && allocs[i].array==array){
|
||||
allocs[i].free= true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
for(int i=0; i<hashCode; ++i){
|
||||
if(!allocs[i].free && allocs[i].ptr==ptr && allocs[i].array==array){
|
||||
allocs[i].free= true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AllocRegistry::reset(){
|
||||
for(int i=0; i<maxAllocs; ++i){
|
||||
allocs[i]= AllocInfo();
|
||||
}
|
||||
}
|
||||
|
||||
void AllocRegistry::dump(const char *path){
|
||||
FILE *f= fopen(path, "wt");
|
||||
int leakCount=0;
|
||||
size_t leakBytes=0;
|
||||
|
||||
fprintf(f, "Memory leak dump\n\n");
|
||||
|
||||
for(int i=0; i<maxAllocs; ++i){
|
||||
if(!allocs[i].free){
|
||||
leakBytes+= allocs[i].bytes;
|
||||
fprintf(f, "%d.\tfile: %s, line: %d, bytes: %d, array: %d\n", ++leakCount, allocs[i].file, allocs[i].line, allocs[i].bytes, allocs[i].array);
|
||||
}
|
||||
}
|
||||
|
||||
fprintf(f, "\nTotal leaks: %d, %d bytes\n", leakCount, leakBytes);
|
||||
fprintf(f, "Total allocations: %d, %d bytes\n", allocCount, allocBytes);
|
||||
fprintf(f, "Not monitored allocations: %d, %d bytes\n", nonMonitoredCount, nonMonitoredBytes);
|
||||
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
#endif
|
117
source/shared_lib/sources/util/profiler.cpp
Normal file
117
source/shared_lib/sources/util/profiler.cpp
Normal file
@@ -0,0 +1,117 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#include "profiler.h"
|
||||
|
||||
#ifdef SL_PROFILE
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace Shared{ namespace Util{
|
||||
|
||||
// =====================================================
|
||||
// class Section
|
||||
// =====================================================
|
||||
|
||||
Section::Section(const string &name){
|
||||
this->name= name;
|
||||
milisElapsed= 0;
|
||||
parent= NULL;
|
||||
}
|
||||
|
||||
Section *Section::getChild(const string &name){
|
||||
SectionContainer::iterator it;
|
||||
for(it= children.begin(); it!=children.end(); ++it){
|
||||
if((*it)->getName()==name){
|
||||
return *it;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void Section::print(FILE *outStream, int tabLevel){
|
||||
|
||||
float percent= (parent==NULL || parent->milisElapsed==0)? 100.0f: 100.0f*milisElapsed/parent->milisElapsed;
|
||||
string pname= parent==NULL? "": parent->getName();
|
||||
|
||||
for(int i=0; i<tabLevel; ++i)
|
||||
fprintf(outStream, "\t");
|
||||
|
||||
fprintf(outStream, "%s: ", name.c_str());
|
||||
fprintf(outStream, "%d ms, ", milisElapsed);
|
||||
fprintf(outStream, "%.1f%s\n", percent, "%");
|
||||
|
||||
SectionContainer::iterator it;
|
||||
for(it= children.begin(); it!=children.end(); ++it){
|
||||
(*it)->print(outStream, tabLevel+1);
|
||||
}
|
||||
}
|
||||
|
||||
// =====================================================
|
||||
// class Profiler
|
||||
// =====================================================
|
||||
|
||||
Profiler::Profiler(){
|
||||
rootSection= new Section("Root");
|
||||
currSection= rootSection;
|
||||
rootSection->start();
|
||||
}
|
||||
|
||||
Profiler::~Profiler(){
|
||||
rootSection->stop();
|
||||
|
||||
string profileLog = "profiler.log";
|
||||
if(getGameReadWritePath() != "") {
|
||||
profileLog = getGameReadWritePath() + profileLog;
|
||||
}
|
||||
FILE *f= fopen(profileLog.c_str(), "w");
|
||||
if(f==NULL)
|
||||
throw runtime_error("Can not open file: " + profileLog);
|
||||
|
||||
fprintf(f, "Profiler Results\n\n");
|
||||
|
||||
rootSection->print(f);
|
||||
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
Profiler &Profiler::getInstance(){
|
||||
static Profiler profiler;
|
||||
return profiler;
|
||||
}
|
||||
|
||||
void Profiler::sectionBegin(const string &name){
|
||||
Section *childSection= currSection->getChild(name);
|
||||
if(childSection==NULL){
|
||||
childSection= new Section(name);
|
||||
currSection->addChild(childSection);
|
||||
childSection->setParent(currSection);
|
||||
}
|
||||
currSection= childSection;
|
||||
childSection->start();
|
||||
}
|
||||
|
||||
void Profiler::sectionEnd(const string &name){
|
||||
if(name==currSection->getName()){
|
||||
currSection->stop();
|
||||
currSection= currSection->getParent();
|
||||
}
|
||||
else{
|
||||
throw runtime_error("Profile: Leaving section is not current section: "+name);
|
||||
}
|
||||
}
|
||||
|
||||
}};//end namespace
|
||||
|
||||
#endif
|
@@ -16,6 +16,7 @@
|
||||
#include <cstring>
|
||||
|
||||
#include "conversion.h"
|
||||
#include "util.h"
|
||||
#include "leak_dumper.h"
|
||||
|
||||
using namespace std;
|
||||
@@ -29,17 +30,22 @@ namespace Shared{ namespace Util{
|
||||
void Properties::load(const string &path){
|
||||
|
||||
ifstream fileStream;
|
||||
char lineBuffer[maxLine];
|
||||
char lineBuffer[maxLine]="";
|
||||
string line, key, value;
|
||||
int pos;
|
||||
int pos=0;
|
||||
|
||||
this->path= path;
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] path = [%s]\n",__FILE__,__FUNCTION__,__LINE__,path.c_str());
|
||||
|
||||
fileStream.open(path.c_str(), ios_base::in);
|
||||
if(fileStream.fail()){
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] path = [%s]\n",__FILE__,__FUNCTION__,__LINE__,path.c_str());
|
||||
throw runtime_error("Can't open propertyMap file: " + path);
|
||||
}
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] path = [%s]\n",__FILE__,__FUNCTION__,__LINE__,path.c_str());
|
||||
|
||||
propertyMap.clear();
|
||||
while(!fileStream.eof()){
|
||||
fileStream.getline(lineBuffer, maxLine);
|
||||
|
Reference in New Issue
Block a user