The Halting problem states that it is impossible to write a program that can determine if another program halts, for all possible input programs.
I can, however, certainly write a program that can compute the running time of a program of like:
for(i=0; i<N; i++)
{ x = 1; }
and return a time complexity of $N$, without ever running it.
For all other input programs, it would return a flag indicating it was unable to determine the time-complexity.
My question is this:
What conditions must hold, such that we can algorithmically determine the time-complexity of a given program?
*If there is a canonical reference or review article to this I would appreciate a link to it in the comments.