Well, first, you need to get the number of queries used. You can use something like MicroStats.
Then, you need to get the number of lines used in the page. Use something like count(file($SERVER["PHP_SELF"])) to find the number of lines in the current file, then calculate:
$percentmysql = int($queries/count(file($SERVER["PHP_SELF"])));
$percentphp = 100-$percentmysql;
Hope this helps. Please note that this is not optimised nor fast in any way!