import sys
import os
import subprocess
import string
import random

import signal
import subprocess
import time

import collections
import itertools
import sys
import os.path

from energy_parser import *

import ConfigParser

num_of_programs = sys.argv[1]
output_directory = sys.argv[2]

os.system("cd "+output_directory)

for i in range (int(num_of_programs)):

	print('****')
	
	pro = subprocess.Popen("./get-power.sh")
	#execute program
	time.sleep(0.1)
	
	cudafile = "cudatest"+str(i)
	os.system("nvcc -c "+output_directory+"/"+cudafile+".cu >/dev/null 2>&1 && nvcc -o cudatest "+cudafile+".o")
	os.system("./cudatest")
	os.system("rm ./cudatest*")

	pro.kill()
	energy_results()

	pro = subprocess.Popen("./get-power.sh")
	#execute program
	time.sleep(0.1)

	cfile = "ctest"+str(i)
	print("Analysing Program "+str(i))
	os.system("gcc -std=c11 -c "+output_directory+"/"+cfile+".c >/dev/null 2>&1 && gcc -o ctest "+cfile+".o")
	os.system("./ctest")

	pro.kill()
	energy_results()

	os.system("rm ./ctest*")