Sounds to me like the real solution to this problem is to have some sleep hygiene and get off of your laptop for awhile when you get sleepy.
If I was frequently waking on the couch with my laptop on my chest I wouldn't think "gee, did I get enough sleep? I should write an application that detects what time I doze off on the couch!" I'd think "Wow, I need to address my late night computing habits, as they're clearly interfering with my sleep."
So you want to answer the questions 'when did i fall sleep last night?' and 'did i get enough sleep?' I have to wonder why.
It suggests you are wanting to ensure you get a healthy amount of sleep by getting the answers to these questions. But really, you don't need to answer these questions at all. Instead just time-box the amount of sleep you should have (whatever you determine that to be) and then just set alarms on your phone/laptop around your schedule to instruct you when to go to bed and when to sleep - sorted.
I sense your overly elaborate, approximate solution to your problem is a result of you suffering from sleep deprivation! ;)
If I was frequently waking on the couch with my laptop on my chest I wouldn't think "gee, did I get enough sleep? I should write an application that detects what time I doze off on the couch!" I'd think "Wow, I need to address my late night computing habits, as they're clearly interfering with my sleep."