Update year range in gprofng copyright notices
[binutils-gdb.git] / gprofng / src / PreviewExp.cc
blobe7c10d8a915021e0132a301074fb01e7161f6fd1
1 /* Copyright (C) 2021-2023 Free Software Foundation, Inc.
2 Contributed by Oracle.
4 This file is part of GNU Binutils.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
9 any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, 51 Franklin Street - Fifth Floor, Boston,
19 MA 02110-1301, USA. */
21 #include "config.h"
22 #include <stdio.h>
24 #include "PreviewExp.h"
25 #include "Data_window.h"
26 #include "DbeSession.h"
27 #include "Emsg.h"
28 #include "Print.h"
29 #include "i18n.h"
31 PreviewExp::PreviewExp (): Experiment () { }
33 PreviewExp::~PreviewExp () { }//~PreviewExp
35 Experiment::Exp_status
36 PreviewExp::experiment_open (char *path)
38 // Find experiment directory
39 if ((status = find_expdir (path)) != SUCCESS)
41 size_t len = strlen (path);
42 is_group = ((len > 4) && !strcmp (&path[len - 4], NTXT (".erg")));
43 return status;
45 else
46 is_group = 0;
48 read_log_file ();
49 if (status == FAILURE)
50 return status;
52 if (status == INCOMPLETE && resume_ts != MAX_TIME)
53 // experiment is incomplete and "resumed" (non-paused)
54 // PreviewExp does not process all the packets, therefore...
55 // ... last_event does not reflect reality
56 // ... we don't know the duration or the end.
57 last_event = ZERO_TIME; // mark last_event as uninitialized
59 read_notes_file ();
60 return status;
63 Vector<char*> *
64 PreviewExp::preview_info ()
66 Vector<char*> *info = new Vector<char*>;
67 if (is_group)
68 info->append (GTXT ("Experiment Group"));
69 else
70 info->append (GTXT ("Experiment"));
71 info->append (expt_name);
73 if (status == FAILURE /* != SUCCESS */)
75 if (is_group)
77 Vector<char*> *grp_list = dbeSession->get_group_or_expt (expt_name);
78 for (int i = 0, grp_sz = grp_list->size (); i < grp_sz; i++)
80 char *nm = grp_list->fetch (i);
81 char *str = dbe_sprintf (GTXT ("Exp.#%d"), i + 1);
82 info->append (str);
83 info->append (nm);
85 delete grp_list;
87 else
89 info->append (GTXT ("Error message"));
90 info->append (mqueue_str (errorq, GTXT ("No errors\n")));
92 return info;
94 info->append (GTXT ("Experiment header"));
95 info->append (mqueue_str (commentq, GTXT ("Empty header\n")));
96 info->append (GTXT ("Error message"));
97 info->append (mqueue_str (errorq, GTXT ("No errors\n")));
98 info->append (GTXT ("Warning message"));
99 info->append (mqueue_str (warnq, GTXT ("No warnings\n")));
100 info->append (GTXT ("Notes"));
101 info->append (mqueue_str (notesq, GTXT ("\n")));
102 return info;
105 char *
106 PreviewExp::mqueue_str (Emsgqueue *msgqueue, char *null_str)
108 char *mesgs = pr_mesgs (msgqueue->fetch (), null_str, "");
109 char *last = mesgs + strlen (mesgs) - 1;
110 if (*last == '\n')
111 *last = '\0';
112 return mesgs;