There are a few ways for both doctors and researchers.
First we have to know when an optimal ammount of sleep did a Person get. There are 2 Aspects to judge it: Risks of pathological developements and Change in Performance.
The first can only be tested in a large population (mostly in meta-analysis rather than randomized control trials), but the latter can also be tested on individuals.
You let the patient/subject sleep various ammounts of time and take some critical metrics that correlate with some pathological developments. For instance if high blood pressure gets lowered by increasing the ammount of sleep, then you can assume that the person should sleep more. If you probe a person on the cortisol secretion, you could also determine if a person has enough sleep.
Let's say a person has some particular performance on a task. Now we can have the person do the task daily with various ammounts of sleep. After normalization (taking into account the average improvement and average loss of performance during sleep duration change), we can determine which ammount of sleep was optimal for the subject.
Another way is to use an electrocardiogram&electroencephalogram and analyse whether the sleep process corresponds to a healthy sleep process (sleep cycle durations, count, sleep waves).
So far these methods are being used by researches, but you have to remember that a doctor will most likely not use any of those. Instead, a doctor will be more interested in sleep deprivation (when you're clearly missing sleep, not when you want to optimize sleep). A doctor will ask you about drops of performance and take some basic metrics (like blood pressure). If they see a negative trend, they might recommend longer sleep.
In case you just wanted to know how much sleep you need: I think the best way is to simply trust your body. Go to sleep without setting an alarm, when you wake up, get out of the bed. It's not scientific, but you'll get a good idea on how long should you sleep.
Further reading:
Sleep duration optimalisation
Sleep stages and at the end some rule of thumb sleep durations.