예제 #1
0
int main(int argc, char *argv[]) {
  PSInit(&argc, &argv, 3, N, N, N);
  PSGrid3DPoint g = PSGrid3DPointNew(N, N, N);

  PSDomain3D d = PSDomain3DNew(1, N-1, 1, N-1, 1, N-1);
  size_t nelms = N*N*N;
  
  struct Point *indata = (struct Point *)malloc(
      sizeof(struct Point) * nelms);
  struct Point *outdata = (struct Point *)malloc(
      sizeof(struct Point) * nelms);
  int i;
  for (i = 0; i < nelms; i++) {
    indata[i].p[0] = i;
    indata[i].p[1] = 0;
    outdata[i].p[0] = 0;
    outdata[i].p[1] = 0;
  }
    
  PSGridCopyin(g, indata);

  PSStencilRun(PSStencilMap(kernel1, d, g));
    
  PSGridCopyout(g, outdata);

  dump(outdata);

  PSGridFree(g);
  PSFinalize();
  free(indata);
  free(outdata);
  return 0;
}
예제 #2
0
int main(int argc, char *argv[]) {
  PSInit(&argc, &argv, 3, N, N, N);
  PSGrid3DFloat g1 = PSGrid3DFloatNew(N, N, N);
  PSGrid3DFloat g2 = PSGrid3DFloatNew(N, N, N);

  PSDomain3D d = PSDomain3DNew(0, N, 0, N, 0, N);
  size_t nelms = N*N*N;
  
  float *indata = (float *)malloc(sizeof(float) * nelms);
  int i;
  for (i = 0; i < nelms; i++) {
    indata[i] = i;
  }
  float *outdata = (float *)malloc(sizeof(float) * nelms);
    
  PSGridCopyin(g1, indata);
  PSGridCopyin(g2, indata);  

  PSStencilRun(PSStencilMap(kernel, d, g1, g2));
    
  PSGridCopyout(g2, outdata);
  dump(outdata);  

  PSGridFree(g1);
  PSGridFree(g2);
  PSFinalize();
  free(indata);
  free(outdata);
  return 0;
}
int main(int argc, char *argv[]) {
  PSInit(&argc, &argv, 3, N, N, N);
  PSGrid3DPoint1 g1 = PSGrid3DPoint1New(N, N, N);
  size_t nelms = N*N*N;
  struct Point1 *indata = (struct Point1 *)malloc(
      sizeof(struct Point1) * nelms);
  struct Point1 *outdata = (struct Point1 *)malloc(
      sizeof(struct Point1) * nelms);
  int i, j;
  int x = 0;
  float c = 1.0f;
  for (x = 0; x < nelms; ++x) {
    for (i = 0; i < DIM1; ++i) {
      for (j = 0; j < DIM2; ++j) {
        indata[x].p[i][j] = c++;
        outdata[x].p[i][j] = 0;
      }
    }
  }
    
  PSGridCopyin(g1, indata);
  PSGridCopyout(g1, outdata);

  check(indata, outdata);

  PSGridFree(g1);
  PSFinalize();
  free(indata);
  free(outdata);
  return 0;
}
예제 #4
0
int main(int argc, char *argv[]) {
  PSInit(&argc, &argv, 3, NX, NX, NX);
  PSGrid3DReal g = PSGrid3DRealNew(NX, NX, NX);
  PSDomain3D d = PSDomain3DNew(0, NX, 0, NX, 0, NX);  

  struct timeval time_begin, time_end;
  int    nx    = NX;
  int    ny    = NX;
  int    nz    = NX;
  REAL  *buff  = (REAL *)malloc(sizeof(REAL) *nx*ny*nz);
  REAL   time  = 0.0;
  int    count = 1000;
  REAL l, dx, dy, dz, kx, ky, kz, kappa, dt;
  REAL ce, cw, cn, cs, ct, cb, cc;

  l = 1.0;
  kappa = 0.1;
  dx = dy = dz = l / nx;
  kx = ky = kz = 2.0 * M_PI;
  dt = 0.1*dx*dx / kappa;

  init(buff, nx, ny, nz, kx, ky, kz, dx, dy, dz, kappa, time);

  PSGridCopyin(g, buff);

  ce = cw = kappa*dt/(dx*dx);
  cn = cs = kappa*dt/(dy*dy);
  ct = cb = kappa*dt/(dz*dz);
  cc = 1.0 - (ce + cw + cn + cs + ct + cb);

  gettimeofday(&time_begin, NULL);
  PSStencilRun(PSStencilMap(kernel, d, g,ce,cw,cn,cs,ct,cb,cc),
               count);
  gettimeofday(&time_end, NULL);

  time += dt * count;
  REAL *answer = (REAL *)malloc(sizeof(REAL) * nx*ny*nz);
  init(answer, nx, ny, nz, kx, ky, kz, dx, dy, dz, kappa, time);
  PSGridCopyout(g, buff);
  REAL err = accuracy(buff, answer, nx*ny*nz);
  double elapsed_time = (time_end.tv_sec - time_begin.tv_sec)
                        + (time_end.tv_usec - time_begin.tv_usec)*1.0e-6;
  REAL mflops = (nx*ny*nz)*13.0*count/elapsed_time * 1.0e-06;
  double thput = (nx * ny * nz) * sizeof(REAL) * 2.0 * count
                 / elapsed_time / (1000 * 1000 * 1000);

  fprintf(stderr, "elapsed time : %.3f (s)\n", elapsed_time);
  fprintf(stderr, "flops        : %.3f (MFlops)\n", mflops);
  fprintf(stderr, "throughput   : %.3f (GB/s)\n", thput);
  fprintf(stderr, "accuracy     : %e\n", err);  
  fprintf(stderr, "count        : %d\n", count);
  free(answer);
  PSGridFree(g);
  PSFinalize();
  return 0;
}
예제 #5
0
int main(int argc, char *argv[]) {
  PSInit(&argc, &argv, 3, N, N+2, N);
  PSGrid3DFloat g1 = PSGrid3DFloatNew(N, N+2, N);
  PSGrid3DFloat g2 = PSGrid3DFloatNew(N, N+2, N);
  PSGrid1DFloat cx = PSGrid1DFloatNew(N);
  PSGrid2DFloat cy = PSGrid2DFloatNew(N+2, N);


  PSDomain3D d = PSDomain3DNew(1, N-1, 1, N+1, 1, N-1);
  size_t nelms = N*(N+2)*N;
  
  float *indata = (float *)malloc(sizeof(float) * nelms);
  int i;
  for (i = 0; i < nelms; i++) {
    indata[i] = i;
  }
  float *outdata = (float *)malloc(sizeof(float) * nelms);
    
  PSGridCopyin(g1, indata);
  PSGridCopyin(g2, indata);

  for (i = 0; i < N; ++i) {
    indata[i] = 1 + (i%2); // 1 or 2
  }
  PSGridCopyin(cx, indata);
  for (i = 0; i < (N+2)*N; ++i) {
    indata[i] = 1 + (i%2); // 1 or 2
  }
  PSGridCopyin(cy, indata);

  PSStencilRun(PSStencilMap(kernel, d, g1, g2, cx, cy));
    
  PSGridCopyout(g2, outdata);
  dump(outdata);  

  PSGridFree(g1);
  PSGridFree(g2);
  PSGridFree(cx);
  PSGridFree(cy);
  PSFinalize();
  free(indata);
  free(outdata);
  return 0;
}
예제 #6
0
int main(int argc, char *argv[]) {
  PSInit(&argc, &argv, 3, N+1, N+1, N+1);
  PSGrid3DFloat g1 = PSGrid3DFloatNew(N, N, N);
  PSGrid3DFloat g2 = PSGrid3DFloatNew(N+1, N+1, N+1);  
  PSDomain3D d = PSDomain3DNew(0, N, 0, N, 0, N);
  size_t nelms1 = N*N*N;
  size_t nelms2 = (N+1)*(N+1)*(N+1);  
  
  float *indata = (float *)malloc(sizeof(float) * nelms2);
  int i;
  for (i = 0; i < nelms2; i++) {
    indata[i] = i;
  }

  float *outdata = (float *)malloc(sizeof(float) * nelms1);
    
  PSGridCopyin(g2, indata);

  PSStencilRun(PSStencilMap(kernel1, d, g1, g2));
    
  PSGridCopyout(g1, outdata);

  dump(outdata, nelms1, stdout);
#if 0    
  for (i = 0; i < nelms; i++) {
    if (indata[i] != outdata[i]) {
      fprintf(stderr, "Error: mismatch at %d, in: %f, out: %f\n",
              i, indata[i], outdata[i]);
    }
  }
#endif

  PSGridFree(g1);
  PSGridFree(g2);
  PSFinalize();
  free(indata);
  free(outdata);
  return 0;
}
예제 #7
0
파일: test_14.c 프로젝트: dmikushin/physis
int main(int argc, char *argv[]) {
  PSInit(&argc, &argv, 3, N, N, N);
  PSGrid3D g1 = PSGrid3DNew(N, N, N);
  size_t nelms = N*N*N;
  float *indata = (float *)malloc(sizeof(REAL) * nelms);
  int i;
  for (i = 0; i < nelms; i++) {
    indata[i] = i+10;
  }
  PSGridCopyin(g1, indata);
  float v;
  PSReduce(&v, PS_MIN, g1);
  float v_ref = reduce(indata);
  fprintf(stderr, "Reduction result: %f, reference: %f\n", v, v_ref);
  if (v != v_ref) {
    fprintf(stderr, "Error: Non matching result\n");
    exit(1);
  }
  PSGridFree(g1);
  PSFinalize();
  free(indata);
  return 0;
}
예제 #8
0
int main(int argc, char *argv[]) {
  PSInit(&argc, &argv, 3, N, N, N);
  PSGrid3DPoint g = PSGrid3DPointNew(N, N, N);

  PSDomain3D d = PSDomain3DNew(0+halo_width, N-halo_width,
                               0+halo_width, N-halo_width,
                               0+halo_width, N-halo_width);
  size_t nelms = N*N*N;
  
  struct Point *indata = (struct Point *)malloc(
      sizeof(struct Point) * nelms);
  int i;
  for (i = 0; i < nelms; i++) {
    indata[i].p = i;
    indata[i].q = i+1;
    indata[i].r = 0;
  }
  struct Point *outdata_ps = (struct Point *)malloc(
      sizeof(struct Point) * nelms);
    
  PSGridCopyin(g, indata);

  PSStencilRun(PSStencilMap(kernel1, d, g),
               PSStencilMap(kernel2, d, g),
               ITER);
    
  PSGridCopyout(g, outdata_ps);

  dump(outdata_ps);

  PSGridFree(g);
  PSFinalize();
  free(indata);
  free(outdata_ps);
  return 0;
}
예제 #9
0
void method()
{		
		//wifi
		if(network==1)
		{
			sprintf(path_tx,"/sys/class/net/wlan0/statistics/tx_packets");
			sprintf(path_rx,"/sys/class/net/wlan0/statistics/rx_packets");
			sprintf(path_oper,"/sys/class/net/wlan0/operstate");
		}
		//3G
		else if(network==0)
		{
			sprintf(path_tx,"/sys/class/net/rmnet0/statistics/tx_packets");
			sprintf(path_rx,"/sys/class/net/rmnet0/statistics/rx_packets");
			sprintf(path_oper,"/sys/class/net/rmnet0/operstate");
		}
		
		isRunOnce = 1;
		
		size = nRows;
		
		samples = (char **)malloc(nRows * sizeof(char *));
		
		int c2=0;
		for(c2=0; c2<nRows; c2++)
			samples[c2] = (char *) malloc(numCol * sizeof(char));
			
		
		printf("test passed2\n");
		
		SPVRScopeImplData *psData;
		
		//Counter information (set at init time)
		SPVRScopeCounterDef    *psCounters;
		unsigned int      uCounterNum;
		
		//Counter reading data
		unsigned int      uActiveGroup;
		unsigned int      uActiveGroupSelect;
		bool        bActiveGroupChanged;
		SPVRScopeCounterReading  sReading;
		
		// Step 2. Initialise PVRScopeStat
		if (PSInit(&psData, &psCounters, &sReading, &uCounterNum)){
			//LOGI("PVRScope up and running.");
			printf("PVRScore up and running...\n");
			
			/*sprintf(aut,"%s\n","su");
			system(aut);*/
			
		}else{
			//LOGE("Error initializing PVRScope.");
			printf("Error initializing PVRScope...\n");
		}
		
		bActiveGroupChanged = true;
		uActiveGroupSelect = 0;
		unsigned int sampleRate = delay;
		unsigned int index = 0;
		unsigned int j = 0;
		unsigned int k = 0;
				
			
		struct timeval tv_start;
		gettimeofday(&tv_start, NULL);
		unsigned long time_in_sec_start = tv_start.tv_sec;
						
		printf("Begin working...\n");
		
		/*
		strcat(header,"Start_time(second)=");
		char startTime[1024];
		snprintf(startTime,1024,"%lu\n",time_in_sec_start);
		strcat(header,startTime);
				
		strcat(header,"delay=");
		char delayData[50];
		snprintf(delayData,50,"%d\n",delay);
		strcat(header,delayData);
		*/
		
		int startIndex = 0;
						
		while (startIndex < nRows)
		{
				// Ask for the active group 0 only on the first run. Then set it to 0xffffffff
				if(bActiveGroupChanged)
				{
						uActiveGroup = uActiveGroupSelect;
				}
				else 
				{
						uActiveGroup = 0xffffffff;
				}
				
				++index;
				
				if (index < 100) 
				{
					// Sample the counters every 10ms. Don't read or output it.
					PVRScopeReadCountersThenSetGroup(psData, NULL, 0, uActiveGroup);
				} 
				else 
				{				
					if(k < delay)
					{
						++k;
						index = 0;
						//continue;
					}
					else
					{
						
						k = 0;
						index = 0;
						printf("sample %d\n", startIndex);

						struct timeval tv;
						gettimeofday(&tv, NULL);
						unsigned long time_in_mill = (tv.tv_sec) * 1000 + (tv.tv_usec) / 1000;
						
						// Step 4. Read and output the counter information for group 0 to Logcat
						if(PVRScopeReadCountersThenSetGroup(psData, &sReading, time_in_mill * 1000, uActiveGroup))
						{
																		
							printf("Start sample\n");		
						
							strcat(header,"\n_LOOP_");
							char loop[50];
							snprintf(loop, 50, "%d\n", startIndex);
							strcat(header,loop);
							
							/*if(startIndex == 10){
								setState(2);
							}
							else if(startIndex == 15){
								setState(5);
							}*/
							
							//Read bigLittle_status
							if((fp_cpu = fopen("su -c /dev/bL_status","r")) != NULL) 
							{	
								printf("bl\n");
								strcat(header,"_BL_\n");
								fgets(buffer,sizeof buffer, fp_cpu);
								fgets(buffer,sizeof buffer, fp_cpu);
								strcat(header,buffer);
								fgets(buffer,sizeof buffer, fp_cpu);
								strcat(header,buffer);
								memset(buffer, 0, sizeof(buffer));
								fclose(fp_cpu);
							}
												
							strcat(header,"_CPU_\n");
							if((fp_cpu = fopen("/proc/stat","r")) != NULL) 
							{		
								
								fgets(buffer,sizeof buffer, fp_cpu);
								
								//CPU0
								fgets(buffer,sizeof buffer, fp_cpu);
								double cpu_util = parseCPU(buffer,0);
								char output[50];
								snprintf(output,50,"util=%.2f",cpu_util);
								strcat(header,output);
								printf("cpu0 util = %s \n",header);
								memset(buffer, 0, sizeof(buffer));
								memset(output, 0, sizeof(output));
								
								if((fp_cpu_chk = fopen("/sys/devices/system/cpu/cpu1/online","r")) != NULL)
								{ 
									char test[50];
									fgets(test, sizeof test, fp_cpu_chk);
									
									if(atoi(test) == 1)
									{
										fgets(buffer,sizeof buffer, fp_cpu);
										cpu_util = parseCPU(buffer,1);
										snprintf(output,50," %.2f",cpu_util);
										strcat(header,output);
										memset(buffer, 0, sizeof(buffer));
										memset(output, 0, sizeof(output));
										//fclose(fp_cpu);
									}
									else
									{							
										strcat(header," x");
									}
									fclose(fp_cpu_chk);
								}
								
								if((fp_cpu_chk = fopen("/sys/devices/system/cpu/cpu2/online","r")) != NULL)
								{ 
									char test[50];
									fgets(test, sizeof test, fp_cpu_chk);
									if(atoi(test) == 1)
									{
										fgets(buffer,sizeof buffer, fp_cpu);
										cpu_util = parseCPU(buffer,2);
										snprintf(output,50," %.2f",cpu_util);
										strcat(header,output);
										memset(buffer, 0, sizeof(buffer));
										memset(output, 0, sizeof(output));
										//fclose(fp_cpu);
									}
									else
									{
										strcat(header," x");
										//printf(" x");
									}
									fclose(fp_cpu_chk);
								}
								
								if((fp_cpu_chk = fopen("/sys/devices/system/cpu/cpu3/online","r")) != NULL)
								{ 
									char test[50];
									fgets(test, sizeof test, fp_cpu_chk);
									if(atoi(test) == 1)
									{
										fgets(buffer,sizeof buffer, fp_cpu);
										cpu_util = parseCPU(buffer,3);
										snprintf(output,50," %.2f",cpu_util);
										strcat(header,output);
										memset(buffer, 0, sizeof(buffer));
										memset(output, 0, sizeof(output));
										//fclose(fp_cpu);
									}
									else
									{
										strcat(header," x");
										//printf("last x\n");
									}
									
									fclose(fp_cpu_chk);
									
								}
								
								fclose(fp_cpu);		
								
							}
							
							strcat(header,"\n_FREQ_");
							
							//Read freq0
							if((fp_cpu = fopen("/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq","r")) != NULL)
							{	
								
								fgets(buffer,sizeof buffer, fp_cpu);
								strcat(header,"\nfreq0=");
								strcat(header,buffer);
								//printf("%s\n",header);
								memset(buffer, 0, sizeof(buffer));
								fclose(fp_cpu);
							}
							
							//Read freq1
							if((fp_cpu = fopen("/sys/devices/system/cpu/cpu1/cpufreq/scaling_cur_freq","r")) != NULL)
							{	
								//printf("freq1\n");
								fgets(buffer,sizeof buffer, fp_cpu);
								strcat(header,"freq1=");
								strcat(header,buffer);
								memset(buffer, 0, sizeof(buffer));
								fclose(fp_cpu);
							}
							else
							{
								strcat(header,"freq1=x");
								//printf("freq1=x");
							}					

							//Read freq2
							if((fp_cpu = fopen("/sys/devices/system/cpu/cpu2/cpufreq/scaling_cur_freq","r")) != NULL) {	
								
								//printf("freq2\n");
								fgets(buffer,sizeof buffer, fp_cpu);
								strcat(header,"freq2=");
								strcat(header,buffer);
								memset(buffer, 0, sizeof(buffer));
								fclose(fp_cpu);	
							}
							else
							{
								strcat(header,"\nfreq2=x");
								//printf("\nfreq2=x");
							}
						
							//Read freq3
							if((fp_cpu = fopen("/sys/devices/system/cpu/cpu3/cpufreq/scaling_cur_freq","r")) != NULL) {	
								//printf("freq3\n");
								fgets(buffer,sizeof buffer, fp_cpu);
								strcat(header,"freq3=");
								strcat(header,buffer);
								memset(buffer, 0, sizeof(buffer));
								fclose(fp_cpu);
															
							}
							else
							{
								strcat(header,"\nfreq3=x");
								//printf("\nfreq3=x");
							}
							
							//printf("%s\n",header);
							
							//Read CPU idle time C0S0IT //////////////////////////////////////////////////////////////////////////
							strcat(header,"\n_IDLE_TIME_\n");
							//printf("idle time\n");
							for(int core=0; core<4; core++)
							{
								char title[100];
								snprintf(title,100,"idle_time_%d=",core);
								strcat(header,title);
							
								for(int state=0; state<3; state++)
								{
								
									char proc[100];
									sprintf(proc,"/sys/devices/system/cpu/cpu%d/cpuidle/state%d/time",core,state);
									
									if((fp_cpu = fopen(proc,"r")) != NULL) 
									{	
									
										fgets(buffer,sizeof buffer, fp_cpu);
										strcat(header," ");
										double cur = atof(buffer);
										double diff_time = cur - csit[core][state];
										char output_idle[50];
										snprintf(output_idle,50,"%.2f",diff_time/1000);
										strcat(header,output_idle);				
										memset(buffer, 0, sizeof(buffer));
										csit[core][state] = cur;
										fclose(fp_cpu);
									}
									else{
										strcat(header," x");
									}
								}
								
								strcat(header,"\n");
									
							}
							
							strcat(header,"_IDLE_USAGE_\n");
							for(int core=0; core<4; core++)
							{
								char title[100];
								snprintf(title,100,"idle_usage_%d=",core);
								strcat(header,title);
							
								for(int state=0; state<3; state++)
								{
								
									char proc[100];
									sprintf(proc,"/sys/devices/system/cpu/cpu%d/cpuidle/state%d/usage",core,state);
									
									if((fp_cpu = fopen(proc,"r")) != NULL) 
									{	
									
										fgets(buffer,sizeof buffer, fp_cpu);
										strcat(header," ");
										int cur = atoi(buffer);
										int diff_entry = cur - csiu[core][state];
										char output_entry[50];
										snprintf(output_entry,50,"%d",diff_entry);
										strcat(header,output_entry);				
										memset(buffer, 0, sizeof(buffer));
										csiu[core][state] = cur;
										fclose(fp_cpu);
									}
									else{
										strcat(header," x");
									}
								}
								
								strcat(header,"\n");
									
							}
							
							///////////////////////// Read memory usage /////////////////////////////////////////
							strcat(header,"_MEM_\n");
							//if((fp = fopen("/data/local/tmp/busybox free -m", "r")) != NULL)
							if((fp_mem = fopen("/proc/meminfo","r")) != NULL)
							{
								//printf("mem\n");
								fgets(buffer, sizeof buffer, fp_mem);
								//printf("buffer = %s\n",buffer);
								strcat(header,"mem=");
								char buffer2[1024];
								char buffer3[1024];
								fgets(buffer2, sizeof buffer, fp_mem);
								fgets(buffer3, sizeof buffer, fp_mem);
								double mem_util = parseMem(buffer, buffer2, buffer3);
								char output[50];
								snprintf(output,50,"%.2f",mem_util);		
								strcat(header,output);
															
								memset(buffer, 0, sizeof(buffer));
								memset(buffer2, 0, sizeof(buffer2));
								memset(buffer3, 0, sizeof(buffer3));		
								fclose(fp_mem);
								
							}
						
							strcat(header,"\n_DISPLAY_");
							//Read bright
							//Nexus ("/sys/class/backlight/s5p_bl/brightness")
							if((fp = fopen("/sys/class/backlight/panel/brightness","r")) != NULL) {	
							
								//printf("brightness\n");
								fgets(buffer,sizeof buffer, fp);
								//sprintf(header,"\n_DISPLAY_\n%s","bright=");
								strcat(header,"\nbright=");
								strcat(header,buffer);				
								memset(buffer, 0, sizeof(buffer));
								fclose(fp);
								
							}
							
							if((fp = fopen("/sys/class/backlight/s5p_bl/brightness","r")) != NULL) {	
							
								//printf("brightness\n");
								fgets(buffer,sizeof buffer, fp);
								//sprintf(header,"\n_DISPLAY_\n%s","bright=");
								strcat(header,"\nbright=");
								strcat(header,buffer);				
								memset(buffer, 0, sizeof(buffer));
								fclose(fp);
								
							}
						
							strcat(header,"_WIFI_\n");
							//wifi				
							if((fp = fopen(path_tx,"r")) != NULL) {
								
								//printf("WiFi\n");
								fgets(buffer,sizeof buffer, fp);
								double cur = atof(buffer);
								double diff_tx = cur - prev_tx;
								char output_tx[50];
								snprintf(output_tx,50,"%.2f",diff_tx);
								strcat(header,"tx=");
								strcat(header,output_tx);
								memset(buffer, 0, sizeof(buffer));
								
								prev_tx = cur;
								fclose(fp);
							}
							else{
								strcat(header,"tx=0");
							}
							
							if((fp = fopen(path_rx,"r")) != NULL) {
							
								fgets(buffer,sizeof buffer, fp);
								double cur = atof(buffer);
								double diff_rx = cur - prev_rx;
								char output_rx[50];
								snprintf(output_rx,50,"%.2f",diff_rx);
								strcat(header,"\nrx=");
								strcat(header,output_rx);
								memset(buffer, 0, sizeof(buffer));
								
								prev_rx = cur;
								fclose(fp);
								
							}
							else{
								strcat(header,"\nrx=0");
							}
							
							if((fp = fopen(path_oper,"r")) != NULL) {
							
								fgets(buffer,sizeof buffer, fp);
								strcat(header,"\noperstate=");				
								strcat(header,buffer);				
								memset(buffer, 0, sizeof(buffer));
								fclose(fp);
							}
							else{
								strcat(header,"\noperstate=0");
							}
							
							
							//Battery						
							strcat(header,"\n_BATTERY_\n");
							if((fp = fopen("/sys/class/power_supply/battery/voltage_now","r")) != NULL) {
							
								fgets(buffer,sizeof buffer, fp);
								strcat(header,"batt_volt=");				
								strcat(header,buffer);				
								memset(buffer, 0, sizeof(buffer));
								fclose(fp);
							}
							
							if((fp = fopen("/sys/class/power_supply/battery/current_now","r")) != NULL) {
								fgets(buffer,sizeof buffer, fp);
								strcat(header,"batt_current=");				
								strcat(header,buffer);				
								memset(buffer, 0, sizeof(buffer));
								fclose(fp);
							}
							
							if((fp = fopen("/sys/class/power_supply/battery/capacity","r")) != NULL) {
								fgets(buffer,sizeof buffer, fp);
								strcat(header,"batt_capacity=");				
								strcat(header,buffer);				
								memset(buffer, 0, sizeof(buffer));
								fclose(fp);
							}
							
							if((fp = fopen("/sys/class/power_supply/battery/temp","r")) != NULL) {
								fgets(buffer,sizeof buffer, fp);
								strcat(header,"batt_temperature=");				
								strcat(header,buffer);				
								memset(buffer, 0, sizeof(buffer));
								fclose(fp);
							}
							
							// Check for all the counters in the system if the counter has a value on the given active group and ouptut it.
							
							strcat(header,"_GPU_\n");
							
							for(int p = 0; p < uCounterNum; ++p)
							{					
								
								if(p < sReading.nValueCnt)
								{										
									
									strcat(header,psCounters[p].pszName);
									strcat(header,"=");								
									char params[50];
									snprintf(params,50,"%.2f\n",sReading.pfValueBuf[p]);
									strcat(header, params);				
									//memset(buffer, 0, sizeof(buffer));		
								}
							}			
						}
						
								strcpy(samples[startIndex],header);
								printf("%s\n",samples[startIndex]);
								memset(header, 0, sizeof(header));
								
								
								//realloc
								/*if(j == nRows-1)
								{	
									samples = (char **)realloc(samples, (nRows + size) * sizeof(char *));
									
									int s=0;
									nRows = nRows + size;
									for(s=j+1; s<nRows; s++)
										samples[s] = (char *) malloc(numCol * sizeof(char));
								}
								
								++j;
								
								cur_cap = getCap();
								*/
								
								++startIndex;
								//printf("Current start index = %d num of rows = %d \n", startIndex, nRows);
								printf("End_loop %d\n", startIndex);
						}		
				}
				
				//Poll for the counters once a second
				usleep(10000);
				//usleep(1000000);	
		}
					
		// Step 5. Shutdown PVRScopeStats
		PVRScopeDeInitialise(&psData, &psCounters, &sReading);
		
		struct timeval tv_stop;
		gettimeofday(&tv_stop, NULL);
		unsigned long time_in_sec_stop = tv_stop.tv_sec;
		char endTime[1024];
		snprintf(endTime,1024,"%lu\n",time_in_sec_stop);
		
		char elapseTime[1024];
		snprintf(elapseTime,1024,"%lu\n",(time_in_sec_stop - time_in_sec_start)/60);
		
		printf("Save file\n");
		sprintf(saveFile,"/data/local/tmp/stat/sample%d.txt", fileIndex);
		fp_save = fopen(saveFile,"w+");
		
		for(int i = 0; i < nRows; i++)
	    {
			//printf("%s",samples[i]);
			fprintf(fp_save, "%s", samples[i]);
		}
		
		fprintf(fp_save, "%s\n",endTime);
		//fprintf(fp_save, "Use time(min)=%s",elapseTime);
		
		printf("close all file\n");
		fclose(fp_save);
		
		printf("end file\n");
		
		//Clear array memory
		//sample is a heap data structure
		free(samples);
		
		memset(saveFile, 0, sizeof(saveFile));
		memset(prev_total, 0, sizeof(prev_total));
		memset(prev_idle, 0, sizeof(prev_idle));
		memset(csit, 0, sizeof(csit));
		memset(csiu, 0, sizeof(csiu));
		prev_tx = 0;
		prev_rx = 0;
		
		printf("clear file\n");
		
		exit(0);
}
예제 #10
0
파일: write3d.c 프로젝트: bfauser/fricas
int
writeViewport (int thingsToWrite)
{

  int               i, j, k, ii, code, *anIndex;
  LLPoint           *anLLPoint;
  LPoint            *anLPoint;
  viewTriple        *aPt;
  XWindowAttributes vwInfo;
  FILE              *viewDataFile;
  char              viewDirName[80], viewDataFilename[80],
                    viewBitmapFilename[80], viewPixmapFilename[80],
                    command[80];

  XGetWindowAttributes(dsply,viewport->titleWindow,&vwInfo);
  sprintf(viewDirName,"%s%s",filename,".VIEW");
  sprintf(command,"%s%s%s","rm -r ",viewDirName," >  /dev/null 2>&1");
  code = system(command);
  sprintf(command,"%s%s%s","mkdir ",viewDirName," > /dev/null 2>&1");
  system(command);
  if (0) {
    fprintf(stderr,"   Error: Cannot create %s\n",viewDirName);
    return(-1);
  } else {

            /*** Create the data file ***/
    sprintf(viewDataFilename,"%s%s",viewDirName,"/data");
    if ((viewDataFile = fopen(viewDataFilename,"w")) == NULL) {
      fprintf(stderr,"   Error: Cannot create %s\n",viewDataFilename);
      perror("fopen");
      return(-1);
    } else {
              /*** write out the view3DStruct stuff ***/
      fprintf(viewDataFile,"%d\n",viewData.typeOf3D);
      fprintf(viewDataFile,"%g %g %g %g %g %g\n",
              viewData.xmin,viewData.xmax,viewData.ymin,viewData.ymax,
              viewData.zmin,viewData.zmax);
      fprintf(viewDataFile,"%s\n",viewport->title);
      fprintf(viewDataFile,"%g %g %g %g %g %g %g %g\n",viewport->deltaX,
              viewport->deltaY,viewport->scale,
              viewport->scaleX,viewport->scaleY,viewport->scaleZ,
              viewport->theta,viewport->phi);
      fprintf(viewDataFile,"%d %d %d %d\n",vwInfo.x,vwInfo.y,vwInfo.width,
              vwInfo.height);
      fprintf(viewDataFile,"%d %d %d %d %d %d %d\n",viewport->haveControl,
              viewData.style, viewport->axesOn,
              viewport->hueOffset,viewport->numberOfHues,
              viewport->diagonals, viewData.outlineRenderOn);
      fprintf(viewDataFile,"%g %g %g %g\n",viewport->lightVector[0],
              viewport->lightVector[1], viewport->lightVector[2],
              viewport->translucency);
      fprintf(viewDataFile,"%d %g\n",viewData.perspective,
              viewData.eyeDistance);

      /* write out the generalized 3D components */
      fprintf(viewDataFile,"%d\n",viewData.numOfPoints);
      for (i=0; i<viewData.numOfPoints; i++) {
        aPt = refPt3D(viewData,i);
        fprintf(viewDataFile,"%g %g %g %g\n",aPt->x, aPt->y, aPt->z, aPt->c);
      }
      fprintf(viewDataFile,"%d\n",viewData.lllp.numOfComponents);
      anLLPoint = viewData.lllp.llp;
      for (i=0; i<viewData.lllp.numOfComponents; i++,anLLPoint++) {
        fprintf(viewDataFile,"%d %d\n",anLLPoint->prop.closed,
                anLLPoint->prop.solid);
        fprintf(viewDataFile,"%d\n",anLLPoint->numOfLists);
        anLPoint = anLLPoint->lp;
        for (j=0; j<anLLPoint->numOfLists; j++,anLPoint++) {
          fprintf(viewDataFile,"%d %d\n",anLPoint->prop.closed,
                  anLPoint->prop.solid);
          fprintf(viewDataFile,"%d\n",anLPoint->numOfPoints);
          anIndex = anLPoint->indices;
          for (k=0; k<anLPoint->numOfPoints; k++,anIndex++) {
            fprintf(viewDataFile,"%d\n",*anIndex);
          } /* for points in LPoints (k) */
        } /* for LPoints in LLPoints (j) */
      } /* for LLPoints in LLLPoints (i) */
      fclose(viewDataFile);
    }  /* else was able to open file under the given filename */

           /* write out special files */
    for (ii=1; ii<numBits; ii++) {   /* write.h is one-based */
      if (thingsToWrite & (1<<ii)) {
        switch (ii) {
        case Bitmap:
            /*** Create the pixmap (bitmaps need leaf name) ***/
          sprintf(viewBitmapFilename,"%s%s%s",viewDirName,"/","image.bm");
          XGetWindowAttributes(dsply,viewport->viewWindow,&vwInfo);
          code = XWriteBitmapFile(dsply,viewBitmapFilename,
                                  viewport->titleWindow,vwInfo.width,
                                  vwInfo.height+vwInfo.border_width+20,-1,-1);
          break;

        case Pixmap:
            /*** Create the pixmap (bitmaps need leaf name) ***/
          sprintf(viewPixmapFilename,"%s%s%s",viewDirName,"/","image.xpm");
          XGetWindowAttributes(dsply,viewport->viewWindow,&vwInfo);
          write_pixmap_file(dsply,scrn,viewPixmapFilename,
                                   viewport->titleWindow,0,0,vwInfo.width,
                                   vwInfo.height+titleHeight);
          break;

        case Image:
            /*** Create the image (bitmaps need leaf name) ***/
          writeImage = yes;
          sprintf(viewPixmapFilename,"%s%s%s",viewDirName,"/","image.xpm");
          XResizeWindow(dsply,viewport->titleWindow,300,300+titleHeight);
          XResizeWindow(dsply,viewport->viewWindow,300,300);
          viewport->hueTop = totalHues-1;  viewport->hueOffset = 0;
          viewport->numberOfHues = viewport->hueTop - viewport->hueOffset;
          firstTime = 1;
          if (viewData.style == transparent) {
            viewData.style = render;
            viewData.outlineRenderOn = 1;
          } else {
            if (viewData.style == render) viewData.outlineRenderOn = 1;
          }
          drawViewport(Xoption);
          writeTitle();
          XGetWindowAttributes(dsply,viewport->viewWindow,&vwInfo);
          write_pixmap_file(dsply,scrn,viewPixmapFilename,
                                   viewport->titleWindow,0,0,vwInfo.width,
                                   vwInfo.height+titleHeight);
          viewport->monoOn = 1;
          maxGreyShade = XInitShades(dsply,scrn);
          firstTime = 1;
          drawViewport(Xoption);
          writeTitle();
          sprintf(viewBitmapFilename,"%s%s%s",viewDirName,"/","image.bm");
          code = XWriteBitmapFile(dsply,viewBitmapFilename,
                                  viewport->titleWindow,vwInfo.width,
                                  vwInfo.height+vwInfo.border_width+20,-1,-1);

          writeImage = no;
          break;

        case Postscript:
            /*** Create postscript output for viewport (in axiom3D.ps) ***/
         sprintf(PSfilename,"%s%s",viewDirName,"/axiom3D.ps");
         if (PSInit(viewport->viewWindow,viewport->titleWindow) == psError)
           return(-1);
         drawViewport(PSoption);  /* write new script file in /tmp */
         if (PSCreateFile(viewBorderWidth,viewport->viewWindow,
                          viewport->titleWindow, viewport->title) == psError)
           return(-1);  /* concat script & proc into axiom3D.ps */
         break;
        } /* switch on ii */
      }  /* if thingsToWrite >> ii */
    }  /* for ii */

    return(0);
  }    /* else create directory okay */

}
예제 #11
0
파일: main.c 프로젝트: billpage/open-axiom
int
main(int argc, char **argv)
{

   XGCValues    values;

   XEvent       report;
   int          x0=0, y0=0, width=300, height=200, border=3;

   char         *fontname = "6x13";
   XFontStruct  *dsp_font;

   Window       menu;
   char         *str1 = "     Print out the PostScript file?    ",
                *str0 = "Generate a PostScript file (OUTPUT.ps)?";
   int          m_width, m_height, flag=yes;

   /* open display */
   if ((dsply = XOpenDisplay(NULL)) == NULL) {
     printf("Can't open display NULL\n");
     exit(-1);
   }

   scrn = DefaultScreen(dsply);

   /* access font */
   Gdraws_load_font(&dsp_font, fontname);

   values.background = WhitePixel(dsply, scrn);
   values.foreground = BlackPixel(dsply, scrn);

   gc = XCreateGC(dsply, RootWindow(dsply, scrn),
                  (GCForeground | GCBackground), &values);
   PSGlobalInit();      /* must initiate before using G/PS functions */
   PSCreateContext(gc, "gc", psNormalWidth, psButtCap,
                   psMiterJoin, psWhite, psBlack);
   XSetFont(dsply, gc, dsp_font->fid);
   gc1 = XCreateGC(dsply, RootWindow(dsply, scrn),
                   (GCForeground | GCBackground), &values);
   PSCreateContext(gc1, "gc1", psNormalWidth, psButtCap, psMiterJoin,
                   psWhite, psBlack);
   XSetFont(dsply, gc1, dsp_font->fid);

   if (!(viewport = (viewPoints *)malloc(sizeof(viewPoints)))) {
     fprintf(stderr,"Ran out of memory (malloc) trying to create a viewport.\n");
     exit(-1);
   }

   viewport->titleWindow = XCreateSimpleWindow(dsply, RootWindow(dsply,scrn),
                                               x0, y0, width+6,
                                               height+32+height/4, border,
                                               BlackPixel(dsply, scrn),
                                               WhitePixel(dsply, scrn));

   viewport->viewWindow = XCreateSimpleWindow(dsply, viewport->titleWindow,
                                              x0, y0+20, width, height, border,
                                              BlackPixel(dsply, scrn),
                                              WhitePixel(dsply, scrn));

   strcpy(viewport->title, "what is a test title?");

   m_width = width; m_height = height/4;
   menu = XCreateSimpleWindow(dsply, viewport->titleWindow, x0, y0+20+height+6,
                              m_width, m_height, border,
                              BlackPixel(dsply,scrn), WhitePixel(dsply,scrn));

   XSelectInput(dsply, viewport->viewWindow,
                KeyPressMask|ButtonPressMask|ExposureMask);
   XSelectInput(dsply, viewport->titleWindow, KeyPressMask|ExposureMask);
   XSelectInput(dsply, menu, KeyPressMask|ButtonPressMask|ExposureMask);

   XMapWindow(dsply, viewport->viewWindow);
   XMapWindow(dsply, viewport->titleWindow);
   XFlush(dsply);

   while (yes) {
      XNextEvent(dsply, &report);
      switch (report.type) {

         case Expose:
                if (report.xexpose.window==viewport->titleWindow) {
                  if (GDrawImageString(gc, viewport->titleWindow,
                                       20, 15, viewport->title,
                                       strlen(viewport->title),X) == psError)
                    printf("screen draw image string failed.\n");
                  if (Gdraws_data(X) == psError)
                    printf("screen Gdraws_data failed.\n");
                }
                if (report.xexpose.window==viewport->viewWindow) {
                  if (Gdraws_data(X) == psError)
                    printf("screen Gdraws_data failed.\n");
                }
                else if (report.xexpose.window==menu) {
                  if (flag)
                    Gdraws_draw_menu(menu, str0, m_width, m_height);
                  else
                    Gdraws_draw_menu(menu, str1, m_width, m_height);
                }
                break;

         case ButtonPress:
                if (report.xbutton.window==viewport->viewWindow) {
                  XMapWindow(dsply, menu);
                  XFlush(dsply);
                }
                else if (report.xbutton.window==menu && flag) {
                       XUnmapWindow(dsply, menu);
                       if (Gdraws_pressed_yes(m_width, m_height, report.xbutton.x,
                           report.xbutton.y)) {
                         flag=no;
                         XMapWindow(dsply, menu);
                         PSInit(viewport->viewWindow, viewport->titleWindow);
                         if (Gdraws_data(PS) != psError)
                           PSCreateFile(3,viewport->viewWindow,
                                        viewport->titleWindow,viewport->title);
                         else printf("PS Gdraws_data failed.\n");
                       }
                     }
                else if (report.xbutton.window==menu && !flag) {
                       XUnmapWindow(dsply, menu);
                       if (Gdraws_pressed_yes(m_width, m_height, report.xbutton.x,
                           report.xbutton.y))
                         system("print OUTPUT.ps");
                       flag = yes;
                     }
                break;

         case KeyPress:
                if (report.xkey.window==viewport->viewWindow ||
                    report.xkey.window==viewport->titleWindow) {
                  XFreeGC(dsply, gc);
                  XFreeGC(dsply, gc1);
                  XCloseDisplay(dsply);
                  PSClose();
                  exit(1);
                }
                else if (report.xkey.window==menu) XUnmapWindow(dsply, menu);

         default:
                break;
      }
   }
   return 0;
}
예제 #12
0
int
writeViewport(int thingsToWrite)
{

    FILE              *viewDataFile;
    char              viewDirName[80],
                      viewBitmapFilename[80],viewDataFilename[80],command[80];
    int               i,j,k,code,ii;
    pointListStruct   *aList;
    pointStruct       *aPoint;
    XWindowAttributes vwInfo;

    XGetWindowAttributes(dsply,viewport->titleWindow,&vwInfo);
    sprintf(viewDirName,"%s%s",filename,".VIEW");
    sprintf(command,"%s%s%s","rm -r ",viewDirName," >  /dev/null 2>&1");
    code = system(command);
    sprintf(command,"%s%s%s","mkdir ",viewDirName," > /dev/null 2>&1");
    if (system(command)) {
        fprintf(stderr,"   Error: Cannot create %s\n",viewDirName);
        return(-1);
    } else {
        /*** Create the data file ***/
        sprintf(viewDataFilename,"%s%s",viewDirName,"/data");
        if ((viewDataFile = fopen(viewDataFilename,"w")) == NULL) {
            fprintf(stderr,"   Error: Cannot create %s\n",viewDataFilename);
            perror("fopen");
            return(-1);
        } else {
            /*** write out the view2DStruct stuff ***/
            fprintf(viewDataFile,"%d\n",view2DType);
            fprintf(viewDataFile,"%s\n",viewport->title);
            fprintf(viewDataFile,"%d %d %d %d\n",vwInfo.x,vwInfo.y,
                    vwInfo.width,vwInfo.height);
            for (i=0; i<maxGraphs; i++) {
                fprintf(viewDataFile,"%d\n",graphArray[i].key);
                fprintf(viewDataFile,"%g %g\n",
                        graphStateArray[i].scaleX,graphStateArray[i].scaleY);
                fprintf(viewDataFile,"%g %g\n",
                        graphStateArray[i].deltaX,graphStateArray[i].deltaY);
                fprintf(viewDataFile,"%g %g\n",
                        graphStateArray[i].centerX,graphStateArray[i].centerY);
                fprintf(viewDataFile,"%d %d %d %d %d %d %d\n",
                        graphStateArray[i].pointsOn,graphStateArray[i].connectOn,
                        graphStateArray[i].splineOn,
                        graphStateArray[i].axesOn, graphStateArray[i].axesColor,
                        graphStateArray[i].unitsOn, graphStateArray[i].unitsColor);
                fprintf(viewDataFile,"%d %d\n",
                        graphStateArray[i].showing,graphStateArray[i].selected);
            }
            fclose(viewDataFile);
            for (i=0; i<maxGraphs; i++) {
                if (graphArray[i].key) {
                    sprintf(viewDataFilename,"%s%s%d",viewDirName,"/graph",i);
                    if ((viewDataFile = fopen(viewDataFilename,"w")) == NULL) {
                        fprintf(stderr,"   Error: Cannot create %s\n",viewDataFilename);
                        perror("fopen");
                        return(-1);
                    } else {
                        fprintf(viewDataFile,"%g %g %g %g\n",
                                graphArray[i].xmin,graphArray[i].ymin,
                                graphArray[i].xmax,graphArray[i].ymax);
                        fprintf(viewDataFile,"%g %g\n",
                                graphArray[i].xNorm,graphArray[i].yNorm);
                        fprintf(viewDataFile,"%g %g\n",
                                graphArray[i].originX,graphArray[i].originY);
                        fprintf(viewDataFile,"%g %g\n",
                                graphArray[i].spadUnitX,graphArray[i].spadUnitY);
                        fprintf(viewDataFile,"%g %g\n",
                                graphArray[i].unitX,graphArray[i].unitY);
                        fprintf(viewDataFile,"%d\n",graphArray[i].numberOfLists);
                        for (j=0,aList=graphArray[i].listOfListsOfPoints;
                                j<graphArray[i].numberOfLists;
                                j++, aList++) {
                            fprintf(viewDataFile,"%d\n",aList->numberOfPoints);
                            fprintf(viewDataFile,"%d %d %d\n",
                                    aList->pointColor,aList->lineColor,aList->pointSize);
                            for (k=0,aPoint=aList->listOfPoints;
                                    k<aList->numberOfPoints;
                                    k++,aPoint++)
                                fprintf(viewDataFile,"%g %g %g %g\n",
                                        aPoint->x,aPoint->y,aPoint->hue,aPoint->shade);
                        } /* for j, aList */
                        fclose(viewDataFile);
                    } /* else graph i */
                } /* if */
            } /* for */
        } /* else */

        /* write out special files */
        for (ii=1; ii<numBits; ii++) {   /* write.h is one-based */
            if (thingsToWrite & (1<<ii)) {
                switch (ii) {
                case Pixmap:
                    /*** Create the pixmap (bitmaps need leaf name) ***/
                    sprintf(viewBitmapFilename,"%s%s",viewDirName,"/image.xpm");
                    XGetWindowAttributes(dsply,viewport->viewWindow,&vwInfo);
                    write_pixmap_file(dsply,scrn,viewBitmapFilename,
                                      viewport->titleWindow,0,0,vwInfo.width,
                                      vwInfo.height+titleHeight);
                    break;
                case Bitmap:
                    /*** Create the bitmap (bitmaps need leaf name) ***/
                    sprintf(viewBitmapFilename,"%s%s",viewDirName,"/image.bm");
                    XGetWindowAttributes(dsply,viewport->viewWindow,&vwInfo);
                    code = XWriteBitmapFile(dsply,viewBitmapFilename,
                                            viewport->titleWindow,vwInfo.width,
                                            vwInfo.height+vwInfo.border_width+20,-1,-1);
                    break;
                case Image:
                    /*** Create the pixmap (bitmaps need leaf name) ***/
                    sprintf(viewBitmapFilename,"%s%s",viewDirName,"/image.xpm");
                    XResizeWindow(dsply,viewport->titleWindow,300,300+titleHeight);
                    XResizeWindow(dsply,viewport->viewWindow,300,300);
                    XGetWindowAttributes(dsply,viewport->viewWindow,&vwInfo);
                    drawViewport(Xoption);
                    writeTitle();
                    write_pixmap_file(dsply,scrn,viewBitmapFilename,
                                      viewport->titleWindow,0,0,vwInfo.width,
                                      vwInfo.height+titleHeight);
                    /*** Create the bitmap (bitmaps need leaf name) ***/
                    mono = 1;
                    drawViewport(Xoption);
                    writeTitle();
                    sprintf(viewBitmapFilename,"%s%s%s",viewDirName,"/","image.bm");
                    code = XWriteBitmapFile(dsply,viewBitmapFilename,
                                            viewport->titleWindow,vwInfo.width,
                                            vwInfo.height+vwInfo.border_width+20,-1,-1);
                    mono = 0;
                    break;

                case Postscript:
                    /*** Create postscript output for viewport (in axiom2D.ps) ***/
                    sprintf(PSfilename,"%s%s",viewDirName,"/axiom2D.ps");
                    if (PSInit(viewport->viewWindow,viewport->titleWindow) == psError)
                        return (-1);
                    drawViewport(PSoption);  /* write new script file in /tmp */
                    if (PSCreateFile(viewBorderWidth,viewport->viewWindow,
                                     viewport->titleWindow, viewport->title) == psError)
                        return(-1);          /* concat script & proc into axiom2D.ps */
                    break;

                } /* switch on ii */
            }  /* if thingsToWrite >> ii */
        }  /* for ii */

        return(0);
    }    /* else create directory okay */

}