Contact your local building department and ask it at what depth posts should be set. Building codes require posts to be set below the frost line, but that varies widely between regions. You need to dig the post hole to that requirement and may require concrete, gravel or piers under the posts.
Measure the depth of the hole from ground level to the bottom of the hole, or the top of any support fills, such as concrete or gravel.
Measure the required height of the post. If the post also serves as support for the canopy or roof, the height should accommodate that purpose.
Add the height and depth together to get the total length of the post and pier, combined.
Measure the height of the support piers. These might be precast concrete footpads that attach to the ends of the posts.
Subtract the height of the pier from the total required length of the post and pier. This will give you the total length of just the post.