As I understand it the purpose of sleep is to remove beta-amyloid proteins from the brain, because they plaque together and make signals derptarded. Particularly new learning.
When you sleep the brain shrinks a significant amount and CSF flows increase 400% or so to sweep out beta-amyloid proteins to the liver for digestion. Which is why chronic alcohol use leads to bad sleep long term, but will put you to sleep quickly short term.
Anyways if you are chronically sleep deprived you will "quick sleep" and pass completely out for like 4 hrs. Just last week I wasn't getting enough sleep and got like 12 hrs of sleep both weekend days. Kinda sucked I had alot to do.
It only takes one night of good sleep to undo the damage and re-balance your mood and learning IMO. However your hormones that regulate sleep like ADH will be all out of whack. ADH makes you retain water before you sleep for obvious reasons. You need to be hydrated to get good sleep. When you drink caffeine and pee clear you are dumping sodium from your blood volume. You won't be thirsty because the body doesn't have a water sensor so to speak, it only has cells that can measure blood pressure and sodium concentration so you can dump water and sodium from the blood which thickens it, and the caffeine increases your BP, and your body doesn't realize how dehydrated it is.
So my recommendation to fix bad sleep is a good regimen. Your body is programmed to eat during waking hours. So make sure you eat while at work. If you drink caffeine make sure you eat some SALTY food after work to trigger thirst as your levels of caffeine come down. Salt will make your body realize its dehydrated then you'll actually be thirsty and want to drink water as oppose to just getting a headache and being thirsty but not wanting to drink. This should kick in right before bed and then ADH will retain the water and you'll pass out.
Also chronic bad sleep is linked to poor mood/mental disorders so don't do anything stupid or make big decisions until you get good rest.