Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement heap snapshot memory tracker for r2 #1636

Merged
merged 1 commit into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/workerd/api/r2-admin.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ class R2Admin: public jsg::Object {
JSG_METHOD(list);
}

void visitForMemoryInfo(jsg::MemoryTracker& tracker) const {
tracker.trackField("jwt", jwt);
}

private:
R2Bucket::FeatureFlags featureFlags;
uint subrequestChannel;
Expand Down
34 changes: 34 additions & 0 deletions src/workerd/api/r2-bucket.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,14 @@ class R2Bucket: public jsg::Object {
jsg::Optional<kj::Array<kj::byte>> sha256;
jsg::Optional<kj::Array<kj::byte>> sha384;
jsg::Optional<kj::Array<kj::byte>> sha512;

void visitForMemoryInfo(jsg::MemoryTracker& tracker) const {
tracker.trackField("md5", md5);
tracker.trackField("sha1", sha1);
tracker.trackField("sha256", sha256);
tracker.trackField("sha384", sha384);
tracker.trackField("sha512", sha512);
}
};

struct HttpMetadata {
Expand All @@ -144,6 +152,14 @@ class R2Bucket: public jsg::Object {
JSG_STRUCT_TS_OVERRIDE(R2HTTPMetadata);

HttpMetadata clone() const;

JSG_MEMORY_INFO(HttpMetadata) {
tracker.trackField("contentType", contentType);
tracker.trackField("contentLanguage", contentLanguage);
tracker.trackField("contentDisposition", contentDisposition);
tracker.trackField("contentEncoding", contentEncoding);
tracker.trackField("cacheControl", cacheControl);
}
};

struct PutOptions {
Expand Down Expand Up @@ -221,6 +237,15 @@ class R2Bucket: public jsg::Object {
JSG_TS_OVERRIDE(R2Object);
}

void visitForMemoryInfo(jsg::MemoryTracker& tracker) const {
tracker.trackField("name", name);
tracker.trackField("version", version);
tracker.trackField("etag", etag);
tracker.trackField("checksums", checksums);
tracker.trackField("httpMetadata", httpMetadata);
tracker.trackField("customMetadata", customMetadata);
}

protected:
kj::String name;
kj::String version;
Expand Down Expand Up @@ -271,6 +296,10 @@ class R2Bucket: public jsg::Object {
json<T>(): Promise<T>;
});
}

void visitForMemoryInfo(jsg::MemoryTracker& tracker) const {
tracker.trackField("body", body);
}
private:
jsg::Ref<ReadableStream> body;
};
Expand Down Expand Up @@ -402,6 +431,11 @@ class R2Bucket: public jsg::Object {
bool secondsGranularity = false;
};

void visitForMemoryInfo(jsg::MemoryTracker& tracker) const {
tracker.trackField("adminBucket", adminBucket);
tracker.trackField("jwt", jwt);
}

protected:
kj::Maybe<kj::StringPtr> adminBucketName() const {
return adminBucket;
Expand Down
6 changes: 6 additions & 0 deletions src/workerd/api/r2-multipart.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ class R2MultipartUpload: public jsg::Object {
JSG_METHOD(complete);
}

void visitForMemoryInfo(jsg::MemoryTracker& tracker) const {
tracker.trackField("key", key);
tracker.trackField("uploadId", uploadId);
tracker.trackField("bucket", bucket);
}

protected:
kj::String key;
kj::String uploadId;
Expand Down
8 changes: 5 additions & 3 deletions src/workerd/jsg/jsg.h
Original file line number Diff line number Diff line change
Expand Up @@ -945,15 +945,17 @@ struct Dict {
Value value;

JSG_MEMORY_INFO(Field) {
tracker.trackField(name);
tracker.trackField(value);
tracker.trackField("name", name);
tracker.trackField("value", value);
Comment on lines +948 to +949
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe "key" and "value" would be slightly more standard?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

possibly but I want to keep the names aligned with the actual fields as much as possible.

}
};

kj::Array<Field> fields;

JSG_MEMORY_INFO(Dict) {
tracker.trackField(fields);
for (const auto& field : fields) {
tracker.trackField(nullptr, field);
}
}
};

Expand Down
Loading