tangled
alpha
login
or
join now
altagos.dev
/
austin-converter
0
fork
atom
this repo has no description
0
fork
atom
overview
issues
pulls
pipelines
colorful logs
altagos.dev
8 months ago
b829759e
79b09f56
verified
This commit was signed with the committer's
known signature
.
altagos.dev
SSH Key Fingerprint:
SHA256:UbTjEcCZlc6GzQWLCuDK3D//HESWD2xFPkzue9XMras=
+64
-12
2 changed files
expand all
collapse all
unified
split
src
austin.zig
main.zig
+20
-12
src/austin.zig
···
1
1
const std = @import("std");
2
2
const mem = std.mem;
3
3
4
4
+
const log = std.log.scoped(.austin);
5
5
+
4
6
pub const Process = struct {
5
7
/// Process ID
6
8
pid: usize,
···
150
152
} else {
151
153
// Sample
152
154
const sample = self.parseSample(line, line_num) catch |err| {
153
153
-
std.log.err("[file:{}] {}", .{ line_num, err });
155
155
+
log.warn("Caught {} while parsing line {}:\n\x1b[90m{} |\x1b[0m {s}{s}", .{
156
156
+
err,
157
157
+
line_num,
158
158
+
line_num,
159
159
+
if (line.items.len <= 80) line.items else line.items[0..80],
160
160
+
if (line.items.len <= 80) "" else " ...",
161
161
+
});
154
162
if (err == ParseError.InvalidSample) continue;
155
163
156
164
std.process.exit(1);
···
189
197
}
190
198
};
191
199
192
192
-
std.log.warn(
193
193
-
\\No metrics found while parsing line {}, returning partial sample
194
194
-
\\{} | {s}{s}
195
195
-
,
200
200
+
log.warn(
201
201
+
"No metrics found while parsing line {}, returning partial sample:\n\x1b[90m{} |\x1b[0m {s}{s}",
196
202
.{
197
203
line_num,
198
204
line_num,
···
227
233
};
228
234
229
235
self.parseFullSample(sample, data_raw, line_num) catch |err| {
230
230
-
std.log.warn(
231
231
-
\\Caught {} while parsing line {}, returning metrics ({}):
232
232
-
\\{} | {s}{s}
233
233
-
,
236
236
+
log.debug(
237
237
+
"Caught {} while parsing line {}, returning metrics " ++
238
238
+
"(time delta: {}, idle state: {}, rss memory delta: {}):\n" ++
239
239
+
"\x1b[90m{} |\x1b[0m {s}{s}",
234
240
.{
235
241
err,
236
242
line_num,
237
237
-
sample.metric,
243
243
+
sample.metric.time_delta,
244
244
+
sample.metric.idle_state,
245
245
+
sample.metric.rss_memory_delta,
238
246
line_num,
239
247
if (line.items.len <= 80) line.items else line.items[0..80],
240
248
if (line.items.len <= 80) "" else " ...",
···
282
290
ParseError.NoFunction,
283
291
ParseError.NoLineNumber,
284
292
=> {
285
285
-
std.log.warn(
286
286
-
"Cought invalid frame while parsing line {}:\n{} | {s}{s}",
293
293
+
log.debug(
294
294
+
"Caught invalid frame while parsing line {}:\n\x1b[90m{} |\x1b[0m {s}{s}",
287
295
.{
288
296
line_num,
289
297
line_num,
+44
src/main.zig
···
3
3
const args = @import("args");
4
4
const austin = @import("austin");
5
5
6
6
+
pub const std_options = std.Options{
7
7
+
.log_level = .debug,
8
8
+
.logFn = logFn,
9
9
+
};
10
10
+
6
11
const Options = struct {
7
12
help: bool = false,
8
13
output: ?[]const u8 = null,
···
73
78
74
79
std.log.info("num samples: {} - meta: {}", .{ profile.samples.len, profile.meta });
75
80
}
81
81
+
82
82
+
pub fn logFn(
83
83
+
comptime message_level: std.log.Level,
84
84
+
comptime scope: @TypeOf(.enum_literal),
85
85
+
comptime format: []const u8,
86
86
+
args_: anytype,
87
87
+
) void {
88
88
+
const prefix = comptime blk: {
89
89
+
const level_text = lt: {
90
90
+
switch (message_level) {
91
91
+
.err => {
92
92
+
break :lt "\x1b[31merror \x1b[0m";
93
93
+
},
94
94
+
.warn => {
95
95
+
break :lt "\x1b[33mwarning\x1b[0m";
96
96
+
},
97
97
+
.info => {
98
98
+
break :lt "\x1b[32minfo \x1b[0m";
99
99
+
},
100
100
+
.debug => {
101
101
+
break :lt "\x1b[34mdebug \x1b[0m";
102
102
+
},
103
103
+
}
104
104
+
};
105
105
+
const scope_prefix = scope: {
106
106
+
if (scope == .default) {
107
107
+
break :scope "";
108
108
+
}
109
109
+
break :scope " \x1b[90m[\x1b[0m" ++ @tagName(scope) ++ "\x1b[90m]\x1b[0m";
110
110
+
};
111
111
+
112
112
+
break :blk level_text ++ scope_prefix ++ "\x1b[90m \x1b[0m";
113
113
+
};
114
114
+
115
115
+
std.debug.lockStdErr();
116
116
+
defer std.debug.unlockStdErr();
117
117
+
const stderr = std.io.getStdErr().writer();
118
118
+
nosuspend stderr.print(prefix ++ format ++ "\x1b[0m\n", args_) catch return;
119
119
+
}