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. */
25 #include "Exp_Layout.h"
27 Sample::Sample (int num)
31 start_time = end_time = 0;
32 start_label = end_label = NULL;
46 if (validated == false)
55 Sample::validate_usage ()
57 if (prusage == NULL || validated)
61 // Make sure that none of the times are negative, force to zero if so
62 if (prusage->pr_utime < 0)
63 prusage->pr_utime = 0;
64 if (prusage->pr_stime < 0)
65 prusage->pr_stime = 0;
66 if (prusage->pr_ttime < 0)
67 prusage->pr_ttime = 0;
68 if (prusage->pr_tftime < 0)
69 prusage->pr_tftime = 0;
70 if (prusage->pr_dftime < 0)
71 prusage->pr_dftime = 0;
72 if (prusage->pr_kftime < 0)
73 prusage->pr_kftime = 0;
74 if (prusage->pr_ltime < 0)
75 prusage->pr_ltime = 0;
76 if (prusage->pr_slptime < 0)
77 prusage->pr_slptime = 0;
78 if (prusage->pr_wtime < 0)
79 prusage->pr_wtime = 0;
80 if (prusage->pr_stoptime < 0)
81 prusage->pr_stoptime = 0;
82 if (prusage->pr_rtime < 0)
83 prusage->pr_rtime = 0;
85 // Now make sure that the sum of states is >= prusage->pr_rtime
86 hrtime_t sum = prusage->pr_utime + prusage->pr_stime + prusage->pr_ttime
87 + prusage->pr_tftime + prusage->pr_dftime + prusage->pr_kftime
88 + prusage->pr_ltime + prusage->pr_slptime + prusage->pr_wtime
89 + prusage->pr_stoptime;
91 sum = sum - prusage->pr_rtime;
92 if (sum < 0)// increment sleep time to make it match
93 prusage->pr_slptime = prusage->pr_slptime - sum;