Get profile by building metadata instead of guessing

Rather than doing some ad-hoc lookups of internal data structures
stpierre suggested that it'd be better to use the normal metadata
build procedures.  This implements that and adjusts the tests.