cuda profiler

hey I am a newcomer to the CUDA world. I’d be grateful for some help with a simple question.

I wanted to know if cuda compiler nvcc’s source code is available. I hav been searching for it.
I wanted to edit it for my project.
Actually I wanted to do source code instrumentation for profiling which I thought can be done during compilation.
So I wanted the source code of nvcc. If i get lex and yacc file containing grammar rules for CUDA C it would be sufficient I guess.

In CUDA 4.0, in command line run:

export CUDA_PROFILE=1
export CUDA_PROFILE_CSV=1
export CUDA_PROFILE_LOG=profile.csv
export CUDA_PROFILE_CONFIG=configProf

and add “configProf” file to the project folder which has :

gpustarttimestamp
instructions

Can anyone explain how the profiler works. How it measures all the time , instructions etc given the executable. I know how to run a profiler. I wanted to know its background working.
I want to develop a profiler of my own. So I need to understand how the existing profiler works.
I am provided with the executable and need to develop a profiler to profile the executable.