-
Notifications
You must be signed in to change notification settings - Fork 1
/
switchlog.H
97 lines (67 loc) · 2.16 KB
/
switchlog.H
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
** Copyright 2024 Double Precision, Inc.
** See COPYING for distribution information.
*/
#ifndef switchlog_h
#define switchlog_h
#include <iostream>
#include <fstream>
#include <functional>
#include <filesystem>
#include <vector>
#include <functional>
#include "log.H"
#include "proc_container_statefwd.H"
//! Start logging a runlevel switch
void switchlog_start(const std::string &new_runlevel);
//! Internal function to open a stream for the current switchlog
void switchlog_start();
/*!
Internal function to get the switchlog's current file descriptor.
A non-nullptr indicates that we're logging a runlevel switch.
Overridden in unit tests.
*/
std::ostream *get_current_switchlog();
//! Stop logging a runlevel switch, if we're logging it.
void switchlog_stop();
//! Clean up and purge the switchlog directory
void switchlog_purge(const char *directory,
unsigned ndays,
std::function<void (std::string)> log_error);
//! Create a new switchlog
void switchlog_create(const char *directory, std::ofstream &o);
//! Save the switchlog
void switchlog_save(const char *directory,
std::function<void (std::string)> log_error);
//! Switchlogs returned from switch_enumerate()
struct enumerated_switchlog {
//! Pathname to the switchlog
std::filesystem::path filename;
//! What the switchlog is doing (extracted from the 1st line)
std::string switchname;
//! Timestamp when the log finished
time_t log_end;
};
/*! Enumerate available switchlogs
Returns a sorted list, sorted by the log_end timestamp.
*/
std::vector<enumerated_switchlog> enumerate_switchlogs(const char *directory);
//! Analyzed switchlog
struct analyzed_switchlog {
//! A log entry for a single container
struct container {
//! Container's name
std::string name;
//! This is going to be either STATE_STARTED or STATE_STOPPED
const char *label;
//! How long this container waited to start or stop
elapsed_time waiting;
//! How long it took this container to start or stop
elapsed_time elapsed;
};
//! The analyzed switch log
std::vector<container> log;
};
/*! Analyze a switchlog */
analyzed_switchlog switchlog_analyze(const enumerated_switchlog &log);
#endif