1 /* Copyright (C) 2021-2023 Free Software Foundation, Inc.
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)
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. */
23 #include "DbeSession.h"
25 #include "IndexObject.h"
26 #include "StringBuilder.h"
28 IndexObject::IndexObject (int _indextype
, uint64_t _index
)
30 indextype
= _indextype
;
37 IndexObject::IndexObject (int _indextype
, Histable
*_obj
)
39 indextype
= _indextype
;
41 id
= obj
? obj
->id
: (uint64_t) - 1;
47 IndexObject::set_name (char * other_name
)
57 extractExpgrid (uint64_t id
)
59 return (id
>> IndexObject::INDXOBJ_EXPGRID_SHIFT
)
60 & IndexObject::INDXOBJ_EXPGRID_MASK
;
64 extractExpid (uint64_t id
)
66 return (id
>> IndexObject::INDXOBJ_EXPID_SHIFT
)
67 & IndexObject::INDXOBJ_EXPID_MASK
;
71 extractPayload (uint64_t id
)
73 return (id
>> IndexObject::INDXOBJ_PAYLOAD_SHIFT
)
74 & IndexObject::INDXOBJ_PAYLOAD_MASK
;
78 printCompareLabel (StringBuilder
*sb
, uint64_t grpId
);
81 printThread (StringBuilder
*sbIn
, Expression::Context
* ctx
, uint64_t id
)
83 uint64_t proc
= extractExpid (id
);
84 uint64_t thrid
= extractPayload (id
);
87 bool javaThread
= false;
90 if (ctx
->dview
&& ctx
->dview
->getProp (PROP_JTHREAD
))
93 uint64_t tstamp
= ctx
->dview
->getLongValue (PROP_TSTAMP
, ctx
->eventId
);
94 JThread
*jthread
= ctx
->exp
->map_pckt_to_Jthread (thrid
, tstamp
);
95 if (jthread
!= JTHREAD_NONE
&& jthread
!= JTHREAD_DEFAULT
)
97 sbIn
->appendf (GTXT ("Process %llu, Thread %llu, JThread %llu \'%s\', Group \'%s\', Parent \'%s\'"),
98 (unsigned long long) proc
,
99 (unsigned long long) thrid
,
100 (unsigned long long) jthread
->jthr_id
,
101 get_str(jthread
->name
, ""),
102 get_str(jthread
->group_name
, ""),
103 get_str(jthread
->parent_name
, ""));
110 sbIn
->appendf (GTXT ("Process %llu, Thread %llu"),
111 (unsigned long long) proc
, (unsigned long long) thrid
);
113 // sometimes threads start as native and later become Java; keep checking
116 if (ctx
&& ctx
->dbev
&& ctx
->dbev
->comparingExperiments ())
118 Vector
<Histable
*> *v
= ctx
->exp
->get_comparable_objs ();
120 for (long i
= 0, sz
= VecSize (v
); i
< sz
; i
++)
122 Experiment
*exp
= (Experiment
*) v
->get (i
);
130 sbIn
->appendf (GTXT (" [ Group %llu Process %llu ]"),
131 (unsigned long long) exp
->groupId
- 1,
132 (unsigned long long) exp
->getUserExpId ());
140 printProcess (StringBuilder
*sbIn
, Expression::Context
* ctx
, uint64_t id
)
146 if (ctx
->dbev
&& ctx
->dbev
->comparingExperiments ())
148 Vector
<Histable
*> *v
= ctx
->exp
->get_comparable_objs ();
149 for (long i
= 0, sz
= VecSize (v
); i
< sz
; i
++)
151 Experiment
*exp
= (Experiment
*) v
->get (i
);
157 sbIn
->appendf (GTXT ("%s, Process %3llu, PID %llu"),
158 get_str (exp
->utargname
, GTXT ("(unknown)")),
159 (unsigned long long) proc
,
160 (unsigned long long) exp
->getPID ());
163 sbIn
->appendf (GTXT (" [ Group %llu, Process %llu, PID %llu ]"),
164 (unsigned long long) exp
->groupId
- 1,
165 (unsigned long long) exp
->getUserExpId (),
166 (unsigned long long) exp
->getPID ());
171 sbIn
->appendf (GTXT ("%s, Process %3llu, PID %llu"),
172 get_str (ctx
->exp
->utargname
, GTXT ("(unknown)")),
173 (unsigned long long) proc
,
174 (unsigned long long) ctx
->exp
->getPID ());
177 sbIn
->appendf (GTXT ("Process %3llu"), (unsigned long long) proc
);
178 return true; //name is final
182 printExperiment (StringBuilder
*sbIn
, Expression::Context
* ctx
, uint64_t id
)
184 uint64_t grpId
= extractExpgrid (id
);
185 uint64_t expid
= extractExpid (id
);
186 if (ctx
&& ctx
->dbev
->comparingExperiments ())
187 printCompareLabel (sbIn
, grpId
);
190 Experiment
*hasFounder
= ctx
->exp
->founder_exp
;
191 int pid
= ctx
->exp
->getPID ();
192 uint64_t founderExpid
;
194 founderExpid
= hasFounder
->getUserExpId ();
196 founderExpid
= expid
;
197 sbIn
->appendf (GTXT ("Base Experiment %llu, Process %llu, PID %llu, %s"),
198 (unsigned long long) founderExpid
,
199 (unsigned long long) expid
,
200 (unsigned long long) pid
,
201 get_str (ctx
->exp
->utargname
, GTXT ("(unknown)")));
204 sbIn
->appendf (GTXT ("Process %llu"), (unsigned long long) expid
);
205 return true; // name is final
209 IndexObject::set_name_from_context (Expression::Context
* ctx
)
212 if (nameIsFinal
&& strstr (name
, GTXT ("(unknown)")) == NULL
)
214 if (ctx
== NULL
|| ctx
->dview
== NULL
|| ctx
->dbev
== NULL
)
220 nameIsFinal
= printThread (&sb
, ctx
, id
);
222 case INDEX_PROCESSES
:
223 nameIsFinal
= printProcess (&sb
, ctx
, id
);
225 case INDEX_EXPERIMENTS
:
226 nameIsFinal
= printExperiment (&sb
, ctx
, id
);
233 name
= sb
.toString ();
237 printCompareLabel (StringBuilder
*sbIn
, uint64_t grpId
)
239 static const char *labels
[] = {"", GTXT ("Baseline"), GTXT ("Comparison")};
243 length
= strlen (labels
[1]);
244 int length2
= strlen (labels
[2]);
245 if (length
< length2
)
247 length
+= 5; // for open/close brace and grpId number and spaces
253 s
= dbe_sprintf ("[%s]", labels
[grpId
]);
255 s
= dbe_sprintf ("[%s-%llu]", labels
[2],
256 (unsigned long long) (grpId
- 1));
258 sbIn
->appendf ("%-*s", length
, get_str (s
, ""));
263 IndexObject::get_name (NameFormat fmt
)
274 printThread (&sb
, NULL
, id
);
278 sb
.sprintf (GTXT ("CPU %llu"), (unsigned long long) id
);
282 sb
.sprintf (GTXT ("Sample %llu"), (unsigned long long) id
);
288 sb
.sprintf (GTXT ("Not in any GCEvent"));
292 sb
.sprintf (GTXT ("GCEvent %llu"), (unsigned long long) id
);
297 sb
.sprintf (GTXT ("Second of execution %llu"), (unsigned long long) id
);
300 case INDEX_PROCESSES
:
301 printProcess (&sb
, NULL
, id
);
304 case INDEX_EXPERIMENTS
:
305 printExperiment (&sb
, NULL
, id
);
313 if (id
% 2 == 1 && id
> 1)
316 if (upper
>= 1099511627776)
318 num1
= upper
/ 1099511627776;
319 sb
.sprintf (GTXT (">= %3llu TB"), (unsigned long long) num1
);
323 // XXXX do nothing, this should not happen
328 if (upper
>= 1099511627776)
330 num1
= upper
/ 1099511627776;
334 sb
.sprintf (GTXT ("%3lluTB < n <= %3lluTB"), (unsigned long long) num2
, (unsigned long long) num1
);
338 sb
.sprintf (GTXT ("256GB < n <= %3lluTB"), (unsigned long long) num1
);
341 else if (upper
>= 1073741824)
343 num1
= upper
/ 1073741824;
347 sb
.sprintf (GTXT ("%3lluGB < n <= %3lluGB"), (unsigned long long) num2
, (unsigned long long) num1
);
351 sb
.sprintf (GTXT ("256MB < n <= %3lluGB"), (unsigned long long) num1
);
354 else if (upper
>= 1048576)
356 num1
= upper
/ 1048576;
360 sb
.sprintf (GTXT ("%3lluMB < n <= %3lluMB"), (unsigned long long) num2
, (unsigned long long) num1
);
364 sb
.sprintf (GTXT ("256KB < n <= %3lluMB"), (unsigned long long) num1
);
367 else if (upper
>= 1024)
373 sb
.sprintf (GTXT ("%3lluKB < n <= %3lluKB"), (unsigned long long) num2
, (unsigned long long) num1
);
377 sb
.sprintf (GTXT (" 256 < n <= %3lluKB"), (unsigned long long) num1
);
386 sb
.sprintf (GTXT (" 1 Byte"));
390 sb
.sprintf (GTXT ("%5llu < n <= %5llu Bytes"), (unsigned long long) num2
, (unsigned long long) num1
);
395 sb
.sprintf (GTXT (" 0 Bytes"));
399 sb
.sprintf (GTXT ("<No Data>"));
409 if (id
> 10000000000000)
411 sb
.sprintf (GTXT ("n > 10000s"));
413 else if (id
> 1000000000000)
415 sb
.sprintf (GTXT ("1000s < n <= 10000s"));
417 else if (id
> 100000000000)
419 sb
.sprintf (GTXT (" 100s < n <= 1000s"));
421 else if (id
> 10000000000)
423 sb
.sprintf (GTXT (" 10s < n <= 100s"));
425 else if (id
> 1000000000)
427 sb
.sprintf (GTXT (" 1s < n <= 10s"));
429 else if (id
> 100000000)
431 sb
.sprintf (GTXT ("100ms < n <= 1s"));
433 else if (id
> 10000000)
435 sb
.sprintf (GTXT (" 10ms < n <= 100ms"));
437 else if (id
> 1000000)
439 sb
.sprintf (GTXT (" 1ms < n <= 10ms"));
441 else if (id
> 100000)
443 sb
.sprintf (GTXT ("100us < n <= 1ms"));
447 sb
.sprintf (GTXT (" 10us < n <= 100us"));
451 sb
.sprintf (GTXT (" 1us < n <= 10us"));
455 sb
.sprintf (GTXT (" 0s < n <= 1us"));
459 sb
.sprintf (GTXT (" 0s"));
463 sb
.sprintf (GTXT ("<No Data>"));
467 // Custom index objects
470 sb
.sprintf (GTXT ("%s from %s"),
471 dbeSession
->getIndexSpaceDescr (indextype
), obj
->get_name (fmt
));
474 IndexObjType_t
*indexObj
= dbeSession
->getIndexSpace (indextype
);
475 if (indexObj
->memObj
)
477 if (strcasecmp (indexObj
->name
, NTXT ("Memory_page_size")) == 0)
480 sb
.append (GTXT ("<Unknown>"));
482 sb
.sprintf (NTXT ("%s 0x%16.16llx (%llu)"), indexObj
->name
,
483 (unsigned long long) id
, (unsigned long long) id
);
485 else if (strcasecmp (indexObj
->name
, NTXT ("Memory_in_home_lgrp")) == 0)
487 if (id
== 0 || id
== 1)
488 sb
.sprintf (NTXT ("%s: %s"), indexObj
->name
,
489 id
== 1 ? GTXT ("True") : GTXT ("False"));
491 sb
.sprintf (NTXT ("%s %s (0x%llx"), indexObj
->name
,
492 GTXT ("<Unknown>"), (unsigned long long) id
);
494 else if (strcasecmp (indexObj
->name
, NTXT ("Memory_lgrp")) == 0)
497 sb
.append (GTXT ("<Unknown>"));
499 sb
.sprintf (NTXT ("%s %llu"), indexObj
->name
, (unsigned long long) id
);
502 sb
.sprintf (NTXT ("%s 0x%16.16llx"), indexObj
->name
, (unsigned long long) id
);
505 sb
.sprintf ("%s 0x%16.16llx (%llu)", indexObj
->name
,
506 (unsigned long long) id
, (unsigned long long) id
);
509 name
= sb
.toString ();
516 IndexObject::requires_string_sort ()
518 if (indextype
== INDEX_PROCESSES
|| indextype
>= INDEX_LAST
)
524 IndexObject::convertto (Histable_type type
, Histable
*ext
)
526 if (type
== INDEXOBJ
)
529 return obj
->convertto (type
, ext
);
533 IndexObjType_t::IndexObjType_t ()
538 index_expr_str
= NULL
;
541 short_description
= NULL
;
542 long_description
= NULL
;
546 IndexObjType_t::~IndexObjType_t ()
550 free (index_expr_str
);
552 free (short_description
);
553 free (long_description
);