Home | History | Annotate | Download | only in common
      1 // Copyright 2016 The SwiftShader Authors. All Rights Reserved.
      2 //
      3 // Licensed under the Apache License, Version 2.0 (the "License");
      4 // you may not use this file except in compliance with the License.
      5 // You may obtain a copy of the License at
      6 //
      7 //    http://www.apache.org/licenses/LICENSE-2.0
      8 //
      9 // Unless required by applicable law or agreed to in writing, software
     10 // distributed under the License is distributed on an "AS IS" BASIS,
     11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     12 // See the License for the specific language governing permissions and
     13 // limitations under the License.
     14 
     15 // debug.cpp: Debugging utilities.
     16 
     17 #include "common/debug.h"
     18 
     19 #ifdef  __ANDROID__
     20 #include <utils/String8.h>
     21 #include <cutils/log.h>
     22 #endif
     23 
     24 #include <stdio.h>
     25 #include <stdarg.h>
     26 
     27 namespace es
     28 {
     29 #ifdef __ANDROID__
     30 	void output(const char *format, va_list vararg)
     31 	{
     32 		ALOGI("%s", android::String8::formatV(format, vararg).string());
     33 	}
     34 #else
     35 	static void output(const char *format, va_list vararg)
     36 	{
     37 		if(false)
     38 		{
     39 			static FILE* file = nullptr;
     40 			if(!file)
     41 			{
     42 				file = fopen(TRACE_OUTPUT_FILE, "w");
     43 			}
     44 
     45 			if(file)
     46 			{
     47 				vfprintf(file, format, vararg);
     48 			}
     49 		}
     50 	}
     51 #endif
     52 
     53 	void trace(const char *format, ...)
     54 	{
     55 		va_list vararg;
     56 		va_start(vararg, format);
     57 		output(format, vararg);
     58 		va_end(vararg);
     59 	}
     60 }
     61