1*11a8fa6cSceastha /* 2*11a8fa6cSceastha * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 3*11a8fa6cSceastha * Use is subject to license terms. 4*11a8fa6cSceastha */ 5*11a8fa6cSceastha 67c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 77c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 87c478bd9Sstevel@tonic-gate 97c478bd9Sstevel@tonic-gate /* 107c478bd9Sstevel@tonic-gate * Copyright (c) 1980 Regents of the University of California. 117c478bd9Sstevel@tonic-gate * All rights reserved. The Berkeley software License Agreement 127c478bd9Sstevel@tonic-gate * specifies the terms and conditions for redistribution. 137c478bd9Sstevel@tonic-gate */ 147c478bd9Sstevel@tonic-gate 157c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 167c478bd9Sstevel@tonic-gate 177c478bd9Sstevel@tonic-gate /* time programs */ 18*11a8fa6cSceastha #include <stdio.h> 19*11a8fa6cSceastha #include <sys/types.h> 207c478bd9Sstevel@tonic-gate 217c478bd9Sstevel@tonic-gate struct tbuffer { 227c478bd9Sstevel@tonic-gate long proc_user_time; 237c478bd9Sstevel@tonic-gate long proc_system_time; 247c478bd9Sstevel@tonic-gate long child_user_time; 257c478bd9Sstevel@tonic-gate long child_system_time; 267c478bd9Sstevel@tonic-gate }; 277c478bd9Sstevel@tonic-gate static long start, user, systm; 28*11a8fa6cSceastha 29*11a8fa6cSceastha void 30*11a8fa6cSceastha tick(void) 317c478bd9Sstevel@tonic-gate { 327c478bd9Sstevel@tonic-gate struct tbuffer tx; 337c478bd9Sstevel@tonic-gate time_t tp; 347c478bd9Sstevel@tonic-gate times(&tx); 357c478bd9Sstevel@tonic-gate time(&tp); 367c478bd9Sstevel@tonic-gate user = tx.proc_user_time; 377c478bd9Sstevel@tonic-gate systm = tx.proc_system_time; 387c478bd9Sstevel@tonic-gate start = tp; 397c478bd9Sstevel@tonic-gate } 40*11a8fa6cSceastha 41*11a8fa6cSceastha void 42*11a8fa6cSceastha tock(void) 437c478bd9Sstevel@tonic-gate { 447c478bd9Sstevel@tonic-gate struct tbuffer tx; 457c478bd9Sstevel@tonic-gate time_t tp; 467c478bd9Sstevel@tonic-gate float lap, use, sys; 47*11a8fa6cSceastha if (start == 0) 48*11a8fa6cSceastha return; 497c478bd9Sstevel@tonic-gate times(&tx); 507c478bd9Sstevel@tonic-gate time(&tp); 517c478bd9Sstevel@tonic-gate lap = (tp - start)/60.; 527c478bd9Sstevel@tonic-gate use = (tx.proc_user_time - user)/60.; 537c478bd9Sstevel@tonic-gate sys = (tx.proc_system_time - systm)/60.; 547c478bd9Sstevel@tonic-gate printf("Elapsed %.2f CPU %.2f (user %.2f, sys %.2f)\n", 557c478bd9Sstevel@tonic-gate lap, use+sys, use, sys); 567c478bd9Sstevel@tonic-gate } 57