This commit is contained in:
Igor Pavlov
2011-04-11 00:00:00 +00:00
committed by Kornel Lesiński
parent de4f8c22fe
commit 35596517f2
322 changed files with 9989 additions and 7759 deletions

View File

@@ -2,296 +2,41 @@
#include "StdAfx.h"
#include "../../../Common/IntToString.h"
#include "../../../Common/MyCom.h"
#if !defined(_7ZIP_ST) || defined(_WIN32)
#include "../../../Windows/System.h"
#endif
#include "../Common/Bench.h"
#include "BenchCon.h"
#include "ConsoleClose.h"
struct CTotalBenchRes
struct CPrintBenchCallback: public IBenchPrintCallback
{
UInt64 NumIterations;
UInt64 Rating;
UInt64 Usage;
UInt64 RPU;
void Init() { NumIterations = 0; Rating = 0; Usage = 0; RPU = 0; }
void Normalize()
{
if (NumIterations == 0)
return;
Rating /= NumIterations;
Usage /= NumIterations;
RPU /= NumIterations;
NumIterations = 1;
}
void SetMid(const CTotalBenchRes &r1, const CTotalBenchRes &r2)
{
Rating = (r1.Rating + r2.Rating) / 2;
Usage = (r1.Usage + r2.Usage) / 2;
RPU = (r1.RPU + r2.RPU) / 2;
NumIterations = (r1.NumIterations + r2.NumIterations) / 2;
}
FILE *_file;
void Print(const char *s);
void NewLine();
HRESULT CheckBreak();
};
struct CBenchCallback: public IBenchCallback
void CPrintBenchCallback::Print(const char *s)
{
CTotalBenchRes EncodeRes;
CTotalBenchRes DecodeRes;
FILE *f;
void Init() { EncodeRes.Init(); DecodeRes.Init(); }
void Normalize() { EncodeRes.Normalize(); DecodeRes.Normalize(); }
UInt32 dictionarySize;
HRESULT SetEncodeResult(const CBenchInfo &info, bool final);
HRESULT SetDecodeResult(const CBenchInfo &info, bool final);
};
static void NormalizeVals(UInt64 &v1, UInt64 &v2)
{
while (v1 > 1000000)
{
v1 >>= 1;
v2 >>= 1;
}
fputs(s, _file);
}
static UInt64 MyMultDiv64(UInt64 value, UInt64 elapsedTime, UInt64 freq)
void CPrintBenchCallback::NewLine()
{
UInt64 elTime = elapsedTime;
NormalizeVals(freq, elTime);
if (elTime == 0)
elTime = 1;
return value * freq / elTime;
Print("\n");
}
static void PrintNumber(FILE *f, UInt64 value, int size)
HRESULT CPrintBenchCallback::CheckBreak()
{
char s[32];
ConvertUInt64ToString(value, s);
fprintf(f, " ");
for (int len = (int)strlen(s); len < size; len++)
fprintf(f, " ");
fputs(s, f);
return NConsoleClose::TestBreakSignal() ? E_ABORT: S_OK;
}
static void PrintRating(FILE *f, UInt64 rating)
HRESULT BenchCon(DECL_EXTERNAL_CODECS_LOC_VARS
const CObjectVector<CProperty> props, UInt32 numIterations, FILE *f)
{
PrintNumber(f, rating / 1000000, 6);
}
static void PrintResults(FILE *f, UInt64 usage, UInt64 rpu, UInt64 rating)
{
PrintNumber(f, (usage + 5000) / 10000, 5);
PrintRating(f, rpu);
PrintRating(f, rating);
}
static void PrintResults(FILE *f, const CBenchInfo &info, UInt64 rating, CTotalBenchRes &res)
{
UInt64 speed = MyMultDiv64(info.UnpackSize, info.GlobalTime, info.GlobalFreq);
PrintNumber(f, speed / 1024, 7);
UInt64 usage = GetUsage(info);
UInt64 rpu = GetRatingPerUsage(info, rating);
PrintResults(f, usage, rpu, rating);
res.NumIterations++;
res.RPU += rpu;
res.Rating += rating;
res.Usage += usage;
}
static void PrintTotals(FILE *f, const CTotalBenchRes &res)
{
fprintf(f, " ");
PrintResults(f, res.Usage, res.RPU, res.Rating);
}
HRESULT CBenchCallback::SetEncodeResult(const CBenchInfo &info, bool final)
{
if (NConsoleClose::TestBreakSignal())
return E_ABORT;
if (final)
{
UInt64 rating = GetCompressRating(dictionarySize, info.GlobalTime, info.GlobalFreq, info.UnpackSize);
PrintResults(f, info, rating, EncodeRes);
}
return S_OK;
}
static const char *kSep = " | ";
HRESULT CBenchCallback::SetDecodeResult(const CBenchInfo &info, bool final)
{
if (NConsoleClose::TestBreakSignal())
return E_ABORT;
if (final)
{
UInt64 rating = GetDecompressRating(info.GlobalTime, info.GlobalFreq, info.UnpackSize, info.PackSize, info.NumIterations);
fputs(kSep, f);
CBenchInfo info2 = info;
info2.UnpackSize *= info2.NumIterations;
info2.PackSize *= info2.NumIterations;
info2.NumIterations = 1;
PrintResults(f, info2, rating, DecodeRes);
}
return S_OK;
}
static void PrintRequirements(FILE *f, const char *sizeString, UInt64 size, const char *threadsString, UInt32 numThreads)
{
fprintf(f, "\nRAM %s ", sizeString);
PrintNumber(f, (size >> 20), 5);
fprintf(f, " MB, # %s %3d", threadsString, (unsigned int)numThreads);
}
HRESULT LzmaBenchCon(
DECL_EXTERNAL_CODECS_LOC_VARS
FILE *f, UInt32 numIterations, UInt32 numThreads, UInt32 dictionary)
{
if (!CrcInternalTest())
return S_FALSE;
#ifndef _7ZIP_ST
UInt64 ramSize = NWindows::NSystem::GetRamSize(); //
UInt32 numCPUs = NWindows::NSystem::GetNumberOfProcessors();
PrintRequirements(f, "size: ", ramSize, "CPU hardware threads:", numCPUs);
if (numThreads == (UInt32)-1)
numThreads = numCPUs;
if (numThreads > 1)
numThreads &= ~1;
if (dictionary == (UInt32)-1)
{
int dicSizeLog;
for (dicSizeLog = 25; dicSizeLog > kBenchMinDicLogSize; dicSizeLog--)
if (GetBenchMemoryUsage(numThreads, ((UInt32)1 << dicSizeLog)) + (8 << 20) <= ramSize)
break;
dictionary = (1 << dicSizeLog);
}
#else
if (dictionary == (UInt32)-1)
dictionary = (1 << 22);
numThreads = 1;
#endif
PrintRequirements(f, "usage:", GetBenchMemoryUsage(numThreads, dictionary), "Benchmark threads: ", numThreads);
CBenchCallback callback;
callback.Init();
callback.f = f;
fprintf(f, "\n\nDict Compressing | Decompressing\n ");
int j;
for (j = 0; j < 2; j++)
{
fprintf(f, " Speed Usage R/U Rating");
if (j == 0)
fputs(kSep, f);
}
fprintf(f, "\n ");
for (j = 0; j < 2; j++)
{
fprintf(f, " KB/s %% MIPS MIPS");
if (j == 0)
fputs(kSep, f);
}
fprintf(f, "\n\n");
for (UInt32 i = 0; i < numIterations; i++)
{
const int kStartDicLog = 22;
int pow = (dictionary < ((UInt32)1 << kStartDicLog)) ? kBenchMinDicLogSize : kStartDicLog;
while (((UInt32)1 << pow) > dictionary)
pow--;
for (; ((UInt32)1 << pow) <= dictionary; pow++)
{
fprintf(f, "%2d:", pow);
callback.dictionarySize = (UInt32)1 << pow;
HRESULT res = LzmaBench(
EXTERNAL_CODECS_LOC_VARS
numThreads, callback.dictionarySize, &callback);
fprintf(f, "\n");
RINOK(res);
}
}
callback.Normalize();
fprintf(f, "----------------------------------------------------------------\nAvr:");
PrintTotals(f, callback.EncodeRes);
fprintf(f, " ");
PrintTotals(f, callback.DecodeRes);
fprintf(f, "\nTot:");
CTotalBenchRes midRes;
midRes.SetMid(callback.EncodeRes, callback.DecodeRes);
PrintTotals(f, midRes);
fprintf(f, "\n");
return S_OK;
}
struct CTempValues
{
UInt64 *Values;
CTempValues(UInt32 num) { Values = new UInt64[num]; }
~CTempValues() { delete []Values; }
};
HRESULT CrcBenchCon(FILE *f, UInt32 numIterations, UInt32 numThreads, UInt32 dictionary)
{
if (!CrcInternalTest())
return S_FALSE;
#ifndef _7ZIP_ST
UInt64 ramSize = NWindows::NSystem::GetRamSize();
UInt32 numCPUs = NWindows::NSystem::GetNumberOfProcessors();
PrintRequirements(f, "size: ", ramSize, "CPU hardware threads:", numCPUs);
if (numThreads == (UInt32)-1)
numThreads = numCPUs;
#else
numThreads = 1;
#endif
if (dictionary == (UInt32)-1)
dictionary = (1 << 24);
CTempValues speedTotals(numThreads);
fprintf(f, "\n\nSize");
for (UInt32 ti = 0; ti < numThreads; ti++)
{
fprintf(f, " %5d", ti + 1);
speedTotals.Values[ti] = 0;
}
fprintf(f, "\n\n");
UInt64 numSteps = 0;
for (UInt32 i = 0; i < numIterations; i++)
{
for (int pow = 10; pow < 32; pow++)
{
UInt32 bufSize = (UInt32)1 << pow;
if (bufSize > dictionary)
break;
fprintf(f, "%2d: ", pow);
UInt64 speed;
for (UInt32 ti = 0; ti < numThreads; ti++)
{
if (NConsoleClose::TestBreakSignal())
return E_ABORT;
RINOK(CrcBench(ti + 1, bufSize, speed));
PrintNumber(f, (speed >> 20), 5);
speedTotals.Values[ti] += speed;
}
fprintf(f, "\n");
numSteps++;
}
}
if (numSteps != 0)
{
fprintf(f, "\nAvg:");
for (UInt32 ti = 0; ti < numThreads; ti++)
PrintNumber(f, ((speedTotals.Values[ti] / numSteps) >> 20), 5);
fprintf(f, "\n");
}
return S_OK;
CPrintBenchCallback callback;
callback._file = f;
callback.NewLine();
return Bench(EXTERNAL_CODECS_LOC_VARS
&callback, NULL, props, numIterations, true);
}

View File

@@ -6,11 +6,9 @@
#include <stdio.h>
#include "../../Common/CreateCoder.h"
#include "../../UI/Common/Property.h"
HRESULT LzmaBenchCon(
DECL_EXTERNAL_CODECS_LOC_VARS
FILE *f, UInt32 numIterations, UInt32 numThreads, UInt32 dictionary);
HRESULT CrcBenchCon(FILE *f, UInt32 numIterations, UInt32 numThreads, UInt32 dictionary);
HRESULT BenchCon(DECL_EXTERNAL_CODECS_LOC_VARS
const CObjectVector<CProperty> props, UInt32 numIterations, FILE *f);
#endif

View File

@@ -628,14 +628,6 @@ SOURCE=..\Common\UpdateProduce.h
# End Source File
# Begin Source File
SOURCE=..\Common\WorkDir.cpp
# End Source File
# Begin Source File
SOURCE=..\Common\WorkDir.h
# End Source File
# Begin Source File
SOURCE=..\Common\ZipRegistry.h
# End Source File
# End Group
@@ -676,6 +668,14 @@ SOURCE=..\..\Common\FilterCoder.h
# End Source File
# Begin Source File
SOURCE=..\..\Common\MethodProps.cpp
# End Source File
# Begin Source File
SOURCE=..\..\Common\MethodProps.h
# End Source File
# Begin Source File
SOURCE=..\..\Common\ProgressUtils.cpp
# End Source File
# Begin Source File

View File

@@ -182,7 +182,7 @@ HRESULT CExtractCallbackConsole::OpenResult(const wchar_t * /* name */, HRESULT
if (result == E_OUTOFMEMORY)
(*OutStream) << "Can't allocate required memory";
else
(*OutStream) << NError::MyFormatMessage(result);
(*OutStream) << NError::MyFormatMessageW(result);
}
(*OutStream) << endl;
NumArchiveErrors++;
@@ -218,11 +218,7 @@ HRESULT CExtractCallbackConsole::ExtractResult(HRESULT result)
if (result == E_OUTOFMEMORY)
(*OutStream) << kMemoryExceptionMessage;
else
{
UString message;
NError::MyFormatMessage(result, message);
(*OutStream) << message;
}
(*OutStream) << NError::MyFormatMessageW(result);
(*OutStream) << endl;
return S_OK;
}

View File

@@ -437,8 +437,8 @@ HRESULT ListArchives(CCodecs *codecs, const CIntVector &formatIndices,
UInt64 arcPackSize = 0;
if (!stdInMode)
{
NFile::NFind::CFileInfoW fi;
if (!fi.Find(archiveName) || fi.IsDir())
NFile::NFind::CFileInfo fi;
if (!fi.Find(us2fs(archiveName)) || fi.IsDir())
{
g_StdOut << endl << "Error: " << archiveName << " is not file" << endl;
numErrors++;
@@ -477,7 +477,7 @@ HRESULT ListArchives(CCodecs *codecs, const CIntVector &formatIndices,
else if (result == E_OUTOFMEMORY)
g_StdOut << "Can't allocate required memory";
else
g_StdOut << NError::MyFormatMessage(result);
g_StdOut << NError::MyFormatMessageW(result);
g_StdOut << endl;
numErrors++;
continue;

View File

@@ -39,7 +39,9 @@ using namespace NWindows;
using namespace NFile;
using namespace NCommandLineParser;
#ifdef _WIN32
HINSTANCE g_hInstance = 0;
#endif
extern CStdOutStream *g_StdStream;
static const char *kCopyrightString = "\n7-Zip"
@@ -111,7 +113,7 @@ static const char *kUserErrorMessage = "Incorrect command line";
static const char *kNoFormats = "7-Zip cannot find the code that works with archives.";
static const char *kUnsupportedArcTypeMessage = "Unsupported archive type";
static const wchar_t *kDefaultSfxModule = L"7zCon.sfx";
static CFSTR kDefaultSfxModule = FTEXT("7zCon.sfx");
static void ShowMessageAndThrowException(CStdOutStream &s, LPCSTR message, NExitCode::EEnum code)
{
@@ -338,20 +340,6 @@ int Main2(
}
else if (options.Command.CommandType == NCommandType::kBenchmark)
{
if (options.Method.CompareNoCase(L"CRC") == 0)
{
HRESULT res = CrcBenchCon((FILE *)stdStream, options.NumIterations, options.NumThreads, options.DictionarySize);
if (res != S_OK)
{
if (res == S_FALSE)
{
stdStream << "\nCRC Error\n";
return NExitCode::kFatalError;
}
throw CSystemException(res);
}
}
else
{
HRESULT res;
#ifdef EXTERNAL_CODECS
@@ -360,11 +348,11 @@ int Main2(
if (res != S_OK)
throw CSystemException(res);
#endif
res = LzmaBenchCon(
res = BenchCon(
#ifdef EXTERNAL_CODECS
compressCodecsInfo, &externalCodecs,
#endif
(FILE *)stdStream, options.NumIterations, options.NumThreads, options.DictionarySize);
options.Properties, options.NumIterations, (FILE *)stdStream);
if (res != S_OK)
{
if (res == S_FALSE)
@@ -410,7 +398,7 @@ int Main2(
eo.YesToAll = options.YesToAll;
eo.CalcCrc = options.CalcCrc;
#if !defined(_7ZIP_ST) && !defined(_SFX)
eo.Properties = options.ExtractProperties;
eo.Properties = options.Properties;
#endif
UString errorMessage;
CDecompressStat stat;
@@ -480,7 +468,7 @@ int Main2(
numErrors);
if (numErrors > 0)
{
g_StdOut << endl << "Errors: " << numErrors;
g_StdOut << endl << "Errors: " << numErrors << endl;
return NExitCode::kFatalError;
}
if (result != S_OK)
@@ -551,12 +539,12 @@ int Main2(
}
if (!errorInfo.FileName.IsEmpty())
{
message += errorInfo.FileName;
message += fs2us(errorInfo.FileName);
message += L"\n";
}
if (!errorInfo.FileName2.IsEmpty())
{
message += errorInfo.FileName2;
message += fs2us(errorInfo.FileName2);
message += L"\n";
}
if (errorInfo.SystemError != 0)

View File

@@ -79,9 +79,8 @@ int MY_CDECL main
(*g_StdStream) << endl << kUserBreak;
return (NExitCode::kUserBreak);
}
UString message;
NError::MyFormatMessage(systemError.ErrorCode, message);
(*g_StdStream) << endl << endl << "System error:" << endl << message << endl;
(*g_StdStream) << endl << endl << "System error:" << endl <<
NError::MyFormatMessageW(systemError.ErrorCode) << endl;
return (NExitCode::kFatalError);
}
catch(NExitCode::EEnum &exitCode)

View File

@@ -7,13 +7,13 @@
#include "PercentPrinter.h"
const int kPaddingSize = 2;
const int kPercentsSize = 4;
const int kMaxExtraSize = kPaddingSize + 32 + kPercentsSize;
static const unsigned kPaddingSize = 2;
static const unsigned kPercentsSize = 4;
static const unsigned kMaxExtraSize = kPaddingSize + 32 + kPercentsSize;
static void ClearPrev(char *p, int num)
static void ClearPrev(char *p, unsigned num)
{
int i;
unsigned i;
for (i = 0; i < num; i++) *p++ = '\b';
for (i = 0; i < num; i++) *p++ = ' ';
for (i = 0; i < num; i++) *p++ = '\b';
@@ -51,18 +51,30 @@ void CPercentPrinter::PrintNewLine()
void CPercentPrinter::RePrintRatio()
{
char s[32];
ConvertUInt64ToString(((m_Total == 0) ? 0 : (m_CurValue * 100 / m_Total)), s);
int size = (int)strlen(s);
s[size++] = '%';
s[size] = '\0';
unsigned size;
{
char c = '%';
UInt64 value = 0;
if (m_Total == (UInt64)(Int64)-1)
{
value = m_CurValue >> 20;
c = 'M';
}
else if (m_Total != 0)
value = m_CurValue * 100 / m_Total;
ConvertUInt64ToString(value, s);
size = (unsigned)strlen(s);
s[size++] = c;
s[size] = '\0';
}
int extraSize = kPaddingSize + MyMax(size, kPercentsSize);
unsigned extraSize = kPaddingSize + MyMax(size, kPercentsSize);
if (extraSize < m_NumExtraChars)
extraSize = m_NumExtraChars;
char fullString[kMaxExtraSize * 3];
char *p = fullString;
int i;
unsigned i;
if (m_NumExtraChars == 0)
{
for (i = 0; i < extraSize; i++)
@@ -73,7 +85,7 @@ void CPercentPrinter::RePrintRatio()
for (i = 0; i < m_NumExtraChars; i++)
*p++ = '\b';
m_NumExtraChars = extraSize;
for (; size < m_NumExtraChars; size++)
for (; size < extraSize; size++)
*p++ = ' ';
MyStringCopy(p, s);
(*OutStream) << fullString;

View File

@@ -1,9 +1,8 @@
// PercentPrinter.h
#ifndef __PERCENTPRINTER_H
#define __PERCENTPRINTER_H
#ifndef __PERCENT_PRINTER_H
#define __PERCENT_PRINTER_H
#include "Common/Types.h"
#include "Common/StdOutStream.h"
class CPercentPrinter
@@ -12,12 +11,12 @@ class CPercentPrinter
UInt64 m_PrevValue;
UInt64 m_CurValue;
UInt64 m_Total;
int m_NumExtraChars;
unsigned m_NumExtraChars;
public:
CStdOutStream *OutStream;
CPercentPrinter(UInt64 minStepSize = 1): m_MinStepSize(minStepSize),
m_PrevValue(0), m_CurValue(0), m_Total(1), m_NumExtraChars(0) {}
m_PrevValue(0), m_CurValue(0), m_Total((UInt64)(Int64)-1), m_NumExtraChars(0) {}
void SetTotal(UInt64 total) { m_Total = total; m_PrevValue = 0; }
void SetRatio(UInt64 doneValue) { m_CurValue = doneValue; }
void PrintString(const char *s);

View File

@@ -54,6 +54,7 @@ WIN_OBJS = \
$O\FilePathAutoRename.obj \
$O\FileStreams.obj \
$O\FilterCoder.obj \
$O\MethodProps.obj \
$O\ProgressUtils.obj \
$O\StreamUtils.obj \
@@ -77,7 +78,6 @@ UI_COMMON_OBJS = \
$O\UpdateCallback.obj \
$O\UpdatePair.obj \
$O\UpdateProduce.obj \
$O\WorkDir.obj \
AR_COMMON_OBJS = \
$O\OutStreamWithCRC.obj \