Skip to content

Commit cf0a262

Browse files
committed
Add feature observer metrics for blob API usage
1 parent 930f334 commit cf0a262

3 files changed

Lines changed: 18 additions & 1 deletion

File tree

src/workerd/api/blob.c++

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "blob.h"
66
#include "streams.h"
77
#include "util.h"
8+
#include <workerd/io/observer.h>
89
#include <workerd/util/mimetype.h>
910

1011
namespace workerd::api {
@@ -90,6 +91,11 @@ jsg::Ref<Blob> Blob::constructor(jsg::Optional<Bits> bits, jsg::Optional<Options
9091
return jsg::alloc<Blob>(concat(kj::mv(bits)), kj::mv(type));
9192
}
9293

94+
kj::ArrayPtr<const byte> Blob::getData() const {
95+
FeatureObserver::maybeRecordUse(FeatureObserver::Feature::BLOB_GET_DATA);
96+
return data;
97+
}
98+
9399
jsg::Ref<Blob> Blob::slice(jsg::Optional<int> maybeStart, jsg::Optional<int> maybeEnd,
94100
jsg::Optional<kj::String> type) {
95101
int start = maybeStart.orDefault(0);
@@ -123,9 +129,11 @@ jsg::Ref<Blob> Blob::slice(jsg::Optional<int> maybeStart, jsg::Optional<int> may
123129

124130
jsg::Promise<kj::Array<kj::byte>> Blob::arrayBuffer(jsg::Lock& js) {
125131
// TODO(perf): Find a way to avoid the copy.
132+
FeatureObserver::maybeRecordUse(FeatureObserver::Feature::BLOB_AS_ARRAY_BUFFER);
126133
return js.resolvedPromise(kj::heapArray<byte>(data));
127134
}
128135
jsg::Promise<kj::String> Blob::text(jsg::Lock& js) {
136+
FeatureObserver::maybeRecordUse(FeatureObserver::Feature::BLOB_AS_TEXT);
129137
return js.resolvedPromise(kj::str(data.asChars()));
130138
}
131139

@@ -185,6 +193,7 @@ private:
185193
};
186194

187195
jsg::Ref<ReadableStream> Blob::stream() {
196+
FeatureObserver::maybeRecordUse(FeatureObserver::Feature::BLOB_AS_STREAM);
188197
return jsg::alloc<ReadableStream>(
189198
IoContext::current(),
190199
kj::heap<BlobInputStream>(JSG_THIS));

src/workerd/api/blob.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class Blob: public jsg::Object {
1919
Blob(jsg::Ref<Blob> parent, kj::ArrayPtr<const byte> data, kj::String type)
2020
: ownData(kj::mv(parent)), data(data), type(kj::mv(type)) {}
2121

22-
inline kj::ArrayPtr<const byte> getData() const KJ_LIFETIMEBOUND { return data; }
22+
kj::ArrayPtr<const byte> getData() const KJ_LIFETIMEBOUND;
2323

2424
// ---------------------------------------------------------------------------
2525
// JS API

src/workerd/io/features.capnp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,12 @@ $Cxx.allowCancellation;
1010

1111
enum Features {
1212
test @0;
13+
14+
# We want to determine how users typically read the data from a Blob.
15+
# The reason is so that we can determine how best to optimize the Blob
16+
# implementation.
17+
blobAsArrayBuffer @1;
18+
blobAsText @2;
19+
blobAsStream @3;
20+
blobGetData @4;
1321
}

0 commit comments

Comments
 (0)