Mercurial > hg > orthanc
comparison Core/FileStorage/StorageAccessor.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 | 4e43e67f8ecf |
children | 94f4a18a79cc |
comparison
equal
deleted
inserted
replaced
3174:8ea7c4546c3a | 3175:574890d14c92 |
---|---|
33 | 33 |
34 #include "../PrecompiledHeaders.h" | 34 #include "../PrecompiledHeaders.h" |
35 #include "StorageAccessor.h" | 35 #include "StorageAccessor.h" |
36 | 36 |
37 #include "../Compression/ZlibCompressor.h" | 37 #include "../Compression/ZlibCompressor.h" |
38 #include "../MetricsRegistry.h" | |
38 #include "../OrthancException.h" | 39 #include "../OrthancException.h" |
39 #include "../Toolbox.h" | 40 #include "../Toolbox.h" |
40 #include "../Toolbox.h" | |
41 | 41 |
42 #if ORTHANC_ENABLE_CIVETWEB == 1 || ORTHANC_ENABLE_MONGOOSE == 1 | 42 #if ORTHANC_ENABLE_CIVETWEB == 1 || ORTHANC_ENABLE_MONGOOSE == 1 |
43 # include "../HttpServer/HttpStreamTranscoder.h" | 43 # include "../HttpServer/HttpStreamTranscoder.h" |
44 #endif | 44 #endif |
45 | |
46 | |
47 static const std::string METRICS_CREATE = "orthanc_storage_create_duration_ms"; | |
48 static const std::string METRICS_READ = "orthanc_storage_read_duration_ms"; | |
49 static const std::string METRICS_REMOVE = "orthanc_storage_remove_duration_ms"; | |
50 | |
45 | 51 |
46 namespace Orthanc | 52 namespace Orthanc |
47 { | 53 { |
54 class StorageAccessor::MetricsTimer : public boost::noncopyable | |
55 { | |
56 private: | |
57 std::auto_ptr<MetricsRegistry::Timer> timer_; | |
58 | |
59 public: | |
60 MetricsTimer(StorageAccessor& that, | |
61 const std::string& name) | |
62 { | |
63 if (that.metrics_ != NULL) | |
64 { | |
65 timer_.reset(new MetricsRegistry::Timer(*that.metrics_, name)); | |
66 } | |
67 } | |
68 }; | |
69 | |
70 | |
48 FileInfo StorageAccessor::Write(const void* data, | 71 FileInfo StorageAccessor::Write(const void* data, |
49 size_t size, | 72 size_t size, |
50 FileContentType type, | 73 FileContentType type, |
51 CompressionType compression, | 74 CompressionType compression, |
52 bool storeMd5) | 75 bool storeMd5) |
62 | 85 |
63 switch (compression) | 86 switch (compression) |
64 { | 87 { |
65 case CompressionType_None: | 88 case CompressionType_None: |
66 { | 89 { |
90 MetricsTimer timer(*this, METRICS_CREATE); | |
91 | |
67 area_.Create(uuid, data, size, type); | 92 area_.Create(uuid, data, size, type); |
68 return FileInfo(uuid, type, size, md5); | 93 return FileInfo(uuid, type, size, md5); |
69 } | 94 } |
70 | 95 |
71 case CompressionType_ZlibWithSize: | 96 case CompressionType_ZlibWithSize: |
80 if (storeMd5) | 105 if (storeMd5) |
81 { | 106 { |
82 Toolbox::ComputeMD5(compressedMD5, compressed); | 107 Toolbox::ComputeMD5(compressedMD5, compressed); |
83 } | 108 } |
84 | 109 |
85 if (compressed.size() > 0) | |
86 { | 110 { |
87 area_.Create(uuid, &compressed[0], compressed.size(), type); | 111 MetricsTimer timer(*this, METRICS_CREATE); |
88 } | 112 |
89 else | 113 if (compressed.size() > 0) |
90 { | 114 { |
91 area_.Create(uuid, NULL, 0, type); | 115 area_.Create(uuid, &compressed[0], compressed.size(), type); |
116 } | |
117 else | |
118 { | |
119 area_.Create(uuid, NULL, 0, type); | |
120 } | |
92 } | 121 } |
93 | 122 |
94 return FileInfo(uuid, type, size, md5, | 123 return FileInfo(uuid, type, size, md5, |
95 CompressionType_ZlibWithSize, compressed.size(), compressedMD5); | 124 CompressionType_ZlibWithSize, compressed.size(), compressedMD5); |
96 } | 125 } |
106 { | 135 { |
107 switch (info.GetCompressionType()) | 136 switch (info.GetCompressionType()) |
108 { | 137 { |
109 case CompressionType_None: | 138 case CompressionType_None: |
110 { | 139 { |
140 MetricsTimer timer(*this, METRICS_READ); | |
111 area_.Read(content, info.GetUuid(), info.GetContentType()); | 141 area_.Read(content, info.GetUuid(), info.GetContentType()); |
112 break; | 142 break; |
113 } | 143 } |
114 | 144 |
115 case CompressionType_ZlibWithSize: | 145 case CompressionType_ZlibWithSize: |
116 { | 146 { |
117 ZlibCompressor zlib; | 147 ZlibCompressor zlib; |
118 | 148 |
119 std::string compressed; | 149 std::string compressed; |
120 area_.Read(compressed, info.GetUuid(), info.GetContentType()); | 150 |
151 { | |
152 MetricsTimer timer(*this, METRICS_READ); | |
153 area_.Read(compressed, info.GetUuid(), info.GetContentType()); | |
154 } | |
155 | |
121 IBufferCompressor::Uncompress(content, zlib, compressed); | 156 IBufferCompressor::Uncompress(content, zlib, compressed); |
122 break; | 157 break; |
123 } | 158 } |
124 | 159 |
125 default: | 160 default: |
130 | 165 |
131 // TODO Check the validity of the uncompressed MD5? | 166 // TODO Check the validity of the uncompressed MD5? |
132 } | 167 } |
133 | 168 |
134 | 169 |
135 void StorageAccessor::Read(Json::Value& content, | 170 void StorageAccessor::ReadRaw(std::string& content, |
136 const FileInfo& info) | 171 const FileInfo& info) |
137 { | 172 { |
138 std::string s; | 173 MetricsTimer timer(*this, METRICS_READ); |
139 Read(s, info); | 174 area_.Read(content, info.GetUuid(), info.GetContentType()); |
140 | 175 } |
141 Json::Reader reader; | 176 |
142 if (!reader.parse(s, content)) | 177 |
143 { | 178 void StorageAccessor::Remove(const std::string& fileUuid, |
144 throw OrthancException(ErrorCode_BadFileFormat); | 179 FileContentType type) |
145 } | 180 { |
181 MetricsTimer timer(*this, METRICS_REMOVE); | |
182 area_.Remove(fileUuid, type); | |
146 } | 183 } |
147 | 184 |
148 | 185 |
149 #if ORTHANC_ENABLE_CIVETWEB == 1 || ORTHANC_ENABLE_MONGOOSE == 1 | 186 #if ORTHANC_ENABLE_CIVETWEB == 1 || ORTHANC_ENABLE_MONGOOSE == 1 |
150 void StorageAccessor::SetupSender(BufferHttpSender& sender, | 187 void StorageAccessor::SetupSender(BufferHttpSender& sender, |
151 const FileInfo& info, | 188 const FileInfo& info, |
152 const std::string& mime) | 189 const std::string& mime) |
153 { | 190 { |
154 area_.Read(sender.GetBuffer(), info.GetUuid(), info.GetContentType()); | 191 { |
192 MetricsTimer timer(*this, METRICS_READ); | |
193 area_.Read(sender.GetBuffer(), info.GetUuid(), info.GetContentType()); | |
194 } | |
195 | |
155 sender.SetContentType(mime); | 196 sender.SetContentType(mime); |
156 | 197 |
157 const char* extension; | 198 const char* extension; |
158 switch (info.GetContentType()) | 199 switch (info.GetContentType()) |
159 { | 200 { |