1 /* Copyright (C) 2021 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. */
26 #include "BaseMetric.h"
27 #include "DbeSession.h"
28 #include "Expression.h"
30 int BaseMetric::last_id = 0;
33 BaseMetric::init (Type t)
51 clock_unit = (Presentation_clock_unit) 0;
52 for (int ii = 0; ii < NSUBTYPES; ii++)
53 default_visbits[ii] = VAL_NA;
55 precision = METRIC_HR_PRECISION;
56 flavors = EXCLUSIVE | INCLUSIVE | ATTRIBUTED;
57 value_styles = VAL_TIMEVAL | VAL_PERCENT;
60 BaseMetric::BaseMetric (Type t)
68 case CP_LMS_USER_LOCK:
71 case OMP_MASTER_THREAD:
93 // all of these are floating point, precision = clock profile tick
95 precision = METRIC_SIG_PRECISION;
96 flavors = EXCLUSIVE | INCLUSIVE | ATTRIBUTED;
97 value_styles = VAL_TIMEVAL | VAL_PERCENT;
104 // all of these are floating point, precision = hrtime tick
106 precision = METRIC_HR_PRECISION;
107 flavors = EXCLUSIVE | INCLUSIVE | ATTRIBUTED;
108 value_styles = VAL_TIMEVAL | VAL_PERCENT;
110 case SYNC_WAIT_COUNT:
119 flavors = EXCLUSIVE | INCLUSIVE | ATTRIBUTED;
120 value_styles = VAL_VALUE | VAL_PERCENT;
124 // all of these are integer
127 flavors = EXCLUSIVE | INCLUSIVE | ATTRIBUTED;
128 value_styles = VAL_VALUE | VAL_PERCENT;
131 case HEAP_ALLOC_BYTES:
132 case HEAP_LEAK_BYTES:
135 // all of these are longlong
138 flavors = EXCLUSIVE | INCLUSIVE | ATTRIBUTED;
139 value_styles = VAL_VALUE | VAL_PERCENT;
145 value_styles = VAL_VALUE;
148 valtype = VT_ADDRESS;
151 value_styles = VAL_VALUE;
157 value_styles = VAL_VALUE;
159 case HWCNTR: // We should call the other constructor for hwc metric
166 // Constructor for linked HW counters (base counter)
167 BaseMetric::BaseMetric (Hwcentry *ctr, const char* _aux, const char* _username,
168 int v_styles, BaseMetric* _dependent_bm)
170 hwc_init (ctr, _aux, _aux, _username, v_styles);
171 dependent_bm = _dependent_bm;
174 // Constructor for linked HW counters (derived counter)
176 BaseMetric::BaseMetric (Hwcentry *ctr, const char *_aux, const char *_cmdname,
177 const char *_username, int v_styles)
179 hwc_init (ctr, _aux, _cmdname, _username, v_styles);
183 BaseMetric::hwc_init (Hwcentry *ctr, const char* _aux, const char* _cmdname,
184 const char* _username, int v_styles)
187 aux = dbe_strdup (_aux); // HWC identifier
188 cmd = dbe_strdup (_cmdname); // may differ from _aux for cycles->time hwcs
189 username = dbe_strdup (_username);
190 flavors = EXCLUSIVE | INCLUSIVE | ATTRIBUTED;
191 value_styles = v_styles | VAL_PERCENT;
192 if ((value_styles & (VAL_TIMEVAL | VAL_VALUE)) == VAL_TIMEVAL)
196 if (ABST_MEMSPACE_ENABLED (ctr->memop))
197 flavors |= DATASPACE; // only for ctrs with memop definitions
202 // Constructor for derived metrics
203 BaseMetric::BaseMetric (const char *_cmd, const char *_username,
207 cmd = dbe_strdup (_cmd);
208 username = dbe_strdup (_username);
209 aux = dbe_strdup (_cmd);
211 flavors = EXCLUSIVE | INCLUSIVE | ATTRIBUTED;
212 clock_unit = CUNIT_NULL; // should it be CUNIT_TIME or 0 or something?
214 /* we're not going to process packets for derived metrics */
215 packet_type = (ProfData_type) (-1);
216 value_styles = VAL_VALUE;
222 BaseMetric::BaseMetric (const BaseMetric& m)
226 aux = dbe_strdup (m.aux);
227 cmd = dbe_strdup (m.cmd);
228 username = dbe_strdup (m.username);
230 value_styles = m.value_styles;
232 precision = m.precision;
234 packet_type = m.packet_type;
235 zeroThreshold = m.zeroThreshold;
236 clock_unit = m.clock_unit;
237 for (int ii = 0; ii < NSUBTYPES; ii++)
238 default_visbits[ii] = m.default_visbits[ii];
241 cond_spec = strdup (m.cond_spec);
242 cond = m.cond->copy ();
251 val_spec = strdup (m.val_spec);
252 val = m.val->copy ();
261 expr_spec = strdup (m.expr_spec);
262 expr = m.expr->copy ();
269 legend = dbe_strdup (m.legend);
272 definition = Definition::add_definition (m.definition->def);
273 dependent_bm = m.dependent_bm;
276 BaseMetric::~BaseMetric ()
292 BaseMetric::is_internal ()
294 return (get_value_styles () & VAL_INTERNAL) != 0;
298 BaseMetric::get_default_visbits (SubType subtype)
305 rc = default_visbits[0];
308 rc = default_visbits[1];
317 BaseMetric::set_default_visbits (SubType subtype, int _visbits)
323 default_visbits[0] = _visbits;
326 default_visbits[1] = _visbits;
334 BaseMetric::set_cond_spec (char *_cond_spec)
345 cond = dbeSession->ql_parse (_cond_spec);
348 fprintf (stderr, GTXT ("Invalid expression in metric specification `%s'\n"), _cond_spec);
351 cond_spec = dbe_strdup (_cond_spec);
356 BaseMetric::set_val_spec (char *_val_spec)
367 val = dbeSession->ql_parse (_val_spec);
370 fprintf (stderr, GTXT ("Invalid expression in metric specification `%s'\n"), _val_spec);
373 val_spec = dbe_strdup (_val_spec);
378 BaseMetric::set_expr_spec (char *_expr_spec)
390 expr = dbeSession->ql_parse (_expr_spec);
393 fprintf (stderr, GTXT ("Invalid expression in metric specification `%s'\n"), _expr_spec);
396 expr_spec = dbe_strdup (_expr_spec);
401 BaseMetric::specify_mstate_metric (int st)
404 snprintf (buf, sizeof (buf), NTXT ("MSTATE==%d"), st);
405 specify_prof_metric (buf);
409 BaseMetric::specify_ompstate_metric (int st)
412 snprintf (buf, sizeof (buf), NTXT ("OMPSTATE==%d"), st);
413 specify_prof_metric (buf);
417 BaseMetric::specify_prof_metric (char *_cond_spec)
419 packet_type = DATA_CLOCK;
420 specify_metric (_cond_spec, NTXT ("NTICK_USEC")); // microseconds
424 BaseMetric::specify_metric (char *_cond_spec, char *_val_spec)
426 set_cond_spec (_cond_spec);
427 set_val_spec (_val_spec);
431 BaseMetric::specify ()
436 (1 << OMP_IDLE_STATE) | (1 << OMP_IBAR_STATE) | (1 << OMP_EBAR_STATE) |
437 (1 << OMP_LKWT_STATE) | (1 << OMP_CTWT_STATE) | (1 << OMP_ODWT_STATE) |
438 (1 << OMP_ATWT_STATE) | (1 << OMP_TSKWT_STATE),
440 (1 << OMP_NO_STATE) | (1 << OMP_WORK_STATE) | (1 << OMP_SERL_STATE) |
441 (1 << OMP_RDUC_STATE)
446 packet_type = (ProfData_type) - 1; // illegal value
447 clock_unit = CUNIT_TIME;
451 username = dbe_strdup (GTXT ("Size"));
452 clock_unit = CUNIT_BYTES;
453 cmd = dbe_strdup (NTXT ("size"));
456 username = dbe_strdup (GTXT ("PC Address"));
457 cmd = dbe_strdup (NTXT ("address"));
460 username = dbe_strdup (GTXT ("Name"));
461 cmd = dbe_strdup (NTXT ("name"));
464 username = dbe_strdup (GTXT ("System CPU Time"));
465 specify_mstate_metric (LMS_SYSTEM);
466 cmd = dbe_strdup (NTXT ("system"));
469 username = dbe_strdup (GTXT ("Total CPU Time"));
470 snprintf (buf, sizeof (buf),
471 "(MSTATE==%d)||(MSTATE==%d)||(MSTATE==%d)||(MSTATE==%d)",
472 LMS_USER, LMS_SYSTEM, LMS_TRAP, LMS_LINUX_CPU);
473 specify_prof_metric (buf);
474 cmd = dbe_strdup (NTXT ("totalcpu"));
477 username = dbe_strdup (GTXT ("Total Thread Time"));
478 snprintf (buf, sizeof (buf), NTXT ("(MSTATE!=%d)&&(MSTATE!=%d)"),
479 LMS_KERNEL_CPU, LMS_LINUX_CPU);
480 specify_prof_metric (buf);
481 cmd = dbe_strdup (NTXT ("total"));
484 username = dbe_strdup (GTXT ("Kernel CPU Time"));
485 specify_mstate_metric (LMS_KERNEL_CPU);
486 cmd = dbe_strdup (NTXT ("kcpu"));
488 case OMP_MASTER_THREAD:
489 username = dbe_strdup (GTXT ("Master Thread Time"));
490 specify_prof_metric (NTXT ("LWPID==1"));
491 cmd = dbe_strdup (NTXT ("masterthread"));
494 username = dbe_strdup (GTXT ("User CPU Time"));
495 specify_mstate_metric (LMS_USER);
496 cmd = dbe_strdup (NTXT ("user"));
498 case CP_LMS_WAIT_CPU:
499 username = dbe_strdup (GTXT ("Wait CPU Time"));
500 specify_mstate_metric (LMS_WAIT_CPU);
501 cmd = dbe_strdup (NTXT ("wait"));
503 case CP_LMS_USER_LOCK:
504 username = dbe_strdup (GTXT ("User Lock Time"));
505 specify_mstate_metric (LMS_USER_LOCK);
506 cmd = dbe_strdup (NTXT ("lock"));
509 username = dbe_strdup (GTXT ("Text Page Fault Time"));
510 specify_mstate_metric (LMS_TFAULT);
511 cmd = dbe_strdup (NTXT ("textpfault"));
514 username = dbe_strdup (GTXT ("Data Page Fault Time"));
515 specify_mstate_metric (LMS_DFAULT);
516 cmd = dbe_strdup (NTXT ("datapfault"));
519 username = dbe_strdup (GTXT ("Trap CPU Time"));
520 specify_mstate_metric (LMS_TRAP);
521 cmd = dbe_strdup (NTXT ("trap"));
524 username = dbe_strdup (GTXT ("Kernel Page Fault Time"));
525 specify_mstate_metric (LMS_KFAULT);
526 cmd = dbe_strdup (NTXT ("kernelpfault"));
529 username = dbe_strdup (GTXT ("Sleep Time"));
530 specify_mstate_metric (LMS_SLEEP);
531 cmd = dbe_strdup (NTXT ("sleep"));
534 username = dbe_strdup (GTXT ("Stopped Time"));
535 specify_mstate_metric (LMS_STOPPED);
536 cmd = dbe_strdup (NTXT ("stop"));
539 username = dbe_strdup (GTXT ("OpenMP Overhead Time"));
540 specify_ompstate_metric (OMP_OVHD_STATE);
541 cmd = dbe_strdup (NTXT ("ompovhd"));
544 username = dbe_strdup (GTXT ("OpenMP Work Time"));
545 snprintf (buf, sizeof (buf),
546 NTXT ("(OMPSTATE>=0) && (MSTATE==%d) && ((1<<OMPSTATE) & %d)"),
547 LMS_USER, LMS_USER_BITS);
548 specify_prof_metric (buf);
549 cmd = dbe_strdup (NTXT ("ompwork"));
552 username = dbe_strdup (GTXT ("OpenMP Wait Time"));
553 snprintf (buf, sizeof (buf),
554 "OMPSTATE>=0 && ((1<<OMPSTATE) & ((MSTATE!=%d) ? %d : %d))",
555 LMS_USER, (LMS_USER_BITS | IDLE_STATE_BITS), IDLE_STATE_BITS);
556 specify_prof_metric (buf);
557 cmd = dbe_strdup (NTXT ("ompwait"));
560 username = dbe_strdup (GTXT ("OpenMP Implicit Barrier Time"));
561 specify_ompstate_metric (OMP_IBAR_STATE);
562 cmd = dbe_strdup (NTXT ("ompibar"));
565 username = dbe_strdup (GTXT ("OpenMP Explicit Barrier Time"));
566 specify_ompstate_metric (OMP_EBAR_STATE);
567 cmd = dbe_strdup (NTXT ("ompebar"));
570 username = dbe_strdup (GTXT ("OpenMP Serial Time"));
571 specify_ompstate_metric (OMP_SERL_STATE);
572 cmd = dbe_strdup (NTXT ("ompserl"));
575 username = dbe_strdup (GTXT ("OpenMP Reduction Time"));
576 specify_ompstate_metric (OMP_RDUC_STATE);
577 cmd = dbe_strdup (NTXT ("omprduc"));
580 username = dbe_strdup (GTXT ("OpenMP Lock Wait Time"));
581 specify_ompstate_metric (OMP_LKWT_STATE);
582 cmd = dbe_strdup (NTXT ("omplkwt"));
585 username = dbe_strdup (GTXT ("OpenMP Critical Section Wait Time"));
586 specify_ompstate_metric (OMP_CTWT_STATE);
587 cmd = dbe_strdup (NTXT ("ompctwt"));
590 username = dbe_strdup (GTXT ("OpenMP Ordered Section Wait Time"));
591 specify_ompstate_metric (OMP_ODWT_STATE);
592 cmd = dbe_strdup (NTXT ("ompodwt"));
595 packet_type = DATA_SYNCH;
596 username = dbe_strdup (GTXT ("Sync Wait Time"));
597 snprintf (buf, sizeof (buf), NTXT ("(EVT_TIME)/%lld"),
598 (long long) (NANOSEC / METRIC_HR_PRECISION));
599 specify_metric (NULL, buf);
600 cmd = dbe_strdup (NTXT ("sync"));
602 case SYNC_WAIT_COUNT:
603 packet_type = DATA_SYNCH;
604 username = dbe_strdup (GTXT ("Sync Wait Count"));
605 specify_metric (NULL, NTXT ("1"));
606 cmd = dbe_strdup (NTXT ("syncn"));
609 packet_type = DATA_HEAP;
610 username = dbe_strdup (GTXT ("Allocations"));
611 snprintf (buf, sizeof (buf), NTXT ("(HTYPE!=%d)&&(HTYPE!=%d)&&HVADDR"),
612 FREE_TRACE, MUNMAP_TRACE);
613 specify_metric (buf, NTXT ("1"));
614 cmd = dbe_strdup (NTXT ("heapalloccnt"));
616 case HEAP_ALLOC_BYTES:
617 packet_type = DATA_HEAP;
618 username = dbe_strdup (GTXT ("Bytes Allocated"));
619 snprintf (buf, sizeof (buf), NTXT ("(HTYPE!=%d)&&(HTYPE!=%d)&&HVADDR"),
620 FREE_TRACE, MUNMAP_TRACE);
621 specify_metric (buf, NTXT ("HSIZE"));
622 cmd = dbe_strdup (NTXT ("heapallocbytes"));
625 packet_type = DATA_HEAP;
626 username = dbe_strdup (GTXT ("Leaks"));
627 snprintf (buf, sizeof (buf), "(HTYPE!=%d)&&(HTYPE!=%d)&&HVADDR&&HLEAKED",
628 FREE_TRACE, MUNMAP_TRACE);
629 specify_metric (buf, NTXT ("1"));
630 cmd = dbe_strdup (NTXT ("heapleakcnt"));
632 case HEAP_LEAK_BYTES:
633 packet_type = DATA_HEAP;
634 username = dbe_strdup (GTXT ("Bytes Leaked"));
635 snprintf (buf, sizeof (buf), NTXT ("(HTYPE!=%d)&&(HTYPE!=%d)&&HVADDR"),
636 FREE_TRACE, MUNMAP_TRACE);
637 specify_metric (buf, NTXT ("HLEAKED"));
638 cmd = dbe_strdup (NTXT ("heapleakbytes"));
642 packet_type = DATA_IOTRACE;
643 username = dbe_strdup (GTXT ("Read Count"));
644 snprintf (buf, sizeof (buf), "(IOTYPE==%d)", READ_TRACE);
645 specify_metric (buf, NTXT ("1"));
646 cmd = dbe_strdup (NTXT ("ioreadcnt"));
649 packet_type = DATA_IOTRACE;
650 username = dbe_strdup (GTXT ("Write Count"));
651 snprintf (buf, sizeof (buf), "(IOTYPE==%d)", WRITE_TRACE);
652 specify_metric (buf, NTXT ("1"));
653 cmd = dbe_strdup (NTXT ("iowritecnt"));
656 packet_type = DATA_IOTRACE;
657 username = dbe_strdup (GTXT ("Other I/O Count"));
658 snprintf (buf, sizeof (buf), "(IOTYPE==%d)||(IOTYPE==%d)||(IOTYPE==%d)",
659 OPEN_TRACE, CLOSE_TRACE, OTHERIO_TRACE);
660 specify_metric (buf, NTXT ("1"));
661 cmd = dbe_strdup (NTXT ("ioothercnt"));
664 packet_type = DATA_IOTRACE;
665 username = dbe_strdup (GTXT ("I/O Error Count"));
666 snprintf (buf, sizeof (buf),
667 "(IOTYPE==%d)||(IOTYPE==%d)||(IOTYPE==%d)||(IOTYPE==%d)||(IOTYPE==%d)",
668 READ_TRACE_ERROR, WRITE_TRACE_ERROR, OPEN_TRACE_ERROR,
669 CLOSE_TRACE_ERROR, OTHERIO_TRACE_ERROR);
670 specify_metric (buf, NTXT ("1"));
671 cmd = dbe_strdup (NTXT ("ioerrorcnt"));
674 packet_type = DATA_IOTRACE;
675 username = dbe_strdup (GTXT ("Read Bytes"));
676 snprintf (buf, sizeof (buf), NTXT ("(IOTYPE==%d)&&IONBYTE"),
678 specify_metric (buf, NTXT ("IONBYTE"));
679 cmd = dbe_strdup (NTXT ("ioreadbytes"));
682 packet_type = DATA_IOTRACE;
683 username = dbe_strdup (GTXT ("Write Bytes"));
684 snprintf (buf, sizeof (buf), "(IOTYPE==%d)&&IONBYTE", WRITE_TRACE);
685 specify_metric (buf, NTXT ("IONBYTE"));
686 cmd = dbe_strdup (NTXT ("iowritebytes"));
689 packet_type = DATA_IOTRACE;
690 username = dbe_strdup (GTXT ("Read Time"));
691 snprintf (buf, sizeof (buf), "(IOTYPE==%d)&&EVT_TIME", READ_TRACE);
692 snprintf (buf2, sizeof (buf2), NTXT ("(EVT_TIME)/%lld"),
693 (long long) (NANOSEC / METRIC_HR_PRECISION));
694 specify_metric (buf, buf2);
695 cmd = dbe_strdup (NTXT ("ioreadtime"));
698 packet_type = DATA_IOTRACE;
699 username = dbe_strdup (GTXT ("Write Time"));
700 snprintf (buf, sizeof (buf), NTXT ("(IOTYPE==%d)&&EVT_TIME"),
702 snprintf (buf2, sizeof (buf2), NTXT ("(EVT_TIME)/%lld"),
703 (long long) (NANOSEC / METRIC_HR_PRECISION));
704 specify_metric (buf, buf2);
705 cmd = dbe_strdup (NTXT ("iowritetime"));
708 packet_type = DATA_IOTRACE;
709 username = dbe_strdup (GTXT ("Other I/O Time"));
710 snprintf (buf, sizeof (buf),
711 "(IOTYPE==%d)||(IOTYPE==%d)||(IOTYPE==%d)&&EVT_TIME",
712 OPEN_TRACE, CLOSE_TRACE, OTHERIO_TRACE);
713 snprintf (buf2, sizeof (buf2), NTXT ("(EVT_TIME)/%lld"),
714 (long long) (NANOSEC / METRIC_HR_PRECISION));
715 specify_metric (buf, buf2);
716 cmd = dbe_strdup (NTXT ("ioothertime"));
719 packet_type = DATA_IOTRACE;
720 username = dbe_strdup (GTXT ("I/O Error Time"));
721 snprintf (buf, sizeof (buf),
722 "(IOTYPE==%d)||(IOTYPE==%d)||(IOTYPE==%d)||(IOTYPE==%d)||(IOTYPE==%d)&&EVT_TIME",
723 READ_TRACE_ERROR, WRITE_TRACE_ERROR, OPEN_TRACE_ERROR,
724 CLOSE_TRACE_ERROR, OTHERIO_TRACE_ERROR);
725 snprintf (buf2, sizeof (buf2), NTXT ("(EVT_TIME)/%lld"),
726 (long long) (NANOSEC / METRIC_HR_PRECISION));
727 specify_metric (buf, buf2);
728 cmd = dbe_strdup (NTXT ("ioerrortime"));
731 packet_type = DATA_RACE;
732 username = dbe_strdup (GTXT ("Race Accesses"));
733 specify_metric (NULL, NTXT ("RCNT"));
734 cmd = dbe_strdup (NTXT ("raccess"));
737 packet_type = DATA_DLCK;
738 username = dbe_strdup (GTXT ("Deadlocks"));
739 specify_metric (NULL, NTXT ("1"));
740 cmd = dbe_strdup (NTXT ("deadlocks"));
743 packet_type = DATA_HWC;
744 // username, cmd, and aux set by hwc constructor
745 if (valtype == VT_DOUBLE)
747 if (hw_ctr->timecvt > 0) // CPU cycles
748 specify_metric (NULL, NTXT ("((HWCINT*1000000)/FREQ_MHZ)"));
749 else if (hw_ctr->timecvt < 0)
750 { // reference clock (frequency is -timecvt MHz)
751 snprintf (buf, sizeof (buf), NTXT ("((HWCINT*1000000)/%d)"), -hw_ctr->timecvt);
752 specify_metric (NULL, buf);
754 else // shouldn't happen
755 specify_metric (NULL, NTXT ("0"));
756 // resulting unit: seconds * 1e12
757 precision = 1000000LL * 1000000LL; // Seconds * 1e12
761 specify_metric (NULL, NTXT ("HWCINT"));
770 username = dbe_strdup (GTXT ("****"));
771 fprintf (stderr, "BaseMetric::init Undefined basemetric %s\n",
772 get_basetype_name ());
776 #define CASE_S(x) case x: s = (char *) #x; break
778 BaseMetric::get_basetype_name ()
780 static char buf[128];
784 CASE_S (CP_LMS_SYSTEM);
785 CASE_S (CP_TOTAL_CPU);
787 CASE_S (OMP_MASTER_THREAD);
788 CASE_S (CP_LMS_USER);
789 CASE_S (CP_LMS_WAIT_CPU);
790 CASE_S (CP_LMS_USER_LOCK);
791 CASE_S (CP_LMS_TFAULT);
792 CASE_S (CP_LMS_DFAULT);
793 CASE_S (CP_LMS_TRAP);
794 CASE_S (CP_LMS_KFAULT);
795 CASE_S (CP_LMS_SLEEP);
796 CASE_S (CP_LMS_STOPPED);
811 CASE_S (CP_KERNEL_CPU);
812 CASE_S (SYNC_WAIT_TIME);
813 CASE_S (IO_READ_TIME);
814 CASE_S (IO_WRITE_TIME);
815 CASE_S (IO_OTHER_TIME);
816 CASE_S (IO_ERROR_TIME);
818 CASE_S (SYNC_WAIT_COUNT);
819 CASE_S (HEAP_ALLOC_CNT);
820 CASE_S (HEAP_LEAK_CNT);
821 CASE_S (IO_READ_CNT);
822 CASE_S (IO_WRITE_CNT);
823 CASE_S (IO_OTHER_CNT);
824 CASE_S (IO_ERROR_CNT);
827 CASE_S (HEAP_ALLOC_BYTES);
828 CASE_S (HEAP_LEAK_BYTES);
829 CASE_S (IO_READ_BYTES);
830 CASE_S (IO_WRITE_BYTES);
839 snprintf (buf, sizeof (buf), NTXT ("%s(%d)"), s, type);
840 buf[sizeof (buf) - 1] = 0;
848 char *msg = dbe_sprintf (NTXT ("id=%d %s aux='%s' cmd='%s' user_name='%s' expr_spec='%s'\n"
849 "%*c cond_spec='%s' val_spec='%s'"),
850 id, get_basetype_name (), STR (aux), STR (cmd),
851 STR (username), STR (expr_spec),
852 len, ' ', STR (cond_spec), STR (val_spec));
857 BaseMetric::get_comparable_obj (Histable *obj)
859 if (obj == NULL || expr == NULL)
861 if (strncmp (expr_spec, NTXT ("EXPGRID=="), 9) == 0)
863 int n = atoi (expr_spec + 9);
864 Vector<Histable *> *cmpObjs = obj->get_comparable_objs ();
865 if (cmpObjs && cmpObjs->size () >= n)
866 return cmpObjs->get (n - 1);
872 Definition::Definition (opType _op)
884 Definition::~Definition ()
892 Vector<BaseMetric *> *
893 Definition::get_dependencies ()
895 if (dependencies == NULL)
897 if (arg1 && arg1->bm && arg2 && arg2->bm)
899 dependencies = new Vector<BaseMetric *>(2);
900 arg1->index = dependencies->size ();
901 dependencies->append (arg1->bm);
902 arg2->index = dependencies->size ();
903 dependencies->append (arg2->bm);
911 Definition::get_map ()
918 Definition::add_definition (char *_def)
920 // parse the definition
921 char *op_ptr = strchr (_def, '/');
924 // it's a primitive metric
925 BaseMetric *bm = dbeSession->find_base_reg_metric (_def);
928 Definition *p = new Definition (opPrimitive);
932 return NULL; // BaseMetric is not yet specified
934 Definition *p2 = add_definition (op_ptr + 1);
937 _def = dbe_strdup (_def);
938 op_ptr = strchr (_def, '/');
940 Definition *p1 = add_definition (_def);
944 Definition *p = new Definition (opDivide);
957 Definition::eval (long *indexes, TValue *values)
962 return values[indexes[index]].to_double ();
965 double x2 = arg2->eval (indexes, values);
968 double x1 = arg1->eval (indexes, values);
972 fprintf (stderr, GTXT ("unknown expression\n"));