MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / write_logfile

Function write_logfile

examples/main/main.cpp:43–85  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

41
42
43static void write_logfile(
44 const llama_context * ctx, const gpt_params & params, const llama_model * model,
45 const std::vector<llama_token> & input_tokens, const std::string & output,
46 const std::vector<llama_token> & output_tokens
47) {
48 if (params.logdir.empty()) {
49 return;
50 }
51
52 const std::string timestamp = get_sortable_timestamp();
53
54 const bool success = create_directory_with_parents(params.logdir);
55 if (!success) {
56 fprintf(stderr, "%s: warning: failed to create logdir %s, cannot write logfile\n",
57 __func__, params.logdir.c_str());
58 return;
59 }
60
61 const std::string logfile_path = params.logdir + timestamp + ".yml";
62 FILE * logfile = fopen(logfile_path.c_str(), "w");
63
64 if (logfile == NULL) {
65 fprintf(stderr, "%s: failed to open logfile %s\n", __func__, logfile_path.c_str());
66 return;
67 }
68
69 fprintf(logfile, "binary: main\n");
70 char model_desc[128];
71 llama_model_desc(model, model_desc, sizeof(model_desc));
72 dump_non_result_info_yaml(logfile, params, ctx, timestamp, input_tokens, model_desc);
73
74 fprintf(logfile, "\n");
75 fprintf(logfile, "######################\n");
76 fprintf(logfile, "# Generation Results #\n");
77 fprintf(logfile, "######################\n");
78 fprintf(logfile, "\n");
79
80 dump_string_yaml_multiline(logfile, "output", output.c_str());
81 dump_vector_int_yaml(logfile, "output_tokens", output_tokens);
82
83 llama_dump_timing_info_yaml(logfile, ctx);
84 fclose(logfile);
85}
86
87#if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__)) || defined (_WIN32)
88static void sigint_handler(int signo) {

Callers 2

sigint_handlerFunction · 0.70
mainFunction · 0.70

Calls 10

get_sortable_timestampFunction · 0.85
fprintfFunction · 0.85
dump_vector_int_yamlFunction · 0.85
llama_model_descFunction · 0.50
emptyMethod · 0.45
c_strMethod · 0.45

Tested by

no test coverage detected