[Bf-blender-cvs] [bfaedae862d] soc-2020-info-editor: WIP: Make reports show in info editor
Mateusz GrzeliÅski
noreply at git.blender.org
Tue Jun 30 17:24:57 CEST 2020
Commit: bfaedae862d331df55eec2f80a05b7234d603e86
Author: Mateusz Grzeliński
Date: Mon Jun 29 12:36:19 2020 +0200
Branches: soc-2020-info-editor
https://developer.blender.org/rBbfaedae862d331df55eec2f80a05b7234d603e86
WIP: Make reports show in info editor
This is highly experimental implementation of T78214 for GSoC project, it has quite a few problems with memory.
- clog context now stores logs as list
- info editor can show reports from window manager of log context
- logs from clog context are converted to reports
{F8653182}
Maniphest Tasks: T78214
Differential Revision: https://developer.blender.org/D8147
===================================================================
M intern/clog/CLG_log.h
M intern/clog/CMakeLists.txt
M intern/clog/clog.c
M release/scripts/startup/bl_ui/space_info.py
M source/blender/editors/space_info/info_intern.h
M source/blender/editors/space_info/info_report.c
M source/blender/editors/space_info/space_info.c
M source/blender/makesdna/DNA_space_types.h
M source/blender/makesrna/intern/rna_internal.h
M source/blender/makesrna/intern/rna_space.c
M source/blender/makesrna/intern/rna_space_api.c
===================================================================
diff --git a/intern/clog/CLG_log.h b/intern/clog/CLG_log.h
index 7418623755c..749cfb0d42d 100644
--- a/intern/clog/CLG_log.h
+++ b/intern/clog/CLG_log.h
@@ -85,11 +85,21 @@ extern "C" {
# define _CLOG_ATTR_PRINTF_FORMAT(format_param, dots_param)
#endif
+
+/* For printing timestamp. */
+#define __STDC_FORMAT_MACROS
+#include <DNA_windowmanager_types.h>
+#include <inttypes.h>
+
+#include "BLI_blenlib.h"
+#include "DNA_listBase.h"
+
#define STRINGIFY_ARG(x) "" #x
#define STRINGIFY_APPEND(a, b) "" a #b
#define STRINGIFY(x) STRINGIFY_APPEND("", x)
struct CLogContext;
+extern struct CLogContext *g_ctx;
/* Don't typedef enums. */
enum CLG_LogFlag {
@@ -120,6 +130,65 @@ typedef struct CLG_LogRef {
CLG_LogType *type;
} CLG_LogRef;
+/* -------------------------------------------------------------------- */
+/** \name Internal Types
+ * \{ */
+
+typedef struct CLG_IDFilter {
+ struct CLG_IDFilter *next;
+ /** Over alloc. */
+ char match[0];
+} CLG_IDFilter;
+
+typedef struct CLG_LogRecord {
+ /** Link for ListBase */
+ struct CLG_LogRecord *next, *prev;
+ /** track where does the log comes from */
+ CLG_LogType *type;
+ enum CLG_Severity severity;
+ uint64_t timestamp;
+ const char *file;
+ const char *line;
+ const char *function;
+ const char *message;
+} CLG_LogRecord;
+
+typedef struct CLogContext {
+ /** Single linked list of types. */
+ CLG_LogType *types;
+ ListBase log_records;
+
+#ifdef WITH_CLOG_PTHREADS
+ pthread_mutex_t types_lock;
+#endif
+
+ /* exclude, include filters. */
+ CLG_IDFilter *filters[2];
+ bool use_color;
+ bool use_basename;
+ bool use_timestamp;
+
+ /** Borrowed, not owned. */
+ int output;
+ FILE *output_file;
+
+ /** For timer (use_timestamp). */
+ uint64_t timestamp_tick_start;
+
+ /** For new types. */
+ struct {
+ int level;
+ } default_type;
+
+ struct {
+ void (*fatal_fn)(void *file_handle);
+ void (*backtrace_fn)(void *file_handle);
+ } callbacks;
+
+} CLogContext;
+
+/** \} */
+
void CLG_log_str(CLG_LogType *lg,
enum CLG_Severity severity,
const char *file_line,
@@ -132,6 +201,14 @@ void CLG_logf(CLG_LogType *lg,
const char *format,
...) _CLOG_ATTR_NONNULL(1, 3, 4, 5) _CLOG_ATTR_PRINTF_FORMAT(5, 6);
+CLG_LogRecord *clog_log_record_init(CLG_LogType *type,
+ enum CLG_Severity severity,
+ const char *file,
+ const char *line,
+ const char *function,
+ const char *message);
+void clog_log_record_free(CLG_LogRecord *log_record);
+
/* Main initializer and distructor (per session, not logger). */
void CLG_init(void);
void CLG_exit(void);
diff --git a/intern/clog/CMakeLists.txt b/intern/clog/CMakeLists.txt
index 41009642e3f..be06d058082 100644
--- a/intern/clog/CMakeLists.txt
+++ b/intern/clog/CMakeLists.txt
@@ -20,6 +20,9 @@ set(INC
.
../atomic
../guardedalloc
+ ../../source/blender/makesdna
+ ../../source/blender/blenlib
+ ../../source/blender/blenkernel
)
set(INC_SYS
diff --git a/intern/clog/clog.c b/intern/clog/clog.c
index 921ee17a672..dca520e4a67 100644
--- a/intern/clog/clog.c
+++ b/intern/clog/clog.c
@@ -42,14 +42,13 @@
# include <windows.h>
#endif
-/* For printing timestamp. */
-#define __STDC_FORMAT_MACROS
-#include <inttypes.h>
-
/* Only other dependency (could use regular malloc too). */
#include "MEM_guardedalloc.h"
/* own include. */
+#include "../../source/blender/blenkernel/BKE_report.h"
+#include "../../source/blender/blenlib/BLI_blenlib.h"
+#include "../../source/blender/makesdna/DNA_listBase.h"
#include "CLG_log.h"
/* Local utility defines */
@@ -62,49 +61,6 @@
# define PATHSEP_CHAR '/'
#endif
-/* -------------------------------------------------------------------- */
-/** \name Internal Types
- * \{ */
-
-typedef struct CLG_IDFilter {
- struct CLG_IDFilter *next;
- /** Over alloc. */
- char match[0];
-} CLG_IDFilter;
-
-typedef struct CLogContext {
- /** Single linked list of types. */
- CLG_LogType *types;
-#ifdef WITH_CLOG_PTHREADS
- pthread_mutex_t types_lock;
-#endif
-
- /* exclude, include filters. */
- CLG_IDFilter *filters[2];
- bool use_color;
- bool use_basename;
- bool use_timestamp;
-
- /** Borrowed, not owned. */
- int output;
- FILE *output_file;
-
- /** For timer (use_timestamp). */
- uint64_t timestamp_tick_start;
-
- /** For new types. */
- struct {
- int level;
- } default_type;
-
- struct {
- void (*fatal_fn)(void *file_handle);
- void (*backtrace_fn)(void *file_handle);
- } callbacks;
-} CLogContext;
-
-/** \} */
-
/* -------------------------------------------------------------------- */
/** \name Mini Buffer Functionality
*
@@ -376,6 +332,42 @@ static uint64_t clg_timestamp_ticks_get(void)
return tick;
}
+CLG_LogRecord *clog_log_record_init(CLG_LogType *type,
+ enum CLG_Severity severity,
+ const char *file,
+ const char *line,
+ const char *function,
+ const char *message)
+{
+ CLG_LogRecord *log_record = MEM_callocN(sizeof(CLG_LogRecord), "ClogRecord"); // MEM_mallocN
+ log_record->next = NULL;
+ log_record->prev = NULL;
+ log_record->type = type;
+ log_record->severity = severity;
+ log_record->timestamp = clg_timestamp_ticks_get() - type->ctx->timestamp_tick_start;
+ log_record->file = file;
+ log_record->line = line;
+ log_record->function = function;
+ log_record->message = message;
+ return log_record;
+}
+
+void clog_log_record_free(CLG_LogRecord *log_record)
+{
+ MEM_freeN(log_record);
+}
+
+void clog_timestamp_to_char()
+{
+ const uint64_t timestamp = 0; // clg_timestamp_ticks_get() - type->ctx->timestamp_tick_start;
+ char timestamp_str[64];
+ const uint timestamp_len = snprintf(timestamp_str,
+ sizeof(timestamp_str),
+ "%" PRIu64 ".%03u ",
+ timestamp / 1000,
+ (uint)(timestamp % 1000));
+}
+
/** \} */
/* -------------------------------------------------------------------- */
@@ -484,6 +476,19 @@ void CLG_logf(CLG_LogType *lg,
const char *fmt,
...)
{
+ CLG_LogRecord *log_record = clog_log_record_init(lg, severity, file_line, file_line, fn, fmt);
+
+ BLI_addtail(&(lg->ctx->log_records), log_record);
+
+ // CLG_LogRecord *log = NULL, *log_iter = NULL;
+ // printf("Dump all log records:\n");
+ // log = lg->ctx->log_records.first;
+ // while (log) {
+ // log_iter = log->next;
+ // printf(" id: %s, %s\n", log->type->identifier, log->message);
+ // log = log_iter;
+ // }
+
CLogStringBuf cstr;
char cstr_stack_buf[CLOG_BUF_LEN_INIT];
clg_str_init(&cstr, cstr_stack_buf, sizeof(cstr_stack_buf));
@@ -597,12 +602,14 @@ static void CLG_ctx_level_set(CLogContext *ctx, int level)
static CLogContext *CLG_ctx_init(void)
{
- CLogContext *ctx = MEM_callocN(sizeof(*ctx), __func__);
+ CLogContext *ctx = MEM_callocN(sizeof(CLogContext), __func__);
#ifdef WITH_CLOG_PTHREADS
pthread_mutex_init(&ctx->types_lock, NULL);
#endif
ctx->use_color = true;
ctx->default_type.level = 1;
+ ctx->log_records.first = NULL;
+ ctx->log_records.last = NULL;
CLG_ctx_output_set(ctx, stdout);
return ctx;
@@ -610,6 +617,13 @@ static CLogContext *CLG_ctx_init(void)
static void CLG_ctx_free(CLogContext *ctx)
{
+ CLG_LogRecord *log = ctx->log_records.first, *log_next=NULL;
+ while (log) {
+ log_next = log->next;
+ clog_log_record_free(log);
+ log = log_next;
+ }
+
while (ctx->types != NULL) {
CLG_LogType *item = ctx->types;
ctx->types = item->next;
@@ -638,7 +652,7 @@ static void CLG_ctx_free(CLogContext *ctx)
* \{ */
/* We could support multiple at once, for now this seems not needed. */
-static struct CLogContext *g_ctx = NULL;
+struct CLogContext *g_ctx = NULL;
void CLG_init(void)
{
diff --git a/release/scripts/startup/bl_ui/space_info.py b/release/scripts/startup/bl_ui/space_info.py
index cd65980fc0d..7e369b370f1 100644
--- a/release/scripts/startup/bl_ui/space_info.py
+++ b/release/scripts/startup/bl_ui/space_info.py
@@ -34,11 +34,16 @@ class INFO_MT_editor_menus(Menu):
bl_idname = "INFO_MT_editor_menus"
bl_label = ""
- def draw(self, _context):
+ def draw(self, context):
layout = self.layout
layout.menu("INFO_MT_view")
layout.menu("INFO_MT_info")
+ sinfo = context.space_data
+ row = layout.row(align=True)
+ row.prop(sinfo, "view", expand=True)
+ # row.prop(sinfo, "view")
+
class INFO_MT_view(Menu):
bl_label = "View"
diff --git a/source/blender/editors/space_info/info_intern.h b/source/blender/editors/space_info/info_intern.h
index 79bfb1fa047..4470c19c317 100644
--- a/source/blender/editors/space_info/info_intern.h
+++ b/source/blender/editors/space_info/info_intern.h
@@ -24,6 +24,8 @@
#ifndef __INFO_INTERN_H__
#define __INFO_INTERN_H__
+#include "DNA_windowmanager_types.h"
+
/* internal exports only */
struct ReportList;
@@ -57,6 +59,7 @@ void info_textview_main(const struct SpaceInfo *sinfo,
const struct ReportList *reports);
/* info_report.c */
+ReportList *clog_to_report_list(void);
int info_report_mask(const struct SpaceInfo *sinfo);
void INFO_OT_select_pick(struct wmOperatorType *ot); /* report selection */
void INFO_OT_select_all(struct wmOperatorType *ot);
diff --git a/source/blender/editors/space_info/info_report.c b/source/blender/editors/space_info/info_report.c
index adc6391a0f6..11f8b0169a8 100644
--- a/source/blender/editors/space_info/info_report.c
+++ b/source/blender/editors/space_info/info_report.c
@@ -18,6 +18,8 @@
* \ingroup spinfo
*/
+#include <BKE_report.h>
+#include <assert.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>
@@ -39,6 +41,7 @@
#include "RNA_access.h"
#include "RNA_define.h"
+#include "../.
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list