1 /*
 2  * Copyright (c) 2021, Amazon.com, Inc. All rights reserved.
 3  * Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
 4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 5  *
 6  * This code is free software; you can redistribute it and/or modify it
 7  * under the terms of the GNU General Public License version 2 only, as
 8  * published by the Free Software Foundation.
 9  *
10  * This code is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
13  * version 2 for more details (a copy is included in the LICENSE file that
14  * accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License version
17  * 2 along with this work; if not, write to the Free Software Foundation,
18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19  *
20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21  * or visit www.oracle.com if you need additional information or have any
22  * questions.
23  *
24  */
25 
26 #ifndef SHARE_GC_SHENANDOAH_SHENANDOAHLOGFILEOUTPUT_HPP
27 #define SHARE_GC_SHENANDOAH_SHENANDOAHLOGFILEOUTPUT_HPP
28 
29 #include "logging/logFileStreamOutput.hpp"
30 #include "logging/logFileOutput.hpp"
31 #include "utilities/globalDefinitions.hpp"
32 #include "runtime/perfData.inline.hpp"
33 
34 // Log file output to capture Shenandoah GC data.
35 
36 class ShenandoahLogFileOutput : public CHeapObj<mtClass> {
37 private:
38     static const char* const FileOpenMode;
39     static const char* const PidFilenamePlaceholder;
40     static const char* const TimestampFilenamePlaceholder;
41     static const char* const TimestampFormat;
42     static const size_t StartTimeBufferSize = 20;
43     static const size_t PidBufferSize = 21;
44     static char         _pid_str[PidBufferSize];
45     static char         _vm_start_time_str[StartTimeBufferSize];
46 
47     const char* _name;
48     char* _file_name;
49     FILE* _stream;
50 
51     bool _write_error_is_shown;
52 
53     bool parse_options(const char* options, outputStream* errstream);
54     char *make_file_name(const char* file_name, const char* pid_string, const char* timestamp_string);
55 
56     bool flush();
57 
58 public:
59     ShenandoahLogFileOutput(const char *name, jlong vm_start_time);
60     ~ShenandoahLogFileOutput();
61 
62     void initialize(outputStream* errstream);
63 
64     int write_snapshot(PerfLongVariable** regions,
65                        PerfLongVariable* ts,
66                        PerfLongVariable* status,
67                        size_t num_regions,
68                        size_t rs);
69 
70     const char* name() const {
71       return _name;
72     }
73 
74     static const char* const Prefix;
75     static void set_file_name_parameters(jlong start_time);
76 };
77 #endif //SHARE_GC_SHENANDOAH_SHENANDOAHLOGFILEOUTPUT_HPP
78