aboutsummaryrefslogtreecommitdiffstats
path: root/fnet/src/vespa/fnet/info.cpp
blob: c0c1c618525b2866b642cbd2129d36a83d72bdaa (plain) (blame)
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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "info.h"
#include <vespa/vespalib/component/vtag.h>

#include <vespa/log/log.h>
LOG_SETUP(".fnet");

uint32_t FNET_Info::_endian = FNET_Info::ENDIAN_UNKNOWN;

FNET_Info::FNET_Info()
{
    uint8_t  *pt     = nullptr;
    uint64_t  cmp    = 0;
    uint32_t  endian = ENDIAN_UNKNOWN;

    uint16_t intval16;
    uint32_t intval32;
    uint64_t intval64;

    pt = (uint8_t *) &intval16;
    pt[0] = 1;
    pt[1] = 2;

    pt = (uint8_t *) &intval32;
    pt[0] = 1;
    pt[1] = 2;
    pt[2] = 3;
    pt[3] = 4;

    pt = (uint8_t *) &intval64;
    pt[0] = 1;
    pt[1] = 2;
    pt[2] = 3;
    pt[3] = 4;
    pt[4] = 5;
    pt[5] = 6;
    pt[6] = 7;
    pt[7] = 8;

    cmp = 0x08070605;
    cmp = (cmp << 32) + 0x04030201;
    if (intval16 == 0x0201 &&
        intval32 == 0x04030201 &&
        intval64 == cmp)
        endian = ENDIAN_LITTLE;

    cmp = 0x01020304;
    cmp = (cmp << 32) + 0x05060708;
    if (intval16 == 0x0102 &&
        intval32 == 0x01020304 &&
        intval64 == cmp)
        endian = ENDIAN_BIG;

    _endian = endian;
}


const char*
FNET_Info::GetFNETVersion()
{
    return vespalib::VersionTag;
}


void
FNET_Info::PrintInfo()
{
    printf("This method is deprecated. "
           "Use the FNET_Info::LogInfo method instead.\n");
}


void
FNET_Info::LogInfo()
{
    LOG(info, "FNET Version    : %s", GetFNETVersion());
    const char *endian_str = "UNKNOWN";
    if (_endian == ENDIAN_LITTLE)
        endian_str = "LITTLE";
    if (_endian == ENDIAN_BIG)
        endian_str = "BIG";
    LOG(info, "Host Endian     : %s", endian_str);
    const char *thread_str = HasThreads() ? "true" : "false";
    LOG(info, "Thread support  : %s", thread_str);
}