Exemple #1
0
void LoadMonitor::addLoadSample (LoadEvent const& sample)
{
    std::string const& name (sample.name());
    RelativeTime const latency (sample.getSecondsTotal());

    if (latency.inSeconds() > 0.5)
    {
        WriteLog ((latency.inSeconds() > 1.0) ? lsWARNING : lsINFO, LoadMonitor)
            << "Job: " << name << " ExecutionTime: " << printElapsed (sample.getSecondsRunning()) <<
            " WaitingTime: " << printElapsed (sample.getSecondsWaiting());
    }

    // VFALCO NOTE Why does 1 become 0?
    std::size_t latencyMilliseconds (latency.inMilliseconds());
    if (latencyMilliseconds == 1)
        latencyMilliseconds = 0;

    ScopedLockType sl (mLock, __FILE__, __LINE__);

    update ();
    ++mCounts;
    ++mLatencyEvents;
    mLatencyMSAvg += latencyMilliseconds;
    mLatencyMSPeak += latencyMilliseconds;

    // VFALCO NOTE Why are we multiplying by 4?
    int const latencyPeak = mLatencyEvents * latencyMilliseconds * 4;

    if (mLatencyMSPeak < latencyPeak)
        mLatencyMSPeak = latencyPeak;
}
 // =================================================================================================================
 bool DiskSampleRecorder::reserveDiskSpace(String outDir, int64 lengthInBytes)
 {
	String		audioFileName(outDir);
	File*		tempDataFile;
	Time		now;

	if ( !audioFileName.endsWith(File::separatorString))
		audioFileName += File::separatorString;

	for (int i=0; i < processorOutputs; i++)
	{
		now = Time::getCurrentTime();

		tempDataFile = new File(audioFileName + "channel" + String::formatted("%.2d", i) + ".dat");

		if (*tempDataFile == File::nonexistent)
		{
			mchaRecordPlayer->logError( L"Failed to reserve disk space for data file:\t" + tempDataFile->getFullPathName() );
			delete tempDataFile;
			return false;		
		}
		else
		{
			FileOutputStream* tempStream = tempDataFile->createOutputStream();
			if (tempStream == NULL)
			{
				mchaRecordPlayer->logError( L"Failed to create output stream for data file:\t" + tempDataFile->getFullPathName() );
				delete tempStream;
				delete tempDataFile;
				return false;
			}
			else
			{
				if (!tempStream->setPosition(lengthInBytes))
				{
					mchaRecordPlayer->logError( L"Failed to position output stream for data file:\t" + tempDataFile->getFullPathName() + ". Insufficient disk space?" );
					delete tempStream;
					delete tempDataFile;
					return false;				
				}
				else
				{
					int zeroByte = 0;
					tempStream->write( (void *) &zeroByte, 1);
					tempStream->flush();
				}
			}
			RelativeTime timeDelay = Time::getCurrentTime() - now;
			mchaRecordPlayer->dbgOut( "\tReserving disk space for\t" + tempDataFile->getFullPathName() + "\t" + String(lengthInBytes) + " bytes\t" + String(timeDelay.inSeconds())+ " s elapsed." );
			delete tempStream;
			delete tempDataFile;			
		}

	}
	
	return true;
 }
Exemple #3
0
bool operator<= (RelativeTime t1, RelativeTime t2) noexcept
{
    return t1.inSeconds() <= t2.inSeconds();
}
bool operator<= (const RelativeTime& t1, const RelativeTime& t2) noexcept       { return t1.inSeconds() <= t2.inSeconds(); }
SmugID SmugMug::uploadFile(int queue, int index)
{
	SmugID retval;

	lock.enter();
	UploadFile& uf = uploadQueue[queue]->getImageFileInfo(index);
	lock.exit();

	int64 bytesDone = 0;
	MD5 md5(uf.file);

	Time start = Time::getCurrentTime();

	startTimer(LOGOUT_TIMER);

	String headers;
    String filename = uf.file.getFileName();
    headers = "PUT http://upload.smugmug.com/" + URL::addEscapeChars(filename, false) + " HTTP/1.1\r\n" +
		      "Host: upload.smugmug.com\r\n" +
			  "Content-Length: " + String(uf.file.getSize()) + "\r\n" +
		      "Content-MD5: " + md5.toHexString() + "\r\n" +
			  "X-Smug-SessionID: " + sessionId + "\r\n" +
			  "X-Smug-Version: 1.2.2\r\n" +
			  "X-Smug-ResponseType: REST\r\n" +
			  "X-Smug-AlbumID: " + String(uploadQueue[queue]->getAlbumId().id) + "\r\n" +
			  "X-Smug-FileName: " + filename + "\r\n\r\n";

#ifdef JUCE_DEBUG
	Logger::outputDebugString(headers);
#endif

	const char* headerUtf8 = headers.toUTF8();

	StreamingSocket soc;

	if (soc.connect("upload.smugmug.com", 80))
	{
		int bytesWritten = soc.write(headerUtf8, (int)strlen(headerUtf8));
		if (bytesWritten == -1)
		{
			uf.status = UploadFile::Failed;
			return retval;
		}

		FileInputStream* fos = uf.file.createInputStream();
		if (fos)
		{
			char buffer[1024 * 8];
			while (!fos->isExhausted())
			{
				int in = fos->read(buffer, sizeof(buffer));
				int out = soc.write(buffer, in);

				startTimer(LOGOUT_TIMER);

				if (in != out)
				{
					delete fos;
					uf.status = UploadFile::Failed;
					return retval;
				}
				else
				{
					bytesDone += in;
					uf.complete = float(bytesDone)/float(uf.file.getSize());
				}

				if (uf.status == UploadFile::Cancelled)
				{
					delete fos;
					return retval;
				}
			}
			delete fos;
		}
		else
		{
			uf.status = UploadFile::Failed;
			return retval;
		}

		String response;
		response.preallocateBytes(1024);

		while (1)
		{
			char buffer;
			int read = soc.read(&buffer, 1, true);
			if (read == -1)
				break;

			response += buffer;

			if (response.endsWith(("\r\n\r\n")) || response.endsWith(("\n\n")))
			{
				String len = response.fromFirstOccurrenceOf(("Content-Length: "), false, true);
				if (len.isNotEmpty())
				{
					// normal mode
					String num;

					int i = 0;
					while (CharacterFunctions::isDigit(len[i]))
						num += len[i++];
					
					int bytes = num.getIntValue();

					char* buffer = new char[bytes + 1];
					soc.read(buffer, bytes, true);
					buffer[bytes] = 0;

					response += buffer;
					delete[] buffer;
				}
				else
				{
					// chunked
					while (1)
					{
						String line;
						char ch;
						while (!line.endsWith("\r\n"))
						{
							soc.read(&ch, 1, true);
							line += ch;
						}

						int sz = line.getHexValue32();
						if (sz == 0)
							break;

						char* buf = new char[sz + 1];
						soc.read(buf, sz, true);
						buf[sz] = 0;

						response += buf;
						delete buf;

						soc.read(&ch, 1, true);
						soc.read(&ch, 1, true);
					}
				}

#ifdef JUCE_DEBUG				
				Logger::outputDebugString(response);
#endif
				soc.close();

				String xml = response.fromFirstOccurrenceOf(("<?xml"), true, true); 
				XmlDocument doc(xml);
				XmlElement* e = doc.getDocumentElement();
				if (e)
				{
					XmlElement* image = e->getChildByName(("Image"));
					if (image)
					{
						int val = image->getIntAttribute(("id"));
						if (val >= 0)
						{
							uf.status = UploadFile::Finished;
							uf.complete = 1.0f;
							uf.url = image->getStringAttribute("URL");

							Time end = Time::getCurrentTime();
							RelativeTime diff = end - start;

							addLogEntry(("Info: ") + uf.file.getFileName() + (" uploaded in ") + String(int(diff.inSeconds())) + (" seconds [") + String(uf.file.getSize() / 1024 / diff.inSeconds(), 1) + ("KB/s]"));

							retval.id  = val;
							retval.key = image->getStringAttribute(("Key"));
								
							delete e;
							return retval;
						}
					}
					delete e;
				}
			}
		} 		
	}

	uf.status = UploadFile::Failed;
	return retval;
}