Mercurial > hg > orthanc
comparison OrthancServer/ServerContext.cpp @ 3175:574890d14c92
new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 29 Jan 2019 17:34:09 +0100 |
parents | 8ea7c4546c3a |
children | 8792867b739a |
comparison
equal
deleted
inserted
replaced
3174:8ea7c4546c3a | 3175:574890d14c92 |
---|---|
320 | 320 |
321 | 321 |
322 void ServerContext::RemoveFile(const std::string& fileUuid, | 322 void ServerContext::RemoveFile(const std::string& fileUuid, |
323 FileContentType type) | 323 FileContentType type) |
324 { | 324 { |
325 area_.Remove(fileUuid, type); | 325 StorageAccessor accessor(area_, GetMetricsRegistry()); |
326 accessor.Remove(fileUuid, type); | |
326 } | 327 } |
327 | 328 |
328 | 329 |
329 StoreStatus ServerContext::Store(std::string& resultPublicId, | 330 StoreStatus ServerContext::Store(std::string& resultPublicId, |
330 DicomInstanceToStore& dicom) | 331 DicomInstanceToStore& dicom) |
331 { | 332 { |
332 try | 333 try |
333 { | 334 { |
334 StorageAccessor accessor(area_); | 335 MetricsRegistry::Timer timer(GetMetricsRegistry(), "orthanc_store_dicom_duration_ms"); |
336 StorageAccessor accessor(area_, GetMetricsRegistry()); | |
335 | 337 |
336 resultPublicId = dicom.GetHasher().HashInstance(); | 338 resultPublicId = dicom.GetHasher().HashInstance(); |
337 | 339 |
338 Json::Value simplifiedTags; | 340 Json::Value simplifiedTags; |
339 ServerToolbox::SimplifyTags(simplifiedTags, dicom.GetJson(), DicomToJsonFormat_Human); | 341 ServerToolbox::SimplifyTags(simplifiedTags, dicom.GetJson(), DicomToJsonFormat_Human); |
470 if (!index_.LookupAttachment(attachment, resourceId, content)) | 472 if (!index_.LookupAttachment(attachment, resourceId, content)) |
471 { | 473 { |
472 throw OrthancException(ErrorCode_UnknownResource); | 474 throw OrthancException(ErrorCode_UnknownResource); |
473 } | 475 } |
474 | 476 |
475 StorageAccessor accessor(area_); | 477 StorageAccessor accessor(area_, GetMetricsRegistry()); |
476 accessor.AnswerFile(output, attachment, GetFileContentMime(content)); | 478 accessor.AnswerFile(output, attachment, GetFileContentMime(content)); |
477 } | 479 } |
478 | 480 |
479 | 481 |
480 void ServerContext::ChangeAttachmentCompression(const std::string& resourceId, | 482 void ServerContext::ChangeAttachmentCompression(const std::string& resourceId, |
498 return; | 500 return; |
499 } | 501 } |
500 | 502 |
501 std::string content; | 503 std::string content; |
502 | 504 |
503 StorageAccessor accessor(area_); | 505 StorageAccessor accessor(area_, GetMetricsRegistry()); |
504 accessor.Read(content, attachment); | 506 accessor.Read(content, attachment); |
505 | 507 |
506 FileInfo modified = accessor.Write(content.empty() ? NULL : content.c_str(), | 508 FileInfo modified = accessor.Write(content.empty() ? NULL : content.c_str(), |
507 content.size(), attachmentType, compression, storeMD5_); | 509 content.size(), attachmentType, compression, storeMD5_); |
508 | 510 |
614 throw OrthancException(ErrorCode_InternalError, | 616 throw OrthancException(ErrorCode_InternalError, |
615 "Unable to read attachment " + EnumerationToString(content) + | 617 "Unable to read attachment " + EnumerationToString(content) + |
616 " of instance " + instancePublicId); | 618 " of instance " + instancePublicId); |
617 } | 619 } |
618 | 620 |
621 assert(attachment.GetContentType() == content); | |
622 | |
619 if (uncompressIfNeeded) | 623 if (uncompressIfNeeded) |
620 { | 624 { |
621 ReadAttachment(result, attachment); | 625 ReadAttachment(result, attachment); |
622 } | 626 } |
623 else | 627 else |
624 { | 628 { |
625 // Do not interpret the content of the storage area, return the | 629 // Do not uncompress the content of the storage area, return the |
626 // raw data | 630 // raw data |
627 area_.Read(result, attachment.GetUuid(), content); | 631 StorageAccessor accessor(area_, GetMetricsRegistry()); |
632 accessor.ReadRaw(result, attachment); | |
628 } | 633 } |
629 } | 634 } |
630 | 635 |
631 | 636 |
632 void ServerContext::ReadAttachment(std::string& result, | 637 void ServerContext::ReadAttachment(std::string& result, |
633 const FileInfo& attachment) | 638 const FileInfo& attachment) |
634 { | 639 { |
635 // This will decompress the attachment | 640 // This will decompress the attachment |
636 StorageAccessor accessor(area_); | 641 StorageAccessor accessor(area_, GetMetricsRegistry()); |
637 accessor.Read(result, attachment); | 642 accessor.Read(result, attachment); |
638 } | 643 } |
639 | 644 |
640 | 645 |
641 IDynamicObject* ServerContext::DicomCacheProvider::Provide(const std::string& instancePublicId) | 646 IDynamicObject* ServerContext::DicomCacheProvider::Provide(const std::string& instancePublicId) |
681 LOG(INFO) << "Adding attachment " << EnumerationToString(attachmentType) << " to resource " << resourceId; | 686 LOG(INFO) << "Adding attachment " << EnumerationToString(attachmentType) << " to resource " << resourceId; |
682 | 687 |
683 // TODO Should we use "gzip" instead? | 688 // TODO Should we use "gzip" instead? |
684 CompressionType compression = (compressionEnabled_ ? CompressionType_ZlibWithSize : CompressionType_None); | 689 CompressionType compression = (compressionEnabled_ ? CompressionType_ZlibWithSize : CompressionType_None); |
685 | 690 |
686 StorageAccessor accessor(area_); | 691 StorageAccessor accessor(area_, GetMetricsRegistry()); |
687 FileInfo attachment = accessor.Write(data, size, attachmentType, compression, storeMD5_); | 692 FileInfo attachment = accessor.Write(data, size, attachmentType, compression, storeMD5_); |
688 | 693 |
689 StoreStatus status = index_.AddAttachment(attachment, resourceId); | 694 StoreStatus status = index_.AddAttachment(attachment, resourceId); |
690 if (status != StoreStatus_Success) | 695 if (status != StoreStatus_Success) |
691 { | 696 { |