| 1 |
/* sysprof-document-mark.c |
| 2 |
* |
| 3 |
* Copyright 2023 Christian Hergert <[email protected]> |
| 4 |
* |
| 5 |
* This program is free software: you can redistribute it and/or modify |
| 6 |
* it under the terms of the GNU General Public License as published by |
| 7 |
* the Free Software Foundation, either version 3 of the License, or |
| 8 |
* (at your option) any later version. |
| 9 |
* |
| 10 |
* This program is distributed in the hope that it will be useful, |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
* GNU General Public License for more details. |
| 14 |
* |
| 15 |
* You should have received a copy of the GNU General Public License |
| 16 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 |
* |
| 18 |
* SPDX-License-Identifier: GPL-3.0-or-later |
| 19 |
*/ |
| 20 |
|
| 21 |
#include "config.h" |
| 22 |
|
| 23 |
#include <glib/gi18n.h> |
| 24 |
|
| 25 |
#include "sysprof-document-frame-private.h" |
| 26 |
#include "sysprof-document-mark.h" |
| 27 |
#include "sysprof-time-span.h" |
| 28 |
|
| 29 |
struct _SysprofDocumentMark |
| 30 |
{ |
| 31 |
SysprofDocumentFrame parent_instance; |
| 32 |
}; |
| 33 |
|
| 34 |
struct _SysprofDocumentMarkClass |
| 35 |
{ |
| 36 |
SysprofDocumentFrameClass parent_class; |
| 37 |
}; |
| 38 |
|
| 39 |
|
| 40 |
enum { |
| 41 |
PROP_0, |
| 42 |
PROP_DURATION, |
| 43 |
PROP_END_TIME, |
| 44 |
PROP_GROUP, |
| 45 |
PROP_MESSAGE, |
| 46 |
PROP_NAME, |
| 47 |
N_PROPS |
| 48 |
}; |
| 49 |
|
| 50 |
G_DEFINE_FINAL_TYPE (SysprofDocumentMark, sysprof_document_mark, SYSPROF_TYPE_DOCUMENT_FRAME) |
| 51 |
|
| 52 |
static GParamSpec *properties [N_PROPS]; |
| 53 |
|
| 54 |
static char * |
| 55 |
get_time_str (gint64 o) |
| 56 |
{ |
| 57 |
char str[32]; |
| 58 |
|
| 59 |
if (o == 0) |
| 60 |
g_snprintf (str, sizeof str, "%.3lf s", .0); |
| 61 |
else if (o < 1000000) |
| 62 |
g_snprintf (str, sizeof str, "%.3lf μs", o/1000.); |
| 63 |
else if (o < SYSPROF_NSEC_PER_SEC) |
| 64 |
g_snprintf (str, sizeof str, "%.3lf ms", o/1000000.); |
| 65 |
else |
| 66 |
g_snprintf (str, sizeof str, "%.3lf s", o/(double)SYSPROF_NSEC_PER_SEC); |
| 67 |
|
| 68 |
return g_strdup (str); |
| 69 |
} |
| 70 |
|
| 71 |
static char * |
| 72 |
sysprof_document_mark_dup_tooltip (SysprofDocumentFrame *frame) |
| 73 |
{ |
| 74 |
SysprofDocumentMark *self = (SysprofDocumentMark *)frame; |
| 75 |
g_autofree char *duration_string = NULL; |
| 76 |
g_autofree char *time_string = NULL; |
| 77 |
|
| 78 |
g_assert (SYSPROF_IS_DOCUMENT_MARK (self)); |
| 79 |
|
| 80 |
time_string = sysprof_document_frame_dup_time_string (SYSPROF_DOCUMENT_FRAME (self)); |
| 81 |
duration_string = get_time_str (sysprof_document_mark_get_duration (self)); |
| 82 |
|
| 83 |
return g_strdup_printf ("%s (%s): %s / %s: %s", |
| 84 |
time_string, |
| 85 |
duration_string, |
| 86 |
sysprof_document_mark_get_group (self), |
| 87 |
sysprof_document_mark_get_name (self), |
| 88 |
sysprof_document_mark_get_message (self)); |
| 89 |
} |
| 90 |
|
| 91 |
static void |
| 92 |
sysprof_document_mark_get_property (GObject *object, |
| 93 |
guint prop_id, |
| 94 |
GValue *value, |
| 95 |
GParamSpec *pspec) |
| 96 |
{ |
| 97 |
SysprofDocumentMark *self = SYSPROF_DOCUMENT_MARK (object); |
| 98 |
|
| 99 |
switch (prop_id) |
| 100 |
{ |
| 101 |
case PROP_DURATION: |
| 102 |
g_value_set_int64 (value, sysprof_document_mark_get_duration (self)); |
| 103 |
break; |
| 104 |
|
| 105 |
case PROP_END_TIME: |
| 106 |
g_value_set_int64 (value, sysprof_document_mark_get_end_time (self)); |
| 107 |
break; |
| 108 |
|
| 109 |
case PROP_NAME: |
| 110 |
g_value_set_string (value, sysprof_document_mark_get_name (self)); |
| 111 |
break; |
| 112 |
|
| 113 |
case PROP_GROUP: |
| 114 |
g_value_set_string (value, sysprof_document_mark_get_group (self)); |
| 115 |
break; |
| 116 |
|
| 117 |
case PROP_MESSAGE: |
| 118 |
g_value_set_string (value, sysprof_document_mark_get_message (self)); |
| 119 |
break; |
| 120 |
|
| 121 |
default: |
| 122 |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
| 123 |
} |
| 124 |
} |
| 125 |
|
| 126 |
static void |
| 127 |
sysprof_document_mark_class_init (SysprofDocumentMarkClass *klass) |
| 128 |
{ |
| 129 |
GObjectClass *object_class = G_OBJECT_CLASS (klass); |
| 130 |
SysprofDocumentFrameClass *document_frame_class = SYSPROF_DOCUMENT_FRAME_CLASS (klass); |
| 131 |
|
| 132 |
object_class->get_property = sysprof_document_mark_get_property; |
| 133 |
|
| 134 |
document_frame_class->type_name = N_("Mark"); |
| 135 |
document_frame_class->dup_tooltip = sysprof_document_mark_dup_tooltip; |
| 136 |
|
| 137 |
properties [PROP_DURATION] = |
| 138 |
g_param_spec_int64 ("duration", NULL, NULL, |
| 139 |
G_MININT64, G_MAXINT64, 0, |
| 140 |
(G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); |
| 141 |
|
| 142 |
properties [PROP_END_TIME] = |
| 143 |
g_param_spec_int64 ("end-time", NULL, NULL, |
| 144 |
G_MININT64, G_MAXINT64, 0, |
| 145 |
(G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); |
| 146 |
|
| 147 |
properties [PROP_GROUP] = |
| 148 |
g_param_spec_string ("group", NULL, NULL, |
| 149 |
NULL, |
| 150 |
(G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); |
| 151 |
|
| 152 |
properties [PROP_NAME] = |
| 153 |
g_param_spec_string ("name", NULL, NULL, |
| 154 |
NULL, |
| 155 |
(G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); |
| 156 |
|
| 157 |
properties [PROP_MESSAGE] = |
| 158 |
g_param_spec_string ("message", NULL, NULL, |
| 159 |
NULL, |
| 160 |
(G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); |
| 161 |
|
| 162 |
g_object_class_install_properties (object_class, N_PROPS, properties); |
| 163 |
} |
| 164 |
|
| 165 |
static void |
| 166 |
sysprof_document_mark_init (SysprofDocumentMark *self) |
| 167 |
{ |
| 168 |
} |
| 169 |
|
| 170 |
gint64 |
| 171 |
sysprof_document_mark_get_duration (SysprofDocumentMark *self) |
| 172 |
{ |
| 173 |
const SysprofCaptureMark *mark; |
| 174 |
|
| 175 |
g_return_val_if_fail (SYSPROF_IS_DOCUMENT_MARK (self), 0); |
| 176 |
|
| 177 |
mark = SYSPROF_DOCUMENT_FRAME_GET (self, SysprofCaptureMark); |
| 178 |
|
| 179 |
return SYSPROF_DOCUMENT_FRAME_INT64 (self, mark->duration); |
| 180 |
} |
| 181 |
|
| 182 |
const char * |
| 183 |
sysprof_document_mark_get_group (SysprofDocumentMark *self) |
| 184 |
{ |
| 185 |
const SysprofCaptureMark *mark; |
| 186 |
|
| 187 |
g_return_val_if_fail (SYSPROF_IS_DOCUMENT_MARK (self), 0); |
| 188 |
|
| 189 |
mark = SYSPROF_DOCUMENT_FRAME_GET (self, SysprofCaptureMark); |
| 190 |
|
| 191 |
return SYSPROF_DOCUMENT_FRAME_CSTRING (self, mark->group); |
| 192 |
} |
| 193 |
|
| 194 |
const char * |
| 195 |
sysprof_document_mark_get_name (SysprofDocumentMark *self) |
| 196 |
{ |
| 197 |
const SysprofCaptureMark *mark; |
| 198 |
|
| 199 |
g_return_val_if_fail (SYSPROF_IS_DOCUMENT_MARK (self), 0); |
| 200 |
|
| 201 |
mark = SYSPROF_DOCUMENT_FRAME_GET (self, SysprofCaptureMark); |
| 202 |
|
| 203 |
return SYSPROF_DOCUMENT_FRAME_CSTRING (self, mark->name); |
| 204 |
} |
| 205 |
|
| 206 |
const char * |
| 207 |
sysprof_document_mark_get_message (SysprofDocumentMark *self) |
| 208 |
{ |
| 209 |
const SysprofCaptureMark *mark; |
| 210 |
|
| 211 |
g_return_val_if_fail (SYSPROF_IS_DOCUMENT_MARK (self), 0); |
| 212 |
|
| 213 |
mark = SYSPROF_DOCUMENT_FRAME_GET (self, SysprofCaptureMark); |
| 214 |
|
| 215 |
return SYSPROF_DOCUMENT_FRAME_CSTRING (self, mark->message); |
| 216 |
} |
| 217 |
|
| 218 |
gint64 |
| 219 |
sysprof_document_mark_get_end_time (SysprofDocumentMark *self) |
| 220 |
{ |
| 221 |
g_return_val_if_fail (SYSPROF_IS_DOCUMENT_MARK (self), 0); |
| 222 |
|
| 223 |
return sysprof_document_frame_get_time (SYSPROF_DOCUMENT_FRAME (self)) |
| 224 |
+ sysprof_document_mark_get_duration (self); |
| 225 |
} |