You can do this lots of ways. Here's a quick way from the command line:
iisapp
tasklist /FI "IMAGENAME eq w3wp.exe"
then just line up the PID numbers.
So the way I am getting this data is just normal dbcc showcontig in a db. But for some reason, when I saw the output of dbcc showcontig today, I just decided I *had* to parse it with the command line. /sigh I just wanted the logical scan fragmentation. So this is, in part, the output.
Profile_Lookup 99
MSSCrawledProperties 96
MSSManagedProperties 66
UserProfileEventLog 50
UserColleagues 40
UserMemberships 85
UserSites 66
MembershipRecursive 73
MembershipNonRecursive 1
Etc etc etc etc
To do this I just did a simple for loop with a call out to a …. I forget what these things are even called since no one uses them anymore or cares....