File: globus_utp_main.c

package info (click to toggle)
globus-xio 6.2-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 8,128 kB
  • sloc: ansic: 46,711; sh: 11,139; perl: 1,598; makefile: 289
file content (756 lines) | stat: -rw-r--r-- 18,407 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
/*
 * Copyright 1999-2006 University of Chicago
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**********************************************************************
globus_utp_main.c

Public functions for the Unnamed Timing Package (UTP).
**********************************************************************/



#include "globus_common.h"

#ifndef _WIN32
#include <pwd.h>
#endif
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <sys/param.h>
#include <sys/types.h>

#ifdef SOLHR
#include <netdb.h>
#endif


#include "globus_utp.h"
#include "globus_utp_private.h"

/******************************************************************************
			  Module activation structure
******************************************************************************/
static int
globus_l_utp_activate(void);

static int
globus_l_utp_deactivate(void);


globus_module_descriptor_t		globus_i_utp_module =
{
    "globus_utp",
    globus_l_utp_activate,
    globus_l_utp_deactivate,
    GLOBUS_NULL
};


/******************************************************************************
		   globus_utp module activation functions
******************************************************************************/

static int
globus_l_utp_activate(void)
{
    if (globus_module_activate(GLOBUS_COMMON_MODULE) != GLOBUS_SUCCESS)
    {
	return GLOBUS_FAILURE;
    }

    /* Initialize some global variables */
    globus_utp_attributes = GLOBUS_NULL;
    globus_utp_numTimers = 0;
    globus_utp_timers = GLOBUS_NULL;
    
    return GLOBUS_SUCCESS;
}


static int
globus_l_utp_deactivate(void)
{
    int rc;
    unsigned i;
    globus_utp_Attribute_t *curAttr;
    globus_utp_Attribute_t *tmpAttr;

    rc = GLOBUS_SUCCESS;
    
    /*
     * Free up any storage
     */
    curAttr = globus_utp_attributes;
    while (curAttr)
    {

	tmpAttr = curAttr;
	curAttr = curAttr->next;
	globus_free(tmpAttr);
    }
    globus_utp_attributes = GLOBUS_NULL;

    for (i = 0; i < globus_utp_numTimers; i++)
    {
	if (globus_utp_timers[i].name)
	{
	    globus_free(globus_utp_timers[i].name);
	}
    }
    globus_free(globus_utp_timers);
    globus_utp_numTimers = 0;
    globus_utp_timers = GLOBUS_NULL;

    /*
     * Deactivate globus_common
     */
    if (globus_module_deactivate(GLOBUS_COMMON_MODULE) != GLOBUS_SUCCESS)
    {
	rc = GLOBUS_FAILURE;
    }

    return rc;
    
}


/**********************************************************************
Public UTP functions.
**********************************************************************/

int globus_utp_init(unsigned numTimers, int mode)
{
	unsigned i;
	int sharingMode = mode & GLOBUS_UTP_MODE_SHARING_FIELD;
	char hostnameBuff[MAXHOSTNAMELEN];
	time_t theTime;
        const char *username;
	char theTimeStr[27];

	if (sharingMode == GLOBUS_UTP_MODE_PRIVATE)
	{
	    globus_utp_warn("globus_utp_init: mode GLOBUS_UTP_MODE_PRIVATE not yet "
			    "implemented");
	    return 1;
	} else if (sharingMode != GLOBUS_UTP_MODE_SHARED)
	{
	    globus_utp_warn("globus_utp_init: invalid sharing mode %#X specified",
			    sharingMode);
	    return 1;
	}

	if (!(globus_utp_timers = globus_malloc(numTimers * sizeof(globus_utp_Timer_t))))
	{
		globus_utp_warn("globus_utp_init: globus_malloc() failed for timers");
		globus_utp_numTimers = 0;
		return 1;
	}

	globus_utp_numTimers = numTimers;

				/* This loop not only initializes every
				   field; by "touching" everything, it also
				   makes sure it is paged in. */
	for (i = 0; i < numTimers; i++) {
		globus_utp_timers[i].state = GLOBUS_UTP_TIMER_STOPPED;
		globus_utp_timeZero(&globus_utp_timers[i].startTime);
		globus_utp_timeZero(&globus_utp_timers[i].accumulatedTime);
		globus_utp_timers[i].numEvents = 0;
				/* If name is still NULL when
				   globus_utp_write_file() is called,
				   globus_utp_DEFAULT_TIMER_NAME is printed. */
		globus_utp_timers[i].name = NULL;
	}

				/* Make key/value linked list empty. */
	globus_utp_attributes = NULL;

				/* Set attributes for "user", "hostname",
				   and "timestamp". */

#       ifdef _WIN32
        {
            username = getenv("USERNAME");
            if (username == NULL)
            {
                username = "globus";
            }
        }
#       else
        {
            struct passwd *passwdEntry;
            passwdEntry = getpwuid(getuid());
            if (!passwdEntry) {
		return 1;
            }
            username = passwdEntry->pw_name;
        }
	globus_utp_set_attribute("%s", "user", username);
#endif

	if (globus_libc_gethostname(hostnameBuff, MAXHOSTNAMELEN)) {
	    /* globus_utp_warn("globus_utp_init: gethostname() failed; system error is "
		         "\"%s\"", sys_errlist[errno]); */
		return 1;
	}
	globus_utp_set_attribute("%s", "hostname", hostnameBuff);

	if ((theTime = time(NULL)) == (time_t) -1) {
	    /* globus_utp_warn("globus_utp_init: time(3) failed; system error is "
		         "\"%s\"", sys_errlist[errno]); */
		return 1;
	}
	strcpy(theTimeStr, ctime(&theTime));
				/* Remove trailing '\n'. */
	theTimeStr[strlen(theTimeStr) - 1] = 0;
	globus_utp_set_attribute("%s", "timestamp", theTimeStr);

	return 0;
}

void
globus_utp_write_file(const char *outFilename)
{
    FILE *outFile;
    unsigned i;
    char buff[100];
    globus_utp_Attribute_t *curAttr;

    if (!(outFile = fopen(outFilename, "w")))
    {
	/* globus_utp_warn("globus_utp_write_file: fopen() on file \"%s\" failed",
			outFilename);
	globus_utp_warn("globus_utp_write_file: system error message is \"%s\"",
			sys_errlist[errno]); */
	return;
    }

    curAttr = globus_utp_attributes;
    while (curAttr)
    {
	globus_utp_Attribute_t *tmp = curAttr;
	fprintf(outFile, "attribute\t\"%s\"\t\"%s\"\n",
		curAttr->key, curAttr->value);
	curAttr = curAttr->next;
	globus_free(tmp->key);
	globus_free(tmp->value);
	globus_free(tmp);
    }
    globus_utp_attributes = NULL;

    for (i = 0; i < globus_utp_numTimers; i++)
    {
	const char *name = globus_utp_timers[i].name;
	    
	if (globus_utp_timers[i].state == GLOBUS_UTP_TIMER_RUNNING)
	{
	    globus_utp_warn("globus_utp_write_file: timer %d still running",
			    i);
	    globus_utp_stop_timer(i);
	}

	globus_utp_timeToString(buff,
				&globus_utp_timers[i].accumulatedTime);

	fprintf(outFile, "timer\t%u\t%s\t%lu\t\"%s\"\n",
		(unsigned) i,
		buff,
		globus_utp_timers[i].numEvents,
		name ? name : GLOBUS_UTP_DEFAULT_TIMER_NAME);
    }

    if (fclose(outFile))
    {
	/* globus_utp_warn("globus_utp_write_file: fclose() on file \"%s\" failed",
			outFilename);
	globus_utp_warn("globus_utp_write_file: system error message is \"%s\"",
			sys_errlist[errno]); */
	return;
    }
}

void
globus_utp_set_attribute(const char *keyStr, const char *keyArg,
		  const char *valueStr, ...)
{
	globus_utp_Attribute_t *newAttr;	/* New key/value pair. */
	globus_utp_Attribute_t **lastNext;	/* Final "next" pointer in list. */
	char *newKey = globus_malloc(sizeof(char) * GLOBUS_UTP_MAX_NAME_LENGTH);
	char *newValue = globus_malloc(sizeof(char) * GLOBUS_UTP_MAX_NAME_LENGTH);
	va_list ap;

	if (!newKey || !newValue) {
		globus_utp_warn("globus_utp_set_attribute: globus_malloc() failed");
		return;
	}
	sprintf(newKey, keyStr, keyArg);	/* Compute new key. */
	va_start(ap, valueStr);			/* Compute new value. */
	vsprintf(newValue, valueStr, ap);

	newAttr = globus_utp_attributes;
	lastNext = &globus_utp_attributes;
					/* Search for same key in list. */
	while (newAttr && strcmp(newAttr->key, newKey) != 0) {
		lastNext = &newAttr->next;
		newAttr = newAttr->next;
	}

	if (newAttr) {			/* Key already exists in list. */
					/* Just replace the old value. */
		strcpy(newAttr->value, newValue);
		globus_free(newKey);
		globus_free(newValue);
		return;
	}

				/* Add new key/value pair to list. */
	*lastNext = newAttr = globus_malloc(sizeof(globus_utp_Attribute_t));
	if (!newAttr) {
		globus_utp_warn("globus_utp_set_attribute: globus_malloc() failed");
		return;
	}
	newAttr->key = newKey;
	newAttr->value = newValue;
	newAttr->next = NULL;
}


/**********************************************************************
Timer state transition diagram.  If timer is in "Current State", and 
"State Change Function" is called, result is either the indicated new state
or "Invalid" (in which case globus_utp_warn() is called).

				State Change Function
Current
State		start()	   stop()     reset()    disable()   enable()
-------		-------	   ------     -------    ---------   ---------
STOPPED		RUNNING    Invalid    STOPPED    DISABLED    STOPPED    

RUNNING		Invalid    STOPPED    STOPPED    Invalid     RUNNING    

DISABLED	DISABLED   DISABLED   DISABLED   DISABLED    STOPPED    
**********************************************************************/

void globus_utp_start_timer(unsigned timerNumber)
{
	globus_utp_Timer_t *theTimer;

		/* Don't compile run-time checks into fully-optimized
		   version of the library. */
#ifndef NDEBUG
	if (timerNumber >= globus_utp_numTimers) {
		globus_utp_warn("globus_utp_start_timer: illegal timer %d",
			 (int) timerNumber);
		return;
	}
#endif /* #ifndef NDEBUG */

	theTimer = &globus_utp_timers[timerNumber];
	if (theTimer->state == GLOBUS_UTP_TIMER_DISABLED)
		return;

#ifndef NDEBUG
	if (theTimer->state == GLOBUS_UTP_TIMER_RUNNING) {
		globus_utp_warn("globus_utp_start_timer: timer %d already running",
			 (int) timerNumber);
		return;
	}
#endif /* #ifndef NDEBUG */

	theTimer->state = GLOBUS_UTP_TIMER_RUNNING;
	globus_utp_readTime(&theTimer->startTime);
}

void globus_utp_stop_timer(unsigned timerNumber)
{
	globus_utp_Timer_t *theTimer;
	globus_utp_TimeValue_t stopTime, elapsedTime;

#ifndef NDEBUG
	if (timerNumber >= globus_utp_numTimers) {
		globus_utp_warn("globus_utp_stop_timer: illegal timer %d",
			 (int) timerNumber);
		return;
	}
#endif /* #ifndef NDEBUG */

	theTimer = &globus_utp_timers[timerNumber];
	if (theTimer->state == GLOBUS_UTP_TIMER_DISABLED)
		return;

#ifndef NDEBUG
	if (theTimer->state == GLOBUS_UTP_TIMER_STOPPED) {
		globus_utp_warn("globus_utp_stop_timer: timer %d not running",
			 (int) timerNumber);
		return;
	}
#endif /* #ifndef NDEBUG */

	theTimer->state = GLOBUS_UTP_TIMER_STOPPED;
	globus_utp_readTime(&stopTime);
	globus_utp_timeDifference(&elapsedTime, &theTimer->startTime, &stopTime);
	globus_utp_timeAdd(&theTimer->accumulatedTime, &elapsedTime);
	theTimer->numEvents++;
}

void globus_utp_reset_timer(unsigned timerNumber)
{
	globus_utp_Timer_t *theTimer;

#ifndef NDEBUG
	if (timerNumber >= globus_utp_numTimers) {
		globus_utp_warn("globus_utp_reset_timer: illegal timer %d",
			 (int) timerNumber);
		return;
	}
#endif /* #ifndef NDEBUG */

	theTimer = &globus_utp_timers[timerNumber];
	if (theTimer->state == GLOBUS_UTP_TIMER_DISABLED)
		return;

	theTimer->state = GLOBUS_UTP_TIMER_STOPPED;
	globus_utp_timeZero(&theTimer->startTime);
	globus_utp_timeZero(&theTimer->accumulatedTime);
	theTimer->numEvents = 0;
}

void globus_utp_disable_timer(unsigned timerNumber)
{
	globus_utp_Timer_t *theTimer;

#ifndef NDEBUG
	if (timerNumber >= globus_utp_numTimers) {
		globus_utp_warn("globus_utp_disable_timer: illegal timer %d",
			 (int) timerNumber);
		return;
	}
#endif /* #ifndef NDEBUG */

	theTimer = &globus_utp_timers[timerNumber];

#ifndef NDEBUG
	if (theTimer->state == GLOBUS_UTP_TIMER_RUNNING) {
		globus_utp_warn("globus_utp_disable_timer: timer %d is running",
			 (int) timerNumber);
		return;
	}
#endif /* #ifndef NDEBUG */

	theTimer->state = GLOBUS_UTP_TIMER_DISABLED;
}

void globus_utp_enable_timer(unsigned timerNumber)
{
	globus_utp_Timer_t *theTimer;

#ifndef NDEBUG
	if (timerNumber >= globus_utp_numTimers) {
		globus_utp_warn("globus_utp_disable_timer: illegal timer %d",
			 (int) timerNumber);
		return;
	}
#endif /* #ifndef NDEBUG */

	theTimer = &globus_utp_timers[timerNumber];

			/* If STOPPED or RUNNING, already enabled.
			   Otherwise, can only get to DISABLED from
			   STOPPED, so go there. */
	if (theTimer->state == GLOBUS_UTP_TIMER_DISABLED)
		theTimer->state = GLOBUS_UTP_TIMER_STOPPED;
}

void globus_utp_disable_all_timers(void)
{
	unsigned i;

	for (i = 0; i < globus_utp_numTimers; i++)
		globus_utp_disable_timer(i);
}

void globus_utp_enable_all_timers(void)
{
	unsigned i;

	for (i = 0; i < globus_utp_numTimers; i++)
		globus_utp_enable_timer(i);
}

const char *
globus_utp_name_timer(unsigned timerNumber, const char *nameStr, ...)
{
	char *name;
	va_list ap;

#ifndef NDEBUG
	if (timerNumber >= globus_utp_numTimers) {
		globus_utp_warn("globus_utp_name_timer: illegal timer %d",
			 (int) timerNumber);
		return NULL;
	}
#endif /* #ifndef NDEBUG */
	if (!(name = globus_malloc(sizeof(char) * GLOBUS_UTP_MAX_NAME_LENGTH))) {
		globus_utp_warn("globus_utp_name_timer: globus_malloc() failed");
		return NULL;
	}

	va_start(ap, nameStr);
	vsprintf(name, nameStr, ap);
	globus_utp_timers[timerNumber].name = name;

	return name;
}

void
globus_utp_get_accum_time(unsigned timerNumber, double *time, int *precision)
{
	globus_utp_Timer_t *theTimer;

#ifndef NDEBUG
	if (timerNumber >= globus_utp_numTimers) {
		globus_utp_warn("globus_utp_get_accum_time: illegal timer %d",
			 (int) timerNumber);
		return;
	}
#endif /* #ifndef NDEBUG */

	theTimer = &globus_utp_timers[timerNumber];

	globus_utp_timeToDouble(time, precision, &theTimer->accumulatedTime);
}


/**********************************************************************
Private UTP functions.
**********************************************************************/

			/* Use external assembler routine for RS6000 by
			   default, unless RS6000_GETTIMER is defined. */
#if !defined(RS6000) || (defined(RS6000) && defined(RS6000_GETTIMER))

void
globus_utp_readTime(globus_utp_TimeValue_t *tv)
{
#ifdef UNIX
	int flag;

	flag = gettimeofday(tv, NULL);

#ifdef DEBUG
	if (flag) {
		globus_utp_warn("globus_utp_readTime: gettimeofday() failed");
		globus_utp_warn("globus_utp_readTime: system error message is \"%s\"",
			 sys_errlist[errno]);
	}
#endif /* #ifdef DEBUG */
#endif /* #ifdef UNIX */


#ifdef SOLHR
	*tv = gethrtime();
#endif

#ifdef RS6000

/*
The AIX 3.2.5 on-line "info" about gettimer() presents a totally wrong
calling interface for gettimer().  The code below is based on the example
on p. 59 of the "Optimizing and Tuning Guide for FORTRAN, C, and C++", and
seems to work just fine.
*/

	int flag;

	flag = gettimer(TIMEOFDAY, tv);

#ifdef DEBUG
	if (flag) {
		globus_utp_warn("globus_utp_readTime: gettimer() failed");
		globus_utp_warn("globus_utp_readTime: system error message is \"%s\"",
			 sys_errlist[errno]);
	}
#endif /* #ifdef DEBUG */

#endif /* #ifdef RS6000 */

#ifdef PARAGON
	*tv = dclock();
#endif	/* #ifdef PARAGON */
}

#endif	/* #if !defined(RS6000) || .... */


void
globus_utp_timeDifference(globus_utp_TimeValue_t *diff, const globus_utp_TimeValue_t *start,
		   const globus_utp_TimeValue_t *end)
{
#ifdef UNIX
	diff->tv_sec = end->tv_sec - start->tv_sec;

	if (end->tv_usec < start->tv_usec) {
		diff->tv_sec--;		/* "Borrow" from seconds. */
		diff->tv_usec = 1000000 + end->tv_usec - start->tv_usec;
	} else
		diff->tv_usec = end->tv_usec - start->tv_usec;
#endif /* #ifdef UNIX */

#ifdef RS6000
	diff->tv_sec = end->tv_sec - start->tv_sec;

	if (end->tv_nsec < start->tv_nsec) {
		diff->tv_sec--;		/* "Borrow" from seconds. */
		diff->tv_nsec = 1000000000 + end->tv_nsec - start->tv_nsec;
	} else
		diff->tv_nsec = end->tv_nsec - start->tv_nsec;
#endif /* #ifdef RS6000 */

#ifdef SOLHR
	*diff = *end - *start;
#endif

#ifdef PARAGON
	*diff = *end - *start;
#endif	/* #ifdef PARAGON */
}


void
globus_utp_timeAdd(globus_utp_TimeValue_t *oldElapsed,
	    const globus_utp_TimeValue_t *newElapsed)
{
#ifdef UNIX
	oldElapsed->tv_usec += newElapsed->tv_usec;

	if (oldElapsed->tv_usec >= 1000000) {
		oldElapsed->tv_sec++;	/* "Carry" into seconds. */
		oldElapsed->tv_usec -= 1000000;
	}

	oldElapsed->tv_sec += newElapsed->tv_sec;
#endif /* #ifdef UNIX */

#ifdef RS6000
	oldElapsed->tv_nsec += newElapsed->tv_nsec;

	if (oldElapsed->tv_nsec >= 1000000000) {
		oldElapsed->tv_sec++;	/* "Carry" into seconds. */
		oldElapsed->tv_nsec -= 1000000000;
	}

	oldElapsed->tv_sec += newElapsed->tv_sec;
#endif /* #ifdef RS6000 */

#ifdef SOLHR
	*oldElapsed += *newElapsed;
#endif

#ifdef PARAGON
	*oldElapsed += *newElapsed;
#endif	/* #ifdef PARAGON */
}


void
globus_utp_timeZero(globus_utp_TimeValue_t *tv)
{
#ifdef UNIX
	tv->tv_sec = 0;
	tv->tv_usec = 0;
#endif /* #ifdef UNIX */

#ifdef RS6000
	tv->tv_sec = 0;
	tv->tv_nsec = 0;
#endif /* #ifdef RS6000 */

#ifdef SOLHR
	*tv = 0;
#endif

#ifdef PARAGON
	*tv = 0.0;
#endif	/* #ifdef PARAGON */
}


void
globus_utp_timeToDouble(double *time, int *precision, const globus_utp_TimeValue_t *tv)
{
#ifdef UNIX
	*time = (double) tv->tv_sec + ((double) tv->tv_usec) / 1000000.0;
	*precision = 6;
#endif /* #ifdef UNIX */

#ifdef RS6000
	*time = (double) tv->tv_sec + ((double) tv->tv_nsec) /
		1000000000.0;
	*precision = 7;
#endif /* #ifdef RS6000 */

#ifdef SOLHR
	*time = ((double)*tv) / 1000000000.0;
	*precision = 6;
#endif

#ifdef PARAGON
	*time = *tv;
	*precision = 7;
#endif	/* #ifdef PARAGON */
}


void
globus_utp_timeToString(char timeString[], const globus_utp_TimeValue_t *tv)
{
	double tvAsDouble;
	int precision;

	globus_utp_timeToDouble(&tvAsDouble, &precision, tv);

	sprintf(timeString, "%.*f", precision, tvAsDouble);
}


void
globus_utp_warn(const char *messageStr, ...)
{
#   if defined(DEBUG)
    {
	va_list ap;

	va_start(ap, messageStr);

	vfprintf(stderr, messageStr, ap);
	fprintf(stderr, "\n");
	fflush(stderr);		/* Just to be safe. */
    }
#   endif
}


/**********************************************************************
Private UTP globals.
**********************************************************************/

unsigned globus_utp_numTimers = 0;
globus_utp_Timer_t *globus_utp_timers = NULL;
globus_utp_Attribute_t *globus_utp_attributes;