
Be on your/its last legs
Metaphoric Use
This phrase often metaphorically describes extreme tiredness or effort. 
Not Literal
Don't take it literally; it doesn't always involve legs. 
Informal Context
It's casual, more likely heard in conversation than formal writing. 