Skip to content
This repository has been archived by the owner on Feb 17, 2024. It is now read-only.

timecraft: add profile resource #33

Merged
merged 7 commits into from
May 30, 2023
Merged

timecraft: add profile resource #33

merged 7 commits into from
May 30, 2023

Conversation

achille-roussel
Copy link
Contributor

This PR adds a new resource type for performance profiles; they get recorded in the object store and get discovered like other resources.

$ ./timecraft profile 181e2fed-7e69-4c3d-8631-b9ed2bdc120c
PROFILE ID    PROCESS ID                            TYPE    START    DURATION  SIZE
d3451ebfcd3c  181e2fed-7e69-4c3d-8631-b9ed2bdc120c  cpu     44s ago  2s        126 KiB
5cd1c90f60a2  181e2fed-7e69-4c3d-8631-b9ed2bdc120c  memory  44s ago  2s        6.83 KiB

Still fleshing out how to get pprof launched off of the recorded profiles (so still WIP).

Signed-off-by: Achille Roussel <[email protected]>
Signed-off-by: Achille Roussel <[email protected]>
@achille-roussel
Copy link
Contributor Author

I added a --export option to the command so generated profiles can be written to local files.

Signed-off-by: Achille Roussel <[email protected]>
Signed-off-by: Achille Roussel <[email protected]>
Comment on lines -45 to -70
// Details about a function call.
table FunctionCall {
// State of the WebAssembly stack before and after the function was called.
// The first {param_count} values are the input parameters, and the remaining
// values are the return values.
stack:[ulong];
// Captured sections of the WebAssembly module's linear memory, stored
// contiguously and indexed by {memory_access}.
memory:[ubyte];
// Ordered collection of memory reads and writes made by the function.
memory_access:[MemoryAccess];
}

// MemoryAccess represents the capture of a section of memory.
struct MemoryAccess {
// Byte offset in the WebAssembly module's linear memory where the memory
// access starts.
offset:uint;
// Byte offset into {FunctionCall.memory}. The length of the captured memory
// can be derived by comparing the {index_offset} with that of the next
// {FunctionCall.memory_access}. The length of the final memory region can
// be derived by comparing the {index_offset} with the length of
// {FunctionCall.memory}.
index_offset:uint;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is unrelated to the actual change but was unused.

Signed-off-by: Achille Roussel <[email protected]>
Signed-off-by: Achille Roussel <[email protected]>
Type: desc.Annotations["timecraft.profile.type"],
StartTime: human.Time(startTime),
Duration: human.Duration(endTime.Sub(startTime)),
Size: human.Bytes(desc.Size),
Copy link
Contributor

@chriso chriso May 30, 2023

Choose a reason for hiding this comment

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

Not sure if this is possible, but are there high-level summary metrics we can derive from the profiles, either immediately accessible or something we can aggregate once and cache? For example, it'd be cool to see avg/max CPU utilization, or avg/max RSS, when listing profiles so that you can see basic trends over time, and see anomalies sticking out so you know what to drill down into.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I like this idea! I'm going to think about it some more.

CPU utilization is interesting, we can compute I/O wait by summing the time spent in stack traces that end in fd_read/fd_write, and ratio that to the total time to estimate CPU usage.

There are a few things that still need adjustments in the CPU profile, the timing is not very precise because we only increment the monotonic clock when we see a record of host function. We can't use the real-time directly because the CPU on which the profile is generated may be different than the one the program was running, but I think we can create a model which works by being a little clever.

I'll look at those enhancements in follow-ups, thanks for the suggestion!

@achille-roussel achille-roussel merged commit 23261fd into main May 30, 2023
3 checks passed
@achille-roussel achille-roussel deleted the profile-resource branch May 30, 2023 21:16
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants