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; properties["throttled"] = _displayPlugin ? _displayPlugin->isThrottled() : false;
QJsonObject bytesDownloaded; QJsonObject bytesDownloaded;
bytesDownloaded["atp"] = statTracker->getStat(STAT_ATP_RESOURCE_TOTAL_BYTES).toInt(); auto atpBytes = statTracker->getStat(STAT_ATP_RESOURCE_TOTAL_BYTES).toLongLong();
bytesDownloaded["http"] = statTracker->getStat(STAT_HTTP_RESOURCE_TOTAL_BYTES).toInt(); auto httpBytes = statTracker->getStat(STAT_HTTP_RESOURCE_TOTAL_BYTES).toLongLong();
bytesDownloaded["file"] = statTracker->getStat(STAT_FILE_RESOURCE_TOTAL_BYTES).toInt(); auto fileBytes = statTracker->getStat(STAT_FILE_RESOURCE_TOTAL_BYTES).toLongLong();
bytesDownloaded["total"] = bytesDownloaded["atp"].toInt() + bytesDownloaded["http"].toInt() bytesDownloaded["atp"] = atpBytes;
+ bytesDownloaded["file"].toInt(); bytesDownloaded["http"] = httpBytes;
properties["bytesDownloaded"] = bytesDownloaded; bytesDownloaded["file"] = fileBytes;
bytesDownloaded["total"] = atpBytes + httpBytes + fileBytes;
properties["bytes_downloaded"] = bytesDownloaded;
auto myAvatar = getMyAvatar(); auto myAvatar = getMyAvatar();
glm::vec3 avatarPosition = myAvatar->getPosition(); glm::vec3 avatarPosition = myAvatar->getPosition();

View file

@ -21,6 +21,7 @@
#include <NetworkLogging.h> #include <NetworkLogging.h>
#include <NodeList.h> #include <NodeList.h>
#include <OffscreenUi.h> #include <OffscreenUi.h>
#include <UserActivityLogger.h>
static const int AUTO_REFRESH_INTERVAL = 1000; static const int AUTO_REFRESH_INTERVAL = 1000;
@ -104,6 +105,21 @@ void AssetMappingsScriptingInterface::uploadFile(QString path, QString mapping,
startedCallback.call(); 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); auto upload = DependencyManager::get<AssetClient>()->createUpload(path);
QObject::connect(upload, &AssetUpload::finished, this, [=](AssetUpload* upload, const QString& hash) mutable { QObject::connect(upload, &AssetUpload::finished, this, [=](AssetUpload* upload, const QString& hash) mutable {
if (upload->getError() != AssetUpload::NoError) { if (upload->getError() != AssetUpload::NoError) {

View file

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

View file

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

View file

@ -69,8 +69,7 @@ void FileResourceRequest::doSend() {
if (_result == ResourceRequest::Success) { if (_result == ResourceRequest::Success) {
statTracker->incrementStat(STAT_FILE_REQUEST_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 { } else {
statTracker->incrementStat(STAT_FILE_REQUEST_FAILED); statTracker->incrementStat(STAT_FILE_REQUEST_FAILED);
} }

View file

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

View file

@ -11,6 +11,9 @@
#include "ResourceRequest.h" #include "ResourceRequest.h"
#include <DependencyManager.h>
#include <StatTracker.h>
#include <QtCore/QThread> #include <QtCore/QThread>
ResourceRequest::ResourceRequest(const QUrl& url) : _url(url) { } ResourceRequest::ResourceRequest(const QUrl& url) : _url(url) { }
@ -40,3 +43,11 @@ QString ResourceRequest::getResultString() const {
default: return "Unspecified Error"; 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: protected:
virtual void doSend() = 0; virtual void doSend() = 0;
void recordBytesDownloadedInStats(const QString& statName, int64_t bytesReceived);
QUrl _url; QUrl _url;
QUrl _relativePathURL; QUrl _relativePathURL;
@ -97,6 +98,7 @@ protected:
ByteRange _byteRange; ByteRange _byteRange;
bool _rangeRequestSuccessful { false }; bool _rangeRequestSuccessful { false };
uint64_t _totalSizeOfResource { 0 }; uint64_t _totalSizeOfResource { 0 };
int64_t _lastRecordedBytesDownloaded { 0 };
}; };
#endif #endif

View file

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

View file

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