Merge pull request #11451 from huffman/feat/upload-user-event

Add uploading to asset server event
This commit is contained in:
Clément Brisset 2017-10-10 11:03:33 -07:00 committed by GitHub
commit 3b48833cc0
10 changed files with 53 additions and 22 deletions

View file

@ -1638,12 +1638,14 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo
properties["throttled"] = _displayPlugin ? _displayPlugin->isThrottled() : false;
QJsonObject bytesDownloaded;
bytesDownloaded["atp"] = statTracker->getStat(STAT_ATP_RESOURCE_TOTAL_BYTES).toInt();
bytesDownloaded["http"] = statTracker->getStat(STAT_HTTP_RESOURCE_TOTAL_BYTES).toInt();
bytesDownloaded["file"] = statTracker->getStat(STAT_FILE_RESOURCE_TOTAL_BYTES).toInt();
bytesDownloaded["total"] = bytesDownloaded["atp"].toInt() + bytesDownloaded["http"].toInt()
+ bytesDownloaded["file"].toInt();
properties["bytesDownloaded"] = bytesDownloaded;
auto atpBytes = statTracker->getStat(STAT_ATP_RESOURCE_TOTAL_BYTES).toLongLong();
auto httpBytes = statTracker->getStat(STAT_HTTP_RESOURCE_TOTAL_BYTES).toLongLong();
auto fileBytes = statTracker->getStat(STAT_FILE_RESOURCE_TOTAL_BYTES).toLongLong();
bytesDownloaded["atp"] = atpBytes;
bytesDownloaded["http"] = httpBytes;
bytesDownloaded["file"] = fileBytes;
bytesDownloaded["total"] = atpBytes + httpBytes + fileBytes;
properties["bytes_downloaded"] = bytesDownloaded;
auto myAvatar = getMyAvatar();
glm::vec3 avatarPosition = myAvatar->getPosition();

View file

@ -21,6 +21,7 @@
#include <NetworkLogging.h>
#include <NodeList.h>
#include <OffscreenUi.h>
#include <UserActivityLogger.h>
static const int AUTO_REFRESH_INTERVAL = 1000;
@ -104,6 +105,21 @@ void AssetMappingsScriptingInterface::uploadFile(QString path, QString mapping,
startedCallback.call();
QFileInfo fileInfo { path };
int64_t size { fileInfo.size() };
QString extension = "";
auto idx = path.lastIndexOf(".");
if (idx >= 0) {
extension = path.mid(idx + 1);
}
UserActivityLogger::getInstance().logAction("uploading_asset", {
{ "size", (qint64)size },
{ "mapping", mapping },
{ "extension", extension}
});
auto upload = DependencyManager::get<AssetClient>()->createUpload(path);
QObject::connect(upload, &AssetUpload::finished, this, [=](AssetUpload* upload, const QString& hash) mutable {
if (upload->getError() != AssetUpload::NoError) {

View file

@ -155,6 +155,7 @@ void AssetResourceRequest::requestHash(const AssetHash& hash) {
case AssetRequest::Error::NoError:
_data = req->getData();
_result = Success;
recordBytesDownloadedInStats(STAT_ATP_RESOURCE_TOTAL_BYTES, _data.size());
break;
case AssetRequest::InvalidHash:
_result = InvalidURL;
@ -202,9 +203,8 @@ void AssetResourceRequest::onDownloadProgress(qint64 bytesReceived, qint64 bytes
emit progress(bytesReceived, bytesTotal);
auto now = p_high_resolution_clock::now();
// Recording ATP bytes downloaded in stats
DependencyManager::get<StatTracker>()->updateStat(STAT_ATP_RESOURCE_TOTAL_BYTES, bytesReceived);
recordBytesDownloadedInStats(STAT_ATP_RESOURCE_TOTAL_BYTES, bytesReceived);
// if we haven't received the full asset check if it is time to output progress to log
// we do so every X seconds to assist with ATP download tracking

View file

@ -41,6 +41,8 @@ private:
AssetRequest* _assetRequest { nullptr };
p_high_resolution_clock::time_point _lastProgressDebug;
int64_t _lastRecordedBytesDownloaded { 0 };
};
#endif

View file

@ -69,8 +69,7 @@ void FileResourceRequest::doSend() {
if (_result == ResourceRequest::Success) {
statTracker->incrementStat(STAT_FILE_REQUEST_SUCCESS);
// Recording FILE bytes downloaded in stats
statTracker->updateStat(STAT_FILE_RESOURCE_TOTAL_BYTES,fileSize);
statTracker->updateStat(STAT_FILE_RESOURCE_TOTAL_BYTES, fileSize);
} else {
statTracker->incrementStat(STAT_FILE_REQUEST_FAILED);
}

View file

@ -141,6 +141,8 @@ void HTTPResourceRequest::onRequestFinished() {
}
}
recordBytesDownloadedInStats(STAT_HTTP_RESOURCE_TOTAL_BYTES, _data.size());
break;
case QNetworkReply::TimeoutError:
@ -201,11 +203,8 @@ void HTTPResourceRequest::onDownloadProgress(qint64 bytesReceived, qint64 bytesT
_sendTimer->start();
emit progress(bytesReceived, bytesTotal);
// Recording HTTP bytes downloaded in stats
DependencyManager::get<StatTracker>()->updateStat(STAT_HTTP_RESOURCE_TOTAL_BYTES, bytesReceived);
recordBytesDownloadedInStats(STAT_HTTP_RESOURCE_TOTAL_BYTES, bytesReceived);
}
void HTTPResourceRequest::onTimeout() {

View file

@ -11,6 +11,9 @@
#include "ResourceRequest.h"
#include <DependencyManager.h>
#include <StatTracker.h>
#include <QtCore/QThread>
ResourceRequest::ResourceRequest(const QUrl& url) : _url(url) { }
@ -40,3 +43,11 @@ QString ResourceRequest::getResultString() const {
default: return "Unspecified Error";
}
}
void ResourceRequest::recordBytesDownloadedInStats(const QString& statName, int64_t bytesReceived) {
auto dBytes = bytesReceived - _lastRecordedBytesDownloaded;
if (dBytes > 0) {
_lastRecordedBytesDownloaded = bytesReceived;
DependencyManager::get<StatTracker>()->updateStat(statName, dBytes);
}
}

View file

@ -85,6 +85,7 @@ signals:
protected:
virtual void doSend() = 0;
void recordBytesDownloadedInStats(const QString& statName, int64_t bytesReceived);
QUrl _url;
QUrl _relativePathURL;
@ -97,6 +98,7 @@ protected:
ByteRange _byteRange;
bool _rangeRequestSuccessful { false };
uint64_t _totalSizeOfResource { 0 };
int64_t _lastRecordedBytesDownloaded { 0 };
};
#endif

View file

@ -14,15 +14,15 @@ StatTracker::StatTracker() {
QVariant StatTracker::getStat(const QString& name) {
std::lock_guard<std::mutex> lock(_statsLock);
return _stats[name];
return QVariant::fromValue<int64_t>(_stats[name]);
}
void StatTracker::setStat(const QString& name, int value) {
void StatTracker::setStat(const QString& name, int64_t value) {
Lock lock(_statsLock);
_stats[name] = value;
}
void StatTracker::updateStat(const QString& name, int value) {
void StatTracker::updateStat(const QString& name, int64_t value) {
Lock lock(_statsLock);
auto itr = _stats.find(name);
if (_stats.end() == itr) {

View file

@ -24,15 +24,15 @@ class StatTracker : public Dependency {
public:
StatTracker();
QVariant getStat(const QString& name);
void setStat(const QString& name, int value);
void updateStat(const QString& name, int mod);
void setStat(const QString& name, int64_t value);
void updateStat(const QString& name, int64_t mod);
void incrementStat(const QString& name);
void decrementStat(const QString& name);
private:
using Mutex = std::mutex;
using Lock = std::lock_guard<Mutex>;
Mutex _statsLock;
QHash<QString, int> _stats;
QHash<QString, int64_t> _stats;
};
class CounterStat {