The phrase evokes a calm, monotonous activity meant to induce sleep by picturing a repetitive motion. When she couldn't sleep, she tried to count sheep, imagining them hopping one by one.
Pro Tip 2/3
Not Literal
Counting sheep is not a literal action but a mental exercise for relaxation and sleep. You don't really count sheep, just picture them in your mind as you try to fall asleep.
Pro Tip 3/3
Cultural Classic
The idea of counting sheep is widely recognized in English-speaking cultures as a common sleep aid. He joked that he got so bored at work, he might as well have been counting sheep.