Make the debug script profile aware
Remove duplicated code

And deprecate duplicated function.