2001-09-28 20:14:13 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
1999-06-15 05:22:25 +00:00
|
|
|
|
|
|
|
#include "nsIServiceManager.h"
|
2002-01-29 21:22:13 +00:00
|
|
|
#include "nsIComponentRegistrar.h"
|
1999-06-15 05:22:25 +00:00
|
|
|
#include "nsIInputStream.h"
|
|
|
|
#include "nsIOutputStream.h"
|
1999-09-15 09:49:18 +00:00
|
|
|
#include "nsIRunnable.h"
|
1999-06-15 05:22:25 +00:00
|
|
|
#include "nsIThread.h"
|
2002-11-13 21:25:32 +00:00
|
|
|
#include "nsCOMArray.h"
|
|
|
|
#include "nsISimpleEnumerator.h"
|
1999-06-15 05:22:25 +00:00
|
|
|
#include "prinrval.h"
|
2000-01-24 21:28:28 +00:00
|
|
|
#include "nsIFileStreams.h"
|
2001-03-12 22:41:28 +00:00
|
|
|
#include "nsIFileChannel.h"
|
2012-06-06 02:08:30 +00:00
|
|
|
#include "nsIFile.h"
|
2000-01-24 21:28:28 +00:00
|
|
|
#include "nsNetUtil.h"
|
1999-06-15 05:22:25 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
1999-06-16 04:15:29 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include <math.h>
|
|
|
|
#include "prprf.h"
|
|
|
|
#include "nsAutoLock.h"
|
|
|
|
|
|
|
|
class nsTimeSampler {
|
|
|
|
public:
|
|
|
|
nsTimeSampler();
|
|
|
|
void Reset();
|
|
|
|
void StartTime();
|
|
|
|
void EndTime();
|
|
|
|
void AddTime(PRIntervalTime time);
|
|
|
|
PRIntervalTime LastInterval() { return mLastInterval; }
|
|
|
|
char* PrintStats();
|
|
|
|
protected:
|
|
|
|
PRIntervalTime mStartTime;
|
|
|
|
double mSquares;
|
|
|
|
double mTotalTime;
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t mCount;
|
1999-06-16 04:15:29 +00:00
|
|
|
PRIntervalTime mLastInterval;
|
|
|
|
};
|
|
|
|
|
|
|
|
nsTimeSampler::nsTimeSampler()
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsTimeSampler::Reset()
|
|
|
|
{
|
|
|
|
mStartTime = 0;
|
|
|
|
mSquares = 0;
|
|
|
|
mTotalTime = 0;
|
|
|
|
mCount = 0;
|
|
|
|
mLastInterval = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsTimeSampler::StartTime()
|
|
|
|
{
|
|
|
|
mStartTime = PR_IntervalNow();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsTimeSampler::EndTime()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mStartTime != 0, "Forgot to call StartTime");
|
|
|
|
PRIntervalTime endTime = PR_IntervalNow();
|
|
|
|
mLastInterval = endTime - mStartTime;
|
|
|
|
AddTime(mLastInterval);
|
|
|
|
mStartTime = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsTimeSampler::AddTime(PRIntervalTime time)
|
|
|
|
{
|
|
|
|
nsAutoCMonitor mon(this);
|
|
|
|
mTotalTime += time;
|
|
|
|
mSquares += (double)time * (double)time;
|
|
|
|
mCount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
char*
|
|
|
|
nsTimeSampler::PrintStats()
|
|
|
|
{
|
|
|
|
double mean = mTotalTime / mCount;
|
|
|
|
double variance = fabs(mSquares / mCount - mean * mean);
|
|
|
|
double stddev = sqrt(variance);
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t imean = (uint32_t)mean;
|
|
|
|
uint32_t istddev = (uint32_t)stddev;
|
1999-06-16 04:15:29 +00:00
|
|
|
return PR_smprintf("%d +/- %d ms",
|
|
|
|
PR_IntervalToMilliseconds(imean),
|
|
|
|
PR_IntervalToMilliseconds(istddev));
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
nsTimeSampler gTimeSampler;
|
1999-06-15 05:22:25 +00:00
|
|
|
|
|
|
|
typedef nsresult (*CreateFun)(nsIRunnable* *result,
|
2000-01-24 21:28:28 +00:00
|
|
|
nsIFile* inPath,
|
|
|
|
nsIFile* outPath,
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t bufferSize);
|
1999-06-15 05:22:25 +00:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
Copy(nsIInputStream* inStr, nsIOutputStream* outStr,
|
2012-08-22 15:56:38 +00:00
|
|
|
char* buf, uint32_t bufSize, uint32_t *copyCount)
|
1999-06-15 05:22:25 +00:00
|
|
|
{
|
|
|
|
nsresult rv;
|
2011-10-17 14:59:28 +00:00
|
|
|
while (true) {
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t count;
|
1999-06-15 05:22:25 +00:00
|
|
|
rv = inStr->Read(buf, bufSize, &count);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-09-09 22:05:05 +00:00
|
|
|
if (count == 0) break;
|
2002-07-04 14:29:25 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t writeCount;
|
1999-06-15 05:22:25 +00:00
|
|
|
rv = outStr->Write(buf, count, &writeCount);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
NS_ASSERTION(writeCount == count, "didn't write all the data");
|
|
|
|
*copyCount += writeCount;
|
|
|
|
}
|
|
|
|
rv = outStr->Flush();
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
class FileSpecWorker : public nsIRunnable {
|
|
|
|
public:
|
|
|
|
|
|
|
|
NS_IMETHOD Run() {
|
|
|
|
nsresult rv;
|
|
|
|
|
1999-06-16 04:15:29 +00:00
|
|
|
PRIntervalTime startTime = PR_IntervalNow();
|
|
|
|
PRIntervalTime endTime;
|
2000-01-24 21:28:28 +00:00
|
|
|
nsCOMPtr<nsIInputStream> inStr;
|
|
|
|
nsCOMPtr<nsIOutputStream> outStr;
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t copyCount = 0;
|
2000-01-24 21:28:28 +00:00
|
|
|
|
1999-06-15 05:22:25 +00:00
|
|
|
// Open the input stream:
|
2000-02-04 07:31:43 +00:00
|
|
|
nsCOMPtr<nsIInputStream> fileIn;
|
2000-03-29 03:58:50 +00:00
|
|
|
rv = NS_NewLocalFileInputStream(getter_AddRefs(fileIn), mInPath);
|
2000-02-04 07:31:43 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
2002-07-04 14:29:25 +00:00
|
|
|
|
2000-03-29 03:58:50 +00:00
|
|
|
rv = NS_NewBufferedInputStream(getter_AddRefs(inStr), fileIn, 65535);
|
2000-01-24 21:28:28 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
2002-07-04 14:29:25 +00:00
|
|
|
|
1999-06-15 05:22:25 +00:00
|
|
|
// Open the output stream:
|
2000-02-04 07:31:43 +00:00
|
|
|
nsCOMPtr<nsIOutputStream> fileOut;
|
2000-03-29 03:58:50 +00:00
|
|
|
rv = NS_NewLocalFileOutputStream(getter_AddRefs(fileOut),
|
|
|
|
mOutPath,
|
|
|
|
PR_CREATE_FILE | PR_WRONLY | PR_TRUNCATE,
|
|
|
|
0664);
|
2000-02-04 07:31:43 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2000-03-29 03:58:50 +00:00
|
|
|
rv = NS_NewBufferedOutputStream(getter_AddRefs(outStr), fileOut, 65535);
|
2000-01-24 21:28:28 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-06-15 05:22:25 +00:00
|
|
|
|
|
|
|
// Copy from one to the other
|
|
|
|
rv = Copy(inStr, outStr, mBuffer, mBufferSize, ©Count);
|
2000-01-24 21:28:28 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-06-16 04:15:29 +00:00
|
|
|
|
1999-06-15 05:22:25 +00:00
|
|
|
endTime = PR_IntervalNow();
|
1999-06-16 04:15:29 +00:00
|
|
|
gTimeSampler.AddTime(endTime - startTime);
|
|
|
|
|
1999-06-15 05:22:25 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
FileSpecWorker()
|
2012-07-30 14:20:58 +00:00
|
|
|
: mInPath(nullptr), mOutPath(nullptr), mBuffer(nullptr),
|
1999-06-15 05:22:25 +00:00
|
|
|
mBufferSize(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2000-01-24 21:28:28 +00:00
|
|
|
nsresult Init(nsIFile* inPath, nsIFile* outPath,
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t bufferSize)
|
1999-06-15 05:22:25 +00:00
|
|
|
{
|
2000-01-24 21:28:28 +00:00
|
|
|
mInPath = inPath;
|
|
|
|
mOutPath = outPath;
|
1999-06-15 05:22:25 +00:00
|
|
|
mBuffer = new char[bufferSize];
|
|
|
|
mBufferSize = bufferSize;
|
|
|
|
return (mInPath && mOutPath && mBuffer)
|
|
|
|
? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
static nsresult Create(nsIRunnable* *result,
|
2000-01-24 21:28:28 +00:00
|
|
|
nsIFile* inPath,
|
|
|
|
nsIFile* outPath,
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t bufferSize)
|
1999-06-15 05:22:25 +00:00
|
|
|
{
|
|
|
|
FileSpecWorker* worker = new FileSpecWorker();
|
2012-07-30 14:20:58 +00:00
|
|
|
if (worker == nullptr)
|
1999-06-15 05:22:25 +00:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
NS_ADDREF(worker);
|
|
|
|
|
|
|
|
nsresult rv = worker->Init(inPath, outPath, bufferSize);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_RELEASE(worker);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
*result = worker;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~FileSpecWorker() {
|
|
|
|
delete[] mBuffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2000-01-24 21:28:28 +00:00
|
|
|
nsCOMPtr<nsIFile> mInPath;
|
|
|
|
nsCOMPtr<nsIFile> mOutPath;
|
|
|
|
char* mBuffer;
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t mBufferSize;
|
1999-06-15 05:22:25 +00:00
|
|
|
};
|
|
|
|
|
2014-04-27 07:06:00 +00:00
|
|
|
NS_IMPL_ISUPPORTS(FileSpecWorker, nsIRunnable)
|
1999-06-15 05:22:25 +00:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "nsIIOService.h"
|
2000-01-24 21:28:28 +00:00
|
|
|
#include "nsIChannel.h"
|
1999-06-15 05:22:25 +00:00
|
|
|
|
|
|
|
class FileChannelWorker : public nsIRunnable {
|
|
|
|
public:
|
|
|
|
|
|
|
|
NS_IMETHOD Run() {
|
|
|
|
nsresult rv;
|
|
|
|
|
1999-06-16 04:15:29 +00:00
|
|
|
PRIntervalTime startTime = PR_IntervalNow();
|
|
|
|
PRIntervalTime endTime;
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t copyCount = 0;
|
2000-01-24 21:28:28 +00:00
|
|
|
nsCOMPtr<nsIFileChannel> inCh;
|
|
|
|
nsCOMPtr<nsIFileChannel> outCh;
|
|
|
|
nsCOMPtr<nsIInputStream> inStr;
|
|
|
|
nsCOMPtr<nsIOutputStream> outStr;
|
|
|
|
|
2000-03-29 03:58:50 +00:00
|
|
|
rv = NS_NewLocalFileChannel(getter_AddRefs(inCh), mInPath);
|
2000-01-24 21:28:28 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-06-15 05:22:25 +00:00
|
|
|
|
2001-02-21 20:38:08 +00:00
|
|
|
rv = inCh->Open(getter_AddRefs(inStr));
|
2000-01-24 21:28:28 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-06-15 05:22:25 +00:00
|
|
|
|
2001-02-21 20:38:08 +00:00
|
|
|
//rv = NS_NewLocalFileChannel(getter_AddRefs(outCh), mOutPath);
|
|
|
|
//if (NS_FAILED(rv)) return rv;
|
1999-06-15 05:22:25 +00:00
|
|
|
|
2001-02-21 20:38:08 +00:00
|
|
|
//rv = outCh->OpenOutputStream(0, -1, 0, getter_AddRefs(outStr));
|
|
|
|
//if (NS_FAILED(rv)) return rv;
|
1999-06-15 05:22:25 +00:00
|
|
|
|
|
|
|
// Copy from one to the other
|
|
|
|
rv = Copy(inStr, outStr, mBuffer, mBufferSize, ©Count);
|
2000-01-24 21:28:28 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
2002-07-04 14:29:25 +00:00
|
|
|
|
1999-06-15 05:22:25 +00:00
|
|
|
endTime = PR_IntervalNow();
|
1999-06-16 04:15:29 +00:00
|
|
|
gTimeSampler.AddTime(endTime - startTime);
|
|
|
|
|
1999-06-15 05:22:25 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
FileChannelWorker()
|
2012-07-30 14:20:58 +00:00
|
|
|
: mInPath(nullptr), mOutPath(nullptr), mBuffer(nullptr),
|
1999-06-15 05:22:25 +00:00
|
|
|
mBufferSize(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2000-01-24 21:28:28 +00:00
|
|
|
nsresult Init(nsIFile* inPath, nsIFile* outPath,
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t bufferSize)
|
1999-06-15 05:22:25 +00:00
|
|
|
{
|
2000-01-24 21:28:28 +00:00
|
|
|
mInPath = inPath;
|
|
|
|
mOutPath = outPath;
|
1999-06-15 05:22:25 +00:00
|
|
|
mBuffer = new char[bufferSize];
|
|
|
|
mBufferSize = bufferSize;
|
|
|
|
return (mInPath && mOutPath && mBuffer)
|
|
|
|
? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
static nsresult Create(nsIRunnable* *result,
|
2000-01-24 21:28:28 +00:00
|
|
|
nsIFile* inPath,
|
|
|
|
nsIFile* outPath,
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t bufferSize)
|
1999-06-15 05:22:25 +00:00
|
|
|
{
|
|
|
|
FileChannelWorker* worker = new FileChannelWorker();
|
2012-07-30 14:20:58 +00:00
|
|
|
if (worker == nullptr)
|
1999-06-15 05:22:25 +00:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
NS_ADDREF(worker);
|
|
|
|
|
|
|
|
nsresult rv = worker->Init(inPath, outPath, bufferSize);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_RELEASE(worker);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
*result = worker;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~FileChannelWorker() {
|
|
|
|
delete[] mBuffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2000-01-24 21:28:28 +00:00
|
|
|
nsCOMPtr<nsIFile> mInPath;
|
|
|
|
nsCOMPtr<nsIFile> mOutPath;
|
|
|
|
char* mBuffer;
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t mBufferSize;
|
1999-06-15 05:22:25 +00:00
|
|
|
};
|
|
|
|
|
2014-04-27 07:06:00 +00:00
|
|
|
NS_IMPL_ISUPPORTS(FileChannelWorker, nsIRunnable)
|
1999-06-15 05:22:25 +00:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void
|
2012-08-22 15:56:38 +00:00
|
|
|
Test(CreateFun create, uint32_t count,
|
|
|
|
nsIFile* inDirSpec, nsIFile* outDirSpec, uint32_t bufSize)
|
1999-06-15 05:22:25 +00:00
|
|
|
{
|
|
|
|
nsresult rv;
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t i;
|
2002-07-04 14:29:25 +00:00
|
|
|
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString inDir;
|
|
|
|
nsAutoCString outDir;
|
2002-05-07 23:07:19 +00:00
|
|
|
(void)inDirSpec->GetNativePath(inDir);
|
|
|
|
(void)outDirSpec->GetNativePath(outDir);
|
1999-06-16 04:15:29 +00:00
|
|
|
printf("###########\nTest: from %s to %s, bufSize = %d\n",
|
2002-04-27 05:33:09 +00:00
|
|
|
inDir.get(), outDir.get(), bufSize);
|
1999-06-16 04:15:29 +00:00
|
|
|
gTimeSampler.Reset();
|
|
|
|
nsTimeSampler testTime;
|
|
|
|
testTime.StartTime();
|
2002-07-04 14:29:25 +00:00
|
|
|
|
2002-11-13 21:25:32 +00:00
|
|
|
nsCOMArray<nsIThread> threads;
|
1999-06-15 05:22:25 +00:00
|
|
|
|
2000-01-24 21:28:28 +00:00
|
|
|
nsCOMPtr<nsISimpleEnumerator> entries;
|
|
|
|
rv = inDirSpec->GetDirectoryEntries(getter_AddRefs(entries));
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "GetDirectoryEntries failed");
|
|
|
|
|
|
|
|
i = 0;
|
2011-09-29 06:19:26 +00:00
|
|
|
bool hasMore;
|
2000-01-24 21:28:28 +00:00
|
|
|
while (i < count && NS_SUCCEEDED(entries->HasMoreElements(&hasMore)) && hasMore) {
|
|
|
|
nsCOMPtr<nsISupports> next;
|
|
|
|
rv = entries->GetNext(getter_AddRefs(next));
|
|
|
|
if (NS_FAILED(rv)) goto done;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIFile> inSpec = do_QueryInterface(next, &rv);
|
|
|
|
if (NS_FAILED(rv)) goto done;
|
1999-06-15 05:22:25 +00:00
|
|
|
|
2000-01-24 21:28:28 +00:00
|
|
|
nsCOMPtr<nsIFile> outSpec;
|
|
|
|
rv = outDirSpec->Clone(getter_AddRefs(outSpec)); // don't munge the original
|
|
|
|
if (NS_FAILED(rv)) goto done;
|
|
|
|
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString leafName;
|
2002-05-07 23:07:19 +00:00
|
|
|
rv = inSpec->GetNativeLeafName(leafName);
|
2000-01-24 21:28:28 +00:00
|
|
|
if (NS_FAILED(rv)) goto done;
|
1999-06-15 05:22:25 +00:00
|
|
|
|
2002-05-07 23:07:19 +00:00
|
|
|
rv = outSpec->AppendNative(leafName);
|
2000-01-24 21:28:28 +00:00
|
|
|
if (NS_FAILED(rv)) goto done;
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool exists;
|
2000-01-24 21:28:28 +00:00
|
|
|
rv = outSpec->Exists(&exists);
|
|
|
|
if (NS_FAILED(rv)) goto done;
|
|
|
|
|
|
|
|
if (exists) {
|
2011-10-17 14:59:28 +00:00
|
|
|
rv = outSpec->Remove(false);
|
2000-01-24 21:28:28 +00:00
|
|
|
if (NS_FAILED(rv)) goto done;
|
1999-06-15 05:22:25 +00:00
|
|
|
}
|
2000-01-24 21:28:28 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIThread> thread;
|
|
|
|
nsCOMPtr<nsIRunnable> worker;
|
|
|
|
rv = create(getter_AddRefs(worker),
|
|
|
|
inSpec,
|
|
|
|
outSpec,
|
1999-06-15 05:22:25 +00:00
|
|
|
bufSize);
|
|
|
|
if (NS_FAILED(rv)) goto done;
|
|
|
|
|
2000-01-24 21:28:28 +00:00
|
|
|
rv = NS_NewThread(getter_AddRefs(thread), worker, 0, PR_JOINABLE_THREAD);
|
1999-06-15 05:22:25 +00:00
|
|
|
if (NS_FAILED(rv)) goto done;
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool inserted = threads.InsertObjectAt(thread, i);
|
1999-06-15 05:22:25 +00:00
|
|
|
NS_ASSERTION(inserted, "not inserted");
|
2000-01-24 21:28:28 +00:00
|
|
|
|
|
|
|
i++;
|
1999-06-15 05:22:25 +00:00
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t j;
|
1999-06-15 05:22:25 +00:00
|
|
|
for (j = 0; j < i; j++) {
|
2002-11-13 21:25:32 +00:00
|
|
|
nsIThread* thread = threads.ObjectAt(j);
|
1999-06-15 05:22:25 +00:00
|
|
|
thread->Join();
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
NS_ASSERTION(rv == NS_OK, "failed");
|
|
|
|
|
1999-06-16 04:15:29 +00:00
|
|
|
testTime.EndTime();
|
|
|
|
char* testStats = testTime.PrintStats();
|
|
|
|
char* workerStats = gTimeSampler.PrintStats();
|
|
|
|
printf(" threads = %d\n work time = %s,\n test time = %s\n",
|
|
|
|
i, workerStats, testStats);
|
|
|
|
PR_smprintf_free(workerStats);
|
|
|
|
PR_smprintf_free(testStats);
|
1999-06-15 05:22:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
if (argc < 2) {
|
|
|
|
printf("usage: %s <in-dir> <out-dir>\n", argv[0]);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
char* inDir = argv[1];
|
|
|
|
char* outDir = argv[2];
|
|
|
|
|
2002-07-04 14:29:25 +00:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIServiceManager> servMan;
|
2012-07-30 14:20:58 +00:00
|
|
|
NS_InitXPCOM2(getter_AddRefs(servMan), nullptr, nullptr);
|
2002-07-04 14:29:25 +00:00
|
|
|
nsCOMPtr<nsIComponentRegistrar> registrar = do_QueryInterface(servMan);
|
|
|
|
NS_ASSERTION(registrar, "Null nsIComponentRegistrar");
|
|
|
|
if (registrar)
|
2012-07-30 14:20:58 +00:00
|
|
|
registrar->AutoRegister(nullptr);
|
2002-07-04 14:29:25 +00:00
|
|
|
|
2012-06-06 02:08:30 +00:00
|
|
|
nsCOMPtr<nsIFile> inDirFile;
|
2011-10-17 14:59:28 +00:00
|
|
|
rv = NS_NewNativeLocalFile(nsDependentCString(inDir), false, getter_AddRefs(inDirFile));
|
2002-07-04 14:29:25 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
2002-01-29 21:22:13 +00:00
|
|
|
|
2012-06-06 02:08:30 +00:00
|
|
|
nsCOMPtr<nsIFile> outDirFile;
|
2011-10-17 14:59:28 +00:00
|
|
|
rv = NS_NewNativeLocalFile(nsDependentCString(outDir), false, getter_AddRefs(outDirFile));
|
2002-07-04 14:29:25 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
2000-01-24 21:28:28 +00:00
|
|
|
|
2002-07-04 14:29:25 +00:00
|
|
|
CreateFun create = FileChannelWorker::Create;
|
|
|
|
Test(create, 1, inDirFile, outDirFile, 16 * 1024);
|
1999-06-16 04:15:29 +00:00
|
|
|
#if 1
|
2002-07-04 14:29:25 +00:00
|
|
|
printf("FileChannelWorker *****************************\n");
|
|
|
|
Test(create, 20, inDirFile, outDirFile, 16 * 1024);
|
|
|
|
Test(create, 20, inDirFile, outDirFile, 16 * 1024);
|
|
|
|
Test(create, 20, inDirFile, outDirFile, 16 * 1024);
|
|
|
|
Test(create, 20, inDirFile, outDirFile, 16 * 1024);
|
|
|
|
Test(create, 20, inDirFile, outDirFile, 16 * 1024);
|
|
|
|
Test(create, 20, inDirFile, outDirFile, 16 * 1024);
|
|
|
|
Test(create, 20, inDirFile, outDirFile, 16 * 1024);
|
|
|
|
Test(create, 20, inDirFile, outDirFile, 16 * 1024);
|
|
|
|
Test(create, 20, inDirFile, outDirFile, 16 * 1024);
|
1999-06-15 05:22:25 +00:00
|
|
|
#endif
|
2002-07-04 14:29:25 +00:00
|
|
|
create = FileSpecWorker::Create;
|
|
|
|
printf("FileSpecWorker ********************************\n");
|
1999-06-16 04:15:29 +00:00
|
|
|
#if 1
|
2002-07-04 14:29:25 +00:00
|
|
|
Test(create, 20, inDirFile, outDirFile, 16 * 1024);
|
|
|
|
Test(create, 20, inDirFile, outDirFile, 16 * 1024);
|
|
|
|
Test(create, 20, inDirFile, outDirFile, 16 * 1024);
|
|
|
|
Test(create, 20, inDirFile, outDirFile, 16 * 1024);
|
|
|
|
Test(create, 20, inDirFile, outDirFile, 16 * 1024);
|
|
|
|
Test(create, 20, inDirFile, outDirFile, 16 * 1024);
|
|
|
|
Test(create, 20, inDirFile, outDirFile, 16 * 1024);
|
|
|
|
Test(create, 20, inDirFile, outDirFile, 16 * 1024);
|
|
|
|
Test(create, 20, inDirFile, outDirFile, 16 * 1024);
|
1999-06-15 05:22:25 +00:00
|
|
|
#endif
|
1999-06-16 04:15:29 +00:00
|
|
|
#if 1
|
2002-07-04 14:29:25 +00:00
|
|
|
Test(create, 20, inDirFile, outDirFile, 4 * 1024);
|
|
|
|
Test(create, 20, inDirFile, outDirFile, 4 * 1024);
|
|
|
|
Test(create, 20, inDirFile, outDirFile, 4 * 1024);
|
|
|
|
Test(create, 20, inDirFile, outDirFile, 4 * 1024);
|
|
|
|
Test(create, 20, inDirFile, outDirFile, 4 * 1024);
|
|
|
|
Test(create, 20, inDirFile, outDirFile, 4 * 1024);
|
|
|
|
Test(create, 20, inDirFile, outDirFile, 4 * 1024);
|
|
|
|
Test(create, 20, inDirFile, outDirFile, 4 * 1024);
|
|
|
|
Test(create, 20, inDirFile, outDirFile, 4 * 1024);
|
1999-06-15 05:22:25 +00:00
|
|
|
#endif
|
2002-07-04 14:29:25 +00:00
|
|
|
} // this scopes the nsCOMPtrs
|
|
|
|
// no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM
|
2012-07-30 14:20:58 +00:00
|
|
|
rv = NS_ShutdownXPCOM(nullptr);
|
2002-07-04 14:29:25 +00:00
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "NS_ShutdownXPCOM failed");
|
1999-06-15 05:22:25 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|