printer functions are allowed to print 0 chars
and still count as successful, unsucessfull prints should return -1
This commit is contained in:
@@ -13,7 +13,7 @@ set BINDIR_LINUX=./%BINDIR_RAW%
|
|||||||
|
|
||||||
echo.
|
echo.
|
||||||
echo clang:
|
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%
|
%BINDIR_WIN%\clang_%EXE_WIN%
|
||||||
|
|
||||||
echo.
|
echo.
|
||||||
@@ -21,14 +21,14 @@ echo g++:
|
|||||||
g++ -std=c++17 %SRC% -o %BINDIR_WIN%\g++_%EXE_WIN%
|
g++ -std=c++17 %SRC% -o %BINDIR_WIN%\g++_%EXE_WIN%
|
||||||
%BINDIR_WIN%\g++_%EXE_WIN%
|
%BINDIR_WIN%\g++_%EXE_WIN%
|
||||||
|
|
||||||
echo.
|
REM echo.
|
||||||
echo cl:
|
REM 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
|
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
|
||||||
%BINDIR_WIN%\cl_%EXE_WIN%
|
REM %BINDIR_WIN%\cl_%EXE_WIN%
|
||||||
|
|
||||||
echo.
|
REM echo.
|
||||||
echo bash_clang:
|
REM echo bash_clang:
|
||||||
bash -c "clang -std=c++17 %SRC% -o %BINDIR_LINUX%/bash_clang_%EXE_LINUX% && %BINDIR_LINUX%/bash_clang_%EXE_LINUX%"
|
REM bash -c "clang -std=c++17 %SRC% -o %BINDIR_LINUX%/bash_clang_%EXE_LINUX% && %BINDIR_LINUX%/bash_clang_%EXE_LINUX%"
|
||||||
|
|
||||||
echo.
|
echo.
|
||||||
echo bash_g++:
|
echo bash_g++:
|
||||||
|
|||||||
@@ -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);
|
int move = maybe_special_print(file, format, &pos, arg_list);
|
||||||
if (move == 0) {
|
if (move == 0) {
|
||||||
move = maybe_fprintf(file, format, &pos, arg_list);
|
move = maybe_fprintf(file, format, &pos, arg_list);
|
||||||
if (move == 0) {
|
if (move == -1) {
|
||||||
putchar('%');
|
fputc('%', file);
|
||||||
putchar(c);
|
fputc(c, file);
|
||||||
move = 1;
|
move = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+15
-9
@@ -1,12 +1,13 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#ifdef _PROFILING
|
#ifdef PROFILING
|
||||||
|
|
||||||
# include <stdlib.h>
|
# include <stdlib.h>
|
||||||
# include <stdio.h>
|
# include <stdio.h>
|
||||||
# include <string.h>
|
# include <string.h>
|
||||||
# include <time.h>
|
# include <time.h>
|
||||||
|
# include "./platform.hpp"
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef FTB_WINDOWS
|
||||||
# include <Windows.h>
|
# include <Windows.h>
|
||||||
#else
|
#else
|
||||||
# include <fcntl.h>
|
# include <fcntl.h>
|
||||||
@@ -47,14 +48,14 @@ bool QueryPerformanceCounter(int64_t *performance_count)
|
|||||||
|
|
||||||
|
|
||||||
struct Profiler {
|
struct Profiler {
|
||||||
#ifdef _MSC_VER
|
#ifdef FTB_WINDOWS
|
||||||
LARGE_INTEGER tmp_time;
|
LARGE_INTEGER tmp_time;
|
||||||
#else
|
#else
|
||||||
int64_t tmp_time;
|
int64_t tmp_time;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// same for all threads
|
// same for all threads
|
||||||
inline static char file_template[40] = "\0";
|
inline static char file_template[100] = "\0";
|
||||||
|
|
||||||
// thread local
|
// thread local
|
||||||
inline thread_local static bool is_initialized = false;
|
inline thread_local static bool is_initialized = false;
|
||||||
@@ -73,8 +74,13 @@ struct Profiler {
|
|||||||
tm* tm_i = localtime(&t);
|
tm* tm_i = localtime(&t);
|
||||||
|
|
||||||
// create folder
|
// create folder
|
||||||
#ifdef _MSC_VER
|
#ifdef FTB_WINDOWS
|
||||||
_mkdir("./profiler_reports/");
|
SECURITY_ATTRIBUTES sa;
|
||||||
|
sa.nLength = sizeof(sa);
|
||||||
|
sa.lpSecurityDescriptor = NULL;
|
||||||
|
sa.bInheritHandle = FALSE;
|
||||||
|
CreateDirectoryA("profiler_reports", &sa);
|
||||||
|
// _mkdir("./profiler_reports/");
|
||||||
#else
|
#else
|
||||||
mkdir("./profiler_reports/", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
|
mkdir("./profiler_reports/", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
|
||||||
#endif
|
#endif
|
||||||
@@ -97,7 +103,7 @@ struct Profiler {
|
|||||||
|
|
||||||
// initially write the performance frequency
|
// initially write the performance frequency
|
||||||
QueryPerformanceFrequency(&tmp_time);
|
QueryPerformanceFrequency(&tmp_time);
|
||||||
#ifdef _MSC_VER
|
#ifdef FTB_WINDOWS
|
||||||
fprintf(out_file, "%lld,,,,\n", tmp_time.QuadPart);
|
fprintf(out_file, "%lld,,,,\n", tmp_time.QuadPart);
|
||||||
#else
|
#else
|
||||||
fprintf(out_file, "%ld,,,,\n", tmp_time);
|
fprintf(out_file, "%ld,,,,\n", tmp_time);
|
||||||
@@ -106,7 +112,7 @@ struct Profiler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
QueryPerformanceCounter(&tmp_time);
|
QueryPerformanceCounter(&tmp_time);
|
||||||
#ifdef _MSC_VER
|
#ifdef FTB_WINDOWS
|
||||||
fprintf(out_file, "->,%lld,%s,%s,%d,%s,%s\n",
|
fprintf(out_file, "->,%lld,%s,%s,%d,%s,%s\n",
|
||||||
tmp_time.QuadPart, name, file,
|
tmp_time.QuadPart, name, file,
|
||||||
line, comment1, comment2);
|
line, comment1, comment2);
|
||||||
@@ -120,7 +126,7 @@ struct Profiler {
|
|||||||
~Profiler() {
|
~Profiler() {
|
||||||
call_depth -= 1;
|
call_depth -= 1;
|
||||||
QueryPerformanceCounter(&tmp_time);
|
QueryPerformanceCounter(&tmp_time);
|
||||||
#ifdef _MSC_VER
|
#ifdef FTB_WINDOWS
|
||||||
fprintf(out_file, "<-,%lld,,,,,\n", tmp_time.QuadPart);
|
fprintf(out_file, "<-,%lld,,,,,\n", tmp_time.QuadPart);
|
||||||
#else
|
#else
|
||||||
fprintf(out_file, "<-,%ld,,,,,\n", tmp_time);
|
fprintf(out_file, "<-,%ld,,,,,\n", tmp_time);
|
||||||
|
|||||||
@@ -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))
|
||||||
@@ -75,6 +75,13 @@ auto test_printer() -> void {
|
|||||||
print(" - %{s32,3}\n", -1,200,-300);
|
print(" - %{s32,3}\n", -1,200,-300);
|
||||||
print(" - %{->} <> %{->,2}\n", &u1, &arr, nullptr);
|
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 {
|
auto test_hm() -> void {
|
||||||
@@ -120,7 +127,7 @@ auto test_hm() -> void {
|
|||||||
s32 main(s32 argc, char* argv[]) {
|
s32 main(s32 argc, char* argv[]) {
|
||||||
init_printer();
|
init_printer();
|
||||||
|
|
||||||
test_hm();
|
test_printer();
|
||||||
|
|
||||||
print("done.");
|
print("done.");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user