From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14621 invoked by alias); 28 Jan 2007 05:31:09 -0000 Received: (qmail 14610 invoked by uid 22791); 28 Jan 2007 05:31:09 -0000 X-Spam-Check-By: sourceware.org Received: from viper.snap.net.nz (HELO viper.snap.net.nz) (202.37.101.8) by sourceware.org (qpsmtpd/0.31) with ESMTP; Sun, 28 Jan 2007 05:31:02 +0000 Received: from kahikatea.snap.net.nz (164.61.255.123.dynamic.snap.net.nz [123.255.61.164]) by viper.snap.net.nz (Postfix) with ESMTP id 3A9E83D8261; Sun, 28 Jan 2007 18:30:56 +1300 (NZDT) Received: by kahikatea.snap.net.nz (Postfix, from userid 500) id 4FB574F71C; Sun, 28 Jan 2007 18:30:53 +1300 (NZDT) From: Nick Roberts MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <17852.13579.802713.886821@kahikatea.snap.net.nz> Date: Sun, 28 Jan 2007 05:31:00 -0000 To: Eli Zaretskii Cc: gdb-patches@sources.redhat.com Subject: Re: [PATCH] MI: new timing command In-Reply-To: References: <17814.10139.269708.848818@kahikatea.snap.net.nz> <17814.58031.865155.682869@kahikatea.snap.net.nz> <20061231042547.GA3236@nevyn.them.org> <17815.18190.987950.612053@kahikatea.snap.net.nz> <20061231054946.GA4873@nevyn.them.org> <17815.27092.497145.908734@kahikatea.snap.net.nz> <20061231151527.GC16449@nevyn.them.org> <200612311524.kBVFObud010411@brahms.sibelius.xs4all.nl> <200612311609.kBVG9Fgh022431@brahms.sibelius.xs4all.nl> <17816.34925.514170.51734@farnswood.snap.net.nz> <17817.34304.221915.628057@kahikatea.snap.net.nz> <17836.26941.915573.399839@kahikatea.snap.net.nz> <17842.33386.836316.276127@kahikatea.snap.net.nz> <17851.52589.491047.323275@kahikatea.snap.net.nz> X-Mailer: VM 7.19 under Emacs 22.0.93.2 X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2007-01/txt/msg00563.txt.bz2 > > Well it was explained to me that get_run_time basically returns wallclock > > time when getrusage isn't defined. > > Not necessarily. Take a look at getruntime.c: it can use `times' when > that is available. `times' returns the sum of user and system times, > not the wallclock time. I don't recollect this point being made earlier but anyway I've tried to make the necessary changes below. -- Nick http://www.inet.net.nz/~nickrob Other changes as before. In particular mi-main.c is a pseudo diff as other previous changes aren't shown. *** mi-parse.h 28 Jan 2007 10:54:38 +1300 1.6 --- mi-parse.h 28 Jan 2007 18:18:46 +1300 *************** *** 24,29 **** --- 24,36 ---- /* MI parser */ + /* Timestamps for current command and last asynchronous command. */ + struct mi_timestamp { + struct timeval wallclock; + struct timeval utime; + struct timeval stime; + }; + enum mi_command_type { MI_COMMAND, CLI_COMMAND *************** struct mi_parse *** 35,40 **** --- 42,48 ---- char *command; char *token; const struct mi_cmd *cmd; + struct mi_timestamp *cmd_start; char *args; char **argv; int argc; *** mi-main.c 23 Jan 2007 20:21:56 +1300 1.91 --- mi-main.c 28 Jan 2007 18:15:17 +1300 *************** _initialize_mi_main (void) *** 1457,1459 **** --- 1517,1565 ---- DEPRECATED_REGISTER_GDBARCH_SWAP (old_regs); deprecated_register_gdbarch_swap (NULL, 0, mi_setup_architecture_data); } + + static void + timestamp (struct mi_timestamp *tv) + { + long usec; + gettimeofday (&tv->wallclock, NULL); + #ifdef HAVE_GETRUSAGE + getrusage (RUSAGE_SELF, &rusage); + tv->utime.tv_sec = rusage.ru_utime.tv_sec; + tv->utime.tv_usec = rusage.ru_utime.tv_usec; + tv->stime.tv_sec = rusage.ru_stime.tv_sec; + tv->stime.tv_usec = rusage.ru_stime.tv_usec; + #else + usec = get_run_time (); + tv->utime.tv_sec = usec/1000000; + tv->utime.tv_usec = usec - 1000000*tv->utime.tv_sec; + tv->stime.tv_sec = 0; + tv->stime.tv_usec = 0; + #endif + } + + static void + print_diff_now (struct mi_timestamp *start) + { + struct mi_timestamp now; + timestamp (&now); + print_diff (start, &now); + } + + static long + timeval_diff (struct timeval start, struct timeval end) + { + return ((end.tv_sec - start.tv_sec) * 1000000) + + (end.tv_usec - start.tv_usec); + } + + static void + print_diff (struct mi_timestamp *start, struct mi_timestamp *end) + { + fprintf_unfiltered + (raw_stdout, + ",time={wallclock=\"%0.5f\",user=\"%0.5f\",system=\"%0.5f\"}", + timeval_diff (start->wallclock, end->wallclock) / 1000000.0, + timeval_diff (start->utime, end->utime) / 1000000.0, + timeval_diff (start->stime, end->stime) / 1000000.0); + }