Parcourir la source

printer functions are allowed to print 0 chars

and still count as successful, unsucessfull prints should return -1
master
Felix Brendel il y a 5 ans
Parent
révision
1e7df8d578
5 fichiers modifiés avec 109 ajouts et 21 suppressions
  1. +8
    -8
      build.bat
  2. +3
    -3
      print.hpp
  3. +15
    -9
      profiler.hpp
  4. +75
    -0
      report2tracing.py
  5. +8
    -1
      test.cpp

+ 8
- 8
build.bat Voir le fichier

@@ -13,7 +13,7 @@ set BINDIR_LINUX=./%BINDIR_RAW%

echo.
echo clang:
clang -std=c++17 %SRC% -o %BINDIR_WIN%\clang_%EXE_WIN%
clang -g -std=c++17 %SRC% -o %BINDIR_WIN%\clang_%EXE_WIN%
%BINDIR_WIN%\clang_%EXE_WIN%

echo.
@@ -21,14 +21,14 @@ echo g++:
g++ -std=c++17 %SRC% -o %BINDIR_WIN%\g++_%EXE_WIN%
%BINDIR_WIN%\g++_%EXE_WIN%

echo.
echo cl:
cl %SRC% /std:c++latest /nologo /Zi /Fd: %BINDIR_WIN%\cl_%EXE_WIN%.pdb /Fo: %BINDIR_WIN%\ /Fe: %BINDIR_WIN%\cl_%EXE_WIN% /wd4090
%BINDIR_WIN%\cl_%EXE_WIN%
REM echo.
REM echo cl:
REM cl %SRC% /std:c++latest /nologo /Zi /Fd: %BINDIR_WIN%\cl_%EXE_WIN%.pdb /Fo: %BINDIR_WIN%\ /Fe: %BINDIR_WIN%\cl_%EXE_WIN% /wd4090
REM %BINDIR_WIN%\cl_%EXE_WIN%

echo.
echo bash_clang:
bash -c "clang -std=c++17 %SRC% -o %BINDIR_LINUX%/bash_clang_%EXE_LINUX% && %BINDIR_LINUX%/bash_clang_%EXE_LINUX%"
REM echo.
REM echo bash_clang:
REM bash -c "clang -std=c++17 %SRC% -o %BINDIR_LINUX%/bash_clang_%EXE_LINUX% && %BINDIR_LINUX%/bash_clang_%EXE_LINUX%"

echo.
echo bash_g++:


+ 3
- 3
print.hpp Voir le fichier

@@ -303,9 +303,9 @@ int print_va_args_to_file(FILE* file, static_string format, va_list* arg_list) {
int move = maybe_special_print(file, format, &pos, arg_list);
if (move == 0) {
move = maybe_fprintf(file, format, &pos, arg_list);
if (move == 0) {
putchar('%');
putchar(c);
if (move == -1) {
fputc('%', file);
fputc(c, file);
move = 1;
}
}


+ 15
- 9
profiler.hpp Voir le fichier

@@ -1,12 +1,13 @@
#pragma once
#ifdef _PROFILING
#ifdef PROFILING

# include <stdlib.h>
# include <stdio.h>
# include <string.h>
# include <time.h>
# include "./platform.hpp"

#ifdef _MSC_VER
#ifdef FTB_WINDOWS
# include <Windows.h>
#else
# include <fcntl.h>
@@ -47,14 +48,14 @@ bool QueryPerformanceCounter(int64_t *performance_count)


struct Profiler {
#ifdef _MSC_VER
#ifdef FTB_WINDOWS
LARGE_INTEGER tmp_time;
#else
int64_t tmp_time;
#endif

// same for all threads
inline static char file_template[40] = "\0";
inline static char file_template[100] = "\0";

// thread local
inline thread_local static bool is_initialized = false;
@@ -73,8 +74,13 @@ struct Profiler {
tm* tm_i = localtime(&t);

// create folder
#ifdef _MSC_VER
_mkdir("./profiler_reports/");
#ifdef FTB_WINDOWS
SECURITY_ATTRIBUTES sa;
sa.nLength = sizeof(sa);
sa.lpSecurityDescriptor = NULL;
sa.bInheritHandle = FALSE;
CreateDirectoryA("profiler_reports", &sa);
// _mkdir("./profiler_reports/");
#else
mkdir("./profiler_reports/", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
#endif
@@ -97,7 +103,7 @@ struct Profiler {

// initially write the performance frequency
QueryPerformanceFrequency(&tmp_time);
#ifdef _MSC_VER
#ifdef FTB_WINDOWS
fprintf(out_file, "%lld,,,,\n", tmp_time.QuadPart);
#else
fprintf(out_file, "%ld,,,,\n", tmp_time);
@@ -106,7 +112,7 @@ struct Profiler {
}

QueryPerformanceCounter(&tmp_time);
#ifdef _MSC_VER
#ifdef FTB_WINDOWS
fprintf(out_file, "->,%lld,%s,%s,%d,%s,%s\n",
tmp_time.QuadPart, name, file,
line, comment1, comment2);
@@ -120,7 +126,7 @@ struct Profiler {
~Profiler() {
call_depth -= 1;
QueryPerformanceCounter(&tmp_time);
#ifdef _MSC_VER
#ifdef FTB_WINDOWS
fprintf(out_file, "<-,%lld,,,,,\n", tmp_time.QuadPart);
#else
fprintf(out_file, "<-,%ld,,,,,\n", tmp_time);


+ 75
- 0
report2tracing.py Voir le fichier

@@ -0,0 +1,75 @@
#!/usr/bin/python

import json
import csv
import sys
import os

class FancyFloat(float):
def __repr__(self):
return format(Decimal(self), "f")

class JsonRpcEncoder(json.JSONEncoder):
def decimalize(self, val):
if isinstance(val, dict):
return {k:self.decimalize(v) for k,v in val.items()}

if isinstance(val, (list, tuple)):
return type(val)(self.decimalize(v) for v in val)

if isinstance(val, float):
return FancyFloat(val)

return val

def encode(self, val):
return super().encode(self.decimalize(val))

if len(sys.argv) == 1:
sys.exit(1)

trace_events = []
call_stack = []
l = [p for p in os.listdir(sys.argv[1]) if p.endswith(".report")]
if len(l) == 0:
print("No reports are in this folder")
sys.exit(1)

file_name = l[0]
with open(file_name, "r") as in_file:
csv_reader = csv.reader(in_file, delimiter=',')
pf = 1
first_line = True
last_ts = -1;
for line in csv_reader:
if first_line:
pf = float(line[0]) / 1000
first_line = False
continue
if line[0] == "->":
call_stack.append(line)
elif line[0] == "<-":
call = call_stack.pop()
ts = float(call[1])
dur = (float(line[1])-ts)
dict = {
"pid": 1,
"tid": 1,
"ts" : ts,
"dur": dur,
"ph" : "X",
"name": call[2],
"args": {
"file": f"({call[3]}:{call[4]})",
}
}
if call[5]:
dict["args"]["info1"] = call[5]
if call[6]:
dict["args"]["info2"] = call[6]
trace_events.append(dict)
else:
print("invalid syntax")
break
with open(f"{file_name}.json", "w") as out_file:
out_file.write(json.dumps({"traceEvents": trace_events}, indent=4))

+ 8
- 1
test.cpp Voir le fichier

@@ -75,6 +75,13 @@ auto test_printer() -> void {
print(" - %{s32,3}\n", -1,200,-300);
print(" - %{->} <> %{->,2}\n", &u1, &arr, nullptr);

print("%{->char}%{->char}%{->char}",
true ? "general " : "",
false ? "validation " : "",
false ? "performance " : "");

// print("%{->char}%{->char}\n\n", "hallo","");

}

auto test_hm() -> void {
@@ -120,7 +127,7 @@ auto test_hm() -> void {
s32 main(s32 argc, char* argv[]) {
init_printer();

test_hm();
test_printer();

print("done.");



Chargement…
Annuler
Enregistrer